A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help needed about removeeventlistener

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    83

    Help needed about removeeventlistener

    Code:
    function Main() {
    	...
    	var loader:Loader = new Loader();
    	loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imgLoadErrorMethod);
    	loader.load(url);
    	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
    
    	this.stage.scaleMode=StageScaleMode.NO_SCALE;
    	this.stage.align=StageAlign.TOP_LEFT;
    	
    	if (fileCount <= 4) {
    		fileCount++;
    	} else {
    		fileCount = 1;
    	}
    }
    function imgLoadErrorMethod(event:IOErrorEvent):void {
    	loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, imgLoadErrorMethod);
            num = 0;
    }
    
    function completeHandler(event:Event):void {
    	loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
    	this.container.addChild(event.target.content);
    ...
    after testing this script I'm getting following errors:

    Scene 1, Layer 'Actions', Frame 1, Line 63 1120: Access of undefined property loader.

    Scene 1, Layer 'Actions', Frame 1, Line 68 1120: Access of undefined property loader.

    can anyone help me?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to declare the the loader variable outside of any function once:

    var loader:Loader;

    then inside Main you write:
    loader = new Loader();

    The problem in your present script is that you have a local variable. However, alternatively you can also delete the listener this way without changing anything else:

    event.currentTarget.removeEventListener(IOErrorEve nt.IO_ERROR, imgLoadErrorMethod);
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Nov 2007
    Posts
    83
    thanks for the reply

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center