Flash Loading 的感慨 一月 23rd, 2009
我是一个.NET的程序员,起先由于公司的需要,不得不学习Action Script。当时情况很糟,项目来了,迫在眉睫,但是公司舍不得出钱请个AS的程序员(AS的程序员要价总是太高),我只能一边学习,一边做项目,幸好Action Script 3.0的面向对象的,这让我感觉也不太难懂,经过一段时间学习,慢慢对于Flash的理解要稍稍多了一些,不知不觉,公司又接了几个Flash的项目,感觉都还能胜任。不过,直到昨天,我才明白Flash的loading的含义。
以下言论是我自身的理解,不保证100%正确,如有谬误,还请指出,并见谅。
你是否曾经被要求把Flash做到加载几KB就要显示呢,如果有,并且你不知道如何解决的话,请继续向下看;如果您是高手,并且也有兴趣的话,也请继续,并在适当的时候指出我的我的错误。
Flash要显示内容,至少得等第一桢下载完毕,很简单吧。
不过,你是否清楚你的第一桢有多大呢?如果你说你的第一桢很小,因为你留的是一个空白的桢,那不一定。现在我的这个项目的Flash里,做了很多的linkage,您可能明白了,Action Script导入的那一桢不管是不是空白,都是可以很大,所以,在我们经典论坛的Flash版块里总是会看到版主说,做loading用三桢,第一桢loading,第二桢导出脚本,第三桢开始程序……
http://bbs.blueidea.com/thread-2853462-1-1.html
但是为什么要这样做呢?
您还记得Flash至少要加载第一桢才能显示的道理吧,所以,要尽快的显示Flash的loading,要尽量减小第一桢的大小,把loading的逻辑写在第一桢,将Action Script导出在第二桢,这样,导出的内容就影响不到你,最后,你会在第三桢,也就是加载完成后,开始主程序逻辑。
在Flash的publish settings(快捷键Ctrl+Shift+F12),选择"Flash"选项卡,点击"Script"的那个"settings",把"Export class in frame 1"改成"Export class in frame 2",这样,你的程序的类会导出到第二桢,它不会把第一桢(loading所在的桢)变大,从而进快显示loading。
看看效果吧,在publish settings中,把"Generate size report"勾选,看看发布后flash文件的体积报告:
Frame # Frame Bytes Total Bytes Scene
1 23892 23892 Main Scene
2 155519 179411 (AS 3.0 Classes Export Frame)
3 36 179447
而把Action Script发布到第一桢呢:
Frame # Frame Bytes Total Bytes Scene
1 106125 106125 Main Scene (AS 3.0 Classes Export Frame)
2 70771 176896
3 36 176932
你看,如果导出到第二桢,第一桢的体积大约是24KB,这是因为loading动画效果有这样大的体积;而如果将AS发布到第一桢,则变成了106KB,主要的加载内容都在第一桢了,这说明这个loading就比较失败。
另外,你可能还会遇到这样的问题:当你辛苦的为你的loading写了一个类,叫myFlashAppPreLoader,在第一桢时,你是这样写的:
//private variables
private var loader:myFlashAppPreLoader;
……
//constructor
loader=new myFlashAppPreLoader();
this.addChild(loader);
this.loaderInfo.addEventListener(Event.COMPLETE,loadCompetedHandler);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,LoadingHandler);
……
//some other function
private function loadCompetedHandler(e:Event) {
this.removeChild(loader);
}
你这样做的原因在于,你想把loading封装成一个类,你直接用就好了,方便!
可是,这样带来一个极大的问题:
试想,你刚刚把AS导出在第二桢了,现在你的第一桢是loading,第一桢就用第二桢的东西……逻辑不太对吧?
所以,在第一桢的loading里,不要把loading写成类,请直接在舞台的第一桢里放loading的动画,对,把它们通通放到舞台上,这样,你可以直接在document class中对其中进行操作,想要什么动画也可以自行控制了。
//constructor
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,LoadingHandler);
……
//loading animation handler
private function LoadingHandler(e:ProgressEvent):void {
txtProgress.text=String(Math.round(e.bytesLoaded/e.bytesTotal*100));
}
这里的txtProgress就是舞台上一个DynamicTextField的实例名称,我直接用它赋一个百分比的值,如果你loading的时候要控制更多的元件,也可以同样这样做。
末尾的时候,提醒大家多留意一个size report,这里面不但可以看到桢的体积情况,还可以看到图形、元件、嵌入字体等的大小,对分析你的Flash用处多多哦。
因为发现这个blog有点问题,有时候发表评论会引起内部错误,这样就看不到日志了
请大家不要继续评论了
谢谢
有评论请发表在经典论坛
http://bbs.blueidea.com/thread-2908332-1-1.html
4zahIb qnpoptdporrk, [url=http://ajgwbivlfprc.com/]ajgwbivlfprc[/url], [link=http://xmebwfpprnnr.com/]xmebwfpprnnr[/link], http://ymhkghtzyywy.com/
comment5, red rose photographs, [url="http://www.freewebs.com/freemsn2/red-rose-photographs.html"]red rose photographs[/url], http://www.freewebs.com/freemsn2/red-rose-photographs.html red rose photographs, %O, worlds biggest nipples, [url="http://www.freewebs.com/piczzz/worlds-biggest-nipples.html"]worlds biggest nipples[/url], http://www.freewebs.com/piczzz/worlds-biggest-nipples.html worlds biggest nipples, 152, pictures highlights dark hair, [url="http://www.freewebs.com/naughtygirlss/pictures-highlights-dark-hair.html"]pictures highlights dark hair[/url], http://www.freewebs.com/naughtygirlss/pictures-highlights-dark-hair.html pictures highlights dark hair, =O, free sports cars wallpapers, [url="http://bestimages43.webs.com/free-sports-cars-wallpapers.html"]free sports cars wallpapers[/url], http://bestimages43.webs.com/free-sports-cars-wallpapers.html free sports cars wallpapers, 46316, billie piper pictures, [url="http://www.freewebs.com/freemsn4/billie-piper-pictures.html"]billie piper pictures[/url], http://www.freewebs.com/freemsn4/billie-piper-pictures.html billie piper pictures, 247, anti flag tattoo, [url="http://www.freewebs.com/tarareidpic/anti-flag-tattoo.html"]anti flag tattoo[/url], http://www.freewebs.com/tarareidpic/anti-flag-tattoo.html anti flag tattoo, soldv, british flag pictures, [url="http://www.freewebs.com/lowpics/british-flag-pictures.html"]british flag pictures[/url], http://www.freewebs.com/lowpics/british-flag-pictures.html british flag pictures, >:DD, black wallpapers, [url="http://bestimages43.webs.com/black-wallpapers.html"]black wallpapers[/url], http://bestimages43.webs.com/black-wallpapers.html black wallpapers, 50440, adam brody movie, [url="http://www.freewebs.com/imagesarticle/adam-brody-movie.html"]adam brody movie[/url], http://www.freewebs.com/imagesarticle/adam-brody-movie.html adam brody movie, mfbwu,
comment3, adam wallace, [url="http://www.freewebs.com/imagesarticle/adam-wallace.html"]adam wallace[/url], http://www.freewebs.com/imagesarticle/adam-wallace.html adam wallace, 0721, navy midshipmen football, [url="http://www.freewebs.com/ginaspics/navy-midshipmen-football.html"]navy midshipmen football[/url], http://www.freewebs.com/ginaspics/navy-midshipmen-football.html navy midshipmen football, 372, denver airport murals, [url="http://www.freewebs.com/picsdig/denver-airport-murals.html"]denver airport murals[/url], http://www.freewebs.com/picsdig/denver-airport-murals.html denver airport murals, csrwkc, hama bead designs, [url="http://www.freewebs.com/facebookss/hama-bead-designs.html"]hama bead designs[/url], http://www.freewebs.com/facebookss/hama-bead-designs.html hama bead designs, 8548, barbaro pictures, [url="http://www.freewebs.com/befreelikeme/barbaro-pictures.html"]barbaro pictures[/url], http://www.freewebs.com/befreelikeme/barbaro-pictures.html barbaro pictures, 573,
comment1, brad pitt wedding pictures, picasso images, colorful spiders, celtic birds, free football desktop wallpapers, cheetah body parts, free art wallpapers, crowns clipart, spanish tattoo quotes, dinosaur coloring sheet, runic tattoo designs, inspirational word tattoos,
ay3Y5P cndwmayqbnbw, [url=http://gmblqmdvhqrf.com/]gmblqmdvhqrf[/url], [link=http://gbpkwqsvuboc.com/]gbpkwqsvuboc[/link], http://ktsqmyndbtkf.com/
fuzzy yellow caterpillars, buckeye caterpillar, pink panther cartoons, celtic thunder damian mcginty, muddy waters pictures,
grim reaper paintings, printable bubble letters, worlds smallest sloth, lindsay lohan yovo,