在ActionScript3中创建预加载程序类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在ActionScript3中创建预加载程序类相关的知识,希望对你有一定的参考价值。
A complete example of how we can create a Preloader in actionscript3 to load an external .swf file.STRUCTURE
------------------
Source Swf
|_ Main.fla
|_ Main.as
|_ Main.swf
Preloader Swf
|_
/* * main.fla -> main.as */ package { import flash.display.MovieClip; import flash.events.Event; /** * ... * @author Faisal */ public class Main extends MovieClip { public function Main() { if (stage) { init(); } else { addEventListener(Event.ADDED_TO_STAGE, init); } } private function init(e:Event = null):void { trace("I am main file loaded from Main.fla :)"); } } } /* * preloader.fla -> preloader.as */ package { import flash.display.Loader; import flash.display.MovieClip; import flash.events.Event; import flash.events.ProgressEvent; import flash.net.URLRequest; /** * ... * @author Faisal */ public class Preloader extends MovieClip { public function Preloader() { if (stage) { init(); } else { addEventListener(Event.ADDED_TO_STAGE, init); } } private function init():void { var url:URLRequest = new URLRequest("Main.swf"); var myLoader:Loader = new Loader(); myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete); myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress); myLoader.load(url); } private function onLoaderComplete(e:Event):void { trace(e.currentTarget.content); var a:MovieClip = new MovieClip(); stage.addChild(a); a.addChild(e.currentTarget.content) } private function onLoaderProgress(e:ProgressEvent):void { var loaded:Number = (e.bytesLoaded / e.bytesTotal) * 100; trace(loaded); } } }
以上是关于在ActionScript3中创建预加载程序类的主要内容,如果未能解决你的问题,请参考以下文章