Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-09-2009, 03:08 AM   #1
Registered User
Join Date: Jul 2009
Posts: 1
Default Fighting loader and custom event dispatch

Hello, I am fighting with the following code. The problem starts with not being able to dispatch the "UnloadMe". I got this code from another forum thread, but it doesn't work for me. How can I debug this type of problem?

thanks Peter

ActionScript Code:
package code{     import flash.display.MovieClip;     import flash.display.SimpleButton;     import flash.display.Sprite;     import flash.display.Shape;     import flash.display.Loader;     import flash.display.LoaderInfo;     import flash.events.ProgressEvent;     import flash.events.Event;     import flash.events.MouseEvent;     import flash.net.URLRequest;     public class Main extends MovieClip {         public var canvas:Sprite;         public var swfLoader:Loader;         public var swfContainer:MovieClip;         private var isLoaded:Boolean=false;         private var isImgLoaded:Boolean=false;         private static  const YELLOW:Number = 0xFFFF00;         private static  const BLUE:Number = 0x0000FF;         private static  const GREEN:Number = 0x00FF00;         private static  const RED:Number = 0xFF0000;         private static  const BLACK:Number = 0x000000;         public function Main() {             canvas=new Sprite();             swfLoader=new Loader();             swfContainer=new MovieClip();             drawCanvas();             addChild(canvas);             controllingSwfs("Load Movie");             cl_Btn.addEventListener(MouseEvent.CLICK, drawCanvasClick);         }         function controllingSwfs(WhatToLoad:String):void {             // declare the load complete event handler             // load the external SWF             trace(WhatToLoad);             loadSwf('videoDemo_final.swf');             isLoaded=true;         }         function loaderCompleteHandler(evt:Event):void {             // cast swfContainer as a MovieClip             swfContainer=swfLoader.content  as  MovieClip;             // add the external SWF to the display list after it has completed loading             swfContainer.x=10;             swfContainer.y=10;             var rect:Shape = new Shape();             rect.graphics.beginFill(0);             rect.graphics.drawRect( 30, 30, 349, 299);             rect.graphics.endFill();             canvas.addChild(rect);             swfContainer.mask=rect;             canvas.addChild(swfContainer);             trace("in complete");             swfContainer.clear_Btn = this.cl_Btn;             trace(swfContainer.clear_Btn, cl_Btn);             swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loaderCompleteHandler,false);         }         function drawCanvas():void {             canvas.graphics.clear();             canvas.graphics.beginFill(0xFFFFF0);             canvas.graphics.lineStyle(2, BLACK);             canvas.graphics.drawRect( 30, 30, 350, 300);             canvas.graphics.endFill();         }         function drawCanvasClick(event:MouseEvent):void {             if (isLoaded==true) {                 trace("blink blink");                 dispatchEvent(new Event("UnloadMe"));                 // swfLoader.unload();                 isLoaded=false;             }             drawCanvas();         }         function loadSwf(Url:String):void {             trace("in load swf");             swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);             swfLoader.addEventListener("UnloadMe", unloadFunction);             swfLoader.load(new URLRequest(Url));                 }         function unloadFunction(event:Event):void {             // event.target is the loader reference.. so cast it as Loader             trace("blink blink blink");             canvas.removeChild(swfContainer);             Loader(event.currentTarget).unload();             swfLoader.removeEventListener("UnloadMe", unloadFunction, false);         }     } }
petzi-baer is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 12:43 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.