
I am having trouble loading external .swf files. I use the following code for my loader:
package { import flash.display.Sprite; import flash.text.TextField; import flash.net.URLRequest; import flash.display.Loader; import flash.events.*; public class testLoader extends Sprite { private var mLoader:Loader = new Loader(); private var progText:TextField = new TextField(); public function testLoader():void { var mytext:TextField = new TextField(); mytext.text = “Loader”; progText.text = “Progress…” addChild(progText); var url:String = ‘myEven.swf’; var mRequest:URLRequest = new URLRequest(url); mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, prog); mLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioEr); mLoader.load(mRequest); } private function ioEr(event:IOErrorEvent):void { progText.text = “ERROR!”; } private function prog(event:ProgressEvent):void { var percent:Number = ( 100 / event.bytesTotal ) * event.bytesLoaded; progText.text = “” + percent; if(event.bytesTotal == event.bytesLoaded) { progText.text = “COMPLETE”; addChild(mLoader); } } private function onCompleteHandler(event:Event):void { progText.text = “COMPLETE!”; addChild(mLoader); } } }
And the following code for myEven.swf:
package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.text.TextField; public class myEven extends Sprite { public function myEven() { var bgCol:uint = 0×000000; graphics.clear(); graphics.beginFill(bgCol); graphics.drawRect(0,0,50,50) stage.addEventListener(MouseEvent.CLICK, catchClick); } private function catchClick(Event:MouseEvent):void { var msgbox:Sprite = new Sprite(); // drawing a white rectangle msgbox.graphics.beginFill(0xFFFFFF); // white msgbox.graphics.drawRect(0,0,300,20); // x, y, width, height msgbox.graphics.endFill(); // drawing a black border msgbox.graphics.lineStyle(2, 0×000000, 100); // line thickness, line color (black), line alpha or opacity msgbox.graphics.drawRect(0,0,300,20); // x, y, width, height var textfield:TextField = new TextField() textfield.text = “Goodybe, world” addChild(msgbox) addChild(textfield) } } }
The issue is that the progress reaches 100% but the other file never shows. I also know the progress check is redundant and that the complete event should do the same, but that was one of my attempts at debugging.
I am quite the AS newbie, so this might be a simple error of where my objects are getting placed, but I am not sure.
The code I gave is a chop-up of the hours-load of tutorials I have been reading, and is just meant to be a test file for me to work with loading external flash files.
Any help is greatly appreciated.
If you would like to make a comment, please fill out the form below.
Recent Comments