ActionScript3优化Word下载.docx
- 文档编号:18168449
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:13
- 大小:66.81KB
ActionScript3优化Word下载.docx
《ActionScript3优化Word下载.docx》由会员分享,可在线阅读,更多相关《ActionScript3优化Word下载.docx(13页珍藏版)》请在冰豆网上搜索。
当分析你的程序效能时,始终保证没有其他的Flash程序正在运行,因为它们可能会破坏你的指标。
随着CPU的使用率,预想它超过90%的时候动画屏幕就黑屏了——例如,如果您切换到另一个浏览器选项卡或向下滚动页面。
较低的帧频导致它不会引起CPU密集型任务,但闪存节流下来的帧频无论每当你在看哪里。
每当发生这种情况,等待几秒钟后的CPU使用率图,在正常的帧频开始工作后来使恢复到合适的CPU使用率值。
步骤二:
这种代码会使我的flash看起来很“肥”吗?
下面是动画影片的源代码,它只有一个类,叫Flames,也是文档类。
这个类包含了一些属性来追踪影片内存使用和CPU使用率历史,被用来画一个图表。
内存和CPU使用率数据的计算和更新都是在Flames.getStates()这个函数中,并且图表是由Flames.drawGraph()逐帧绘制的,为了创造火焰效果,Flames.createParticles()这个函数首先每秒生成几百个粒子,粒子都被存储在fireParticles这个数组里。
这个数组在Flames.drawParticles()中不断循环,用粒子属性创造效果。
花一点时间研究一下Flames这个类。
你已经意识到任何迅速的变化在优化程序上还有很长的路要走吗?
1.Package
com.pjtops{
2.Import
flash.display.MovieClip;
3.Import
flash.events.Event;
4.Import
fl.motion.Color;
5.Import
flash.geom.Point;
6.Import
flash.geom.Rectangle;
7.Import
flash.text.TextField;
8.Import
flash.system.System;
9.Import
flash.utils.getTimer;
10.
11.Public
class
Flames
extends
MovieClip{
12.
13.
Private
var
memory
Log
=
newArray();
//
stores
System.totalMemory
values
for
display
in
the
graph
14.
Max
0;
highest
value
of
recorded
so
far
15.
Min
lowest
16.
Color;
color
used
by
text
displaying
info
17.
18.
ticks
counts
number
times
getStats()
is
called
before
next
frame
rate
set
19.
frameRate
//the
original
as
set
Adobe
Flash
20.
cpuLog
cpu
graph
21.
cpuMax
22.
cpuMin
23.
cpuColor;
cpu
24.
cpu;
current
calculated
use
25.
26.
lastUpdate
last
time
framerate
was
calculated
27.
sampleSize
30;
length
memoryLog
&
cpuLog
28.
graphHeight;
29.
graphWidth;
30.
31.
fireParticles
new
Array();
all
active
flame
particles
32.
fireMC
MovieClip();
canvas
drawing
flames
33.
palette
available
colors
34.
anchors
horizontal
points
along
which
act
like
magnets
to
35.
frame;
movieclips
bounding
box
36.
37.
constructor.
Set
up
events,
timers
and
objects
38.
Public
functionFlames()
{
39.
addChildAt(
fireMC,
1);
40.
Rectangle(
2,
stage.stageWidth
-
stage.stageHeight
2);
41.
42.
colWidth
Math.floor(
frame.width
/
10);
43.
for(
i
<
10;
i++
){
44.
anchors[i]
*
);
45.
}
46.
47.
SetPalette();
48.
49.
memoryColor
memoryTF.textColor;
50.
cpuColor
cpuTF.textColor;
51.
graphHeight
graphMC.height;
52.
graphWidth
graphMC.width;
53.
54.
stage.frameRate;
55.
56.
addEventListener(
Event.ENTER_FRAME,
drawParticles
57.
getStats
58.
drawGraph
59.
60.
61.
//creates
a
collection
particles,
them
palette
62.
function
setPalette(){
63.
Var
black
0x000000;
64.
blue
0x0000FF;
65.
red
0xFF0000;
66.
orange
0xFF7F00;
67.
yellow
0xFFFF00;
68.
white
0xFFFFFF;
69.
palettepalette
palette.concat(
getColorRange(
black,
blue,
10)
70.
red,
30)
71.
orange,
20)
72.
yellow,
73.
white,
74.
75.
76.
//returns
colors,
made
from
different
mixes
color1
color2
77.
color1,
color2,
steps){
78.
output
79.
steps;
80.
progress
81.
Color.interpolateColor(
82.
output.push(
83.
84.
Return
output;
85.
86.
87.
calculates
statistics
state
application,
terms
%
88.
getStats(
event
89.
ticks++;
90.
now
getTimer();
91.
92.
if(
1000){
93.
return;
94.
}else{
95.
now;
96.
97.
98.
100-
100;
99.
cpuLog.push(
100.
101.
cpucpuTF.text
cpu.toFixed
(1)
+
'
%'
;
102.
>
103.
cpucpuMax
104.
cpuMaxTF.text
cpuTF.text;
105.
106.
||
==
0){
107.
cpucpuMin
108.
cpuMinTF.text
109.
110.
111.
1000000;
112.
memoryLog.push(
113.
memoryTF.text
String(
memory.toFixed
(1)
)
mb'
114.
memoryMax
115.
memorymemoryMax
memory;
116.
memoryMaxTF.text
memoryTF.text;
117.
118.
memoryMin
119.
memorymemoryMin
120.
memoryMinTF.text
121.
122.
123.
124.
//render'
s
on
screen,
that
shows
trends
applications
consumption
125.
drawGraph(
126.
graphMC.graphics.clear();
127.
ypoint,
xpoint;
128.
logSize
memoryLog.length;
129.
130.
131.
memoryLog.shift();
132.
cpuLog.shift();
133.
sampleSize;
134.
135.
widthRatio
graphMC.width
logSize;
136.
137.
graphMC.graphics.lineStyle(
3,
memoryColor,
0.9);
138.
memoryRange
memoryMin;
139.
140.
ypoint
(
memoryLog[i]
141.
xpoint
(i
sampleSize)
142.
143.
graphMC.graphics.moveTo(
xpoint,
-ypoint
144.
continue;
145.
146.
graphMC.graphics.lineTo(
147.
148.
149.
cpuColor,
150.
j
cpuLog.length;
j++
151.
cpuLog[j]
100*
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
//renders
each
particle
updates
it'
values
162.
drawParticles(
163.
createParticles(
20);
164.
165.
fireMC.graphics.clear();
166.
vari
infireParticles
167.
varparticle
fireParticles[i];
168.
169.
if(particle.life
0)
170.
delete(
firePar
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ActionScript3 优化
![提示](https://static.bdocx.com/images/bang_tan.gif)