A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] AS3: having trouble getting EventListener to listen to Child dispatchEvent

  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    37

    resolved [RESOLVED] AS3: having trouble getting EventListener to listen to Child dispatchEvent

    Code:
    function createDmg(e) {
    	var duck: enemydmg = new enemydmg;
    	duck.name = "duck";
    	addChild(duck);
    	duck.x = enemy.x
    	duck.y = enemy.y
    	duck.flyholder.flydmg.text = hdmg;
    }
    addEventListener("remove", removeduck);
    function removeduck(e) {
    	trace("trashed");
    	removeChild(e.target);
    	
    }
    and on frame 16 of the movie clip I want removed

    Code:
    this.dispatchEvent(new Event ("remove"));

    Pretty much just want the movieClip to remove itself after reaching the end of its frames.

    But my duck.addEventListener Isn't receiving a dispatch.

    I've tried changing this.dispatchEvent to parent.dispatchEvent, which will allow my addEventListener to hear it, but can't find the target to remove.

    Sorry if this doesn't make any sense or is hard to read, Kinda tired.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Without seeing your files or set up.

    Perhaps this might be easier for you.

    PHP Code:
    //addEventListener("remove", removeduck);
    function removeduck(e)
    {
        
    trace("trashed");
        
    removeChild(e);

    and frame 16 of the clip/s

    PHP Code:
    stop();
    MovieClip(root).removeduck(this); 

  3. #3
    Member
    Join Date
    Jan 2008
    Posts
    37
    Perfect! thank you. I didn't know I could call functions like that. You have set me free fruitbeard! Thank you.

    Solved.

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