actionscript 3 - GOING MAD SWF ASSETS not loading -
i've read through posts on "swf loading issues" on many sites , nothing helps. maybe environment or tiny thing missed causing loader.content null. swf files in same folder added trusted locations in flash preferences.
i'm using mxmlc -static-link-runtime-shared-libraries
build both swf files, 1 main, other assets "images, sounds, , code". loader.progress getting triggered: event.bytesloaded equals event.bytestotal "11303918", content elements null, no class attach. have given on loader.complete, because never triggers locally, it's firefox caching issue; thus, triggering completion through progress bytes.
to protect innocent names have been changed "main, part, , assets", no code has been harmed in writing of post... yet.
10952 main.swf - includes part.as , main.as 11303918 assets.swf - includes assets.as
my flash app simple music mixer. main defines control board. assets provide music, images, , executable code.
all works fine if built single swf. want add preloader because devices cell-phones, load , preloaders entertaining. thus, assets have been placed in own swf loaded main.
here important parts of code: no compiler errors, assume imports exist , variables defined.
main.as -- main.swf
package { ... [swf(scalemode="noscale", widthpercent="100%", heightpercent="100%", framerate="20", backgroundcolor="#000000")] public class main extends sprite { ... function main():void { if( stage ) { maininit(null); return; } addeventlistener(event.added_to_stage,maininit); } private function maininit(e:event):void { if( e ) { removeeventlistener(event.added_to_stage,maininit); } stage.scalemode = stagescalemode.no_scale; stage.align = stagealign.top_left; w=stage.stagewidth; h=stage.stageheight; part=new part(w,h,loadmsg,assetscomplete); } private function assetscomplete():void {... }}}
part.as -- swc built main.swf
package part { ... public class part { ... private static var stuffloader:loader=null; private static var stuffclass:class=null; public static var stuff:*=null; public function part(w:int,h:int,msg:textfield,cb:function):void { ... if( !stuffloader ) { var stuffrequest:urlrequest=new urlrequest("assets.swf"); var stuffcontext:loadercontext=new loadercontext(false,applicationdomain.currentdomain,null); stuffcontext.allowcodeimport=true; stuffloader=new loader(); stuffloader.load(stuffrequest,stuffcontext); stuffloader.contentloaderinfo.addeventlistener(progressevent.progress,stuffloading); //stuffloader.contentloaderinfo.addeventlistener(event.complete,stuffloaded); }} public static function stuffloading(e:progressevent):void { welcomebytes=e.bytesloaded;///1024; welcometotal=e.bytestotal;///1024; welcome(e.currenttarget); } public static function stuffloaded(e:event):void { complete(e.currenttarget); } public static function complete(target:object):void { ... stuffloader.contentloaderinfo.removeeventlistener(progressevent.progress,stuffloading); //stuffloader.contentloaderinfo.removeeventlistener(event.complete,stuffloaded); var objectloaderinfo:loaderinfo=loaderinfo(target); var appdomain:applicationdomain=objectloaderinfo.applicationdomain; if( appdomain.hasdefinition("assets")) { ... // false } else {... stuffloader.content; // null stuffloader.contentloaderinfo.content; // null objectloaderinfo.content; // null } stuffclass=class(stuffloader.contentloaderinfo.applicationdomain.getdefinition("assets")); // null stuff=new stuffclass(width,height); // crash because null reference ... } public static function welcome(target:object):void { var pct:int=100*welcomebytes/welcometotal; ... if( welcomebytes==welcometotal ) { complete(target); } }}}
assets.as -- assets.swf
package { ... public class assets extends sprite { [embed(source="../sounds/beep001.mp3")] private static var sndclsbeep001:class; private static var sndbeep001:sound=new sndclsbeep001() sound; ... function assets(w:int,h:int):void {... } public function background(w:int,h:int):void {... }}}
at end of rope. loader.progress loads bytes, every content null, no hook convert class , access assets embedded therein.
problem solved in comments, code change minor follows.
package { public class assets extends sprite { function assets():void { . . . } public function init(w:int,h:int):void { . . . }}}
breaking out width , height params separate initialization method.
Comments
Post a Comment