0

I have the following functions:

private function createContent(slideData:Object):void 
  {
   transitions = new Transitions();
   if (slide){
   transitions.applyTransition(slide);
   transitions.addEventListener(Transitions.TRANSITION_COMPLETE, completeHandler);

   }
   slide  = new Slide(slideData);
    addChild(slide);
    transitions.applyTransition(slide);
  }
  private function completeHandler(e:Event):void{
   removeChild(slide);
  }

I dispatch an event in the first function and when it comes to the completehandler i would like to delete the slide from the first function but it isnt recognized. How can i pass the slide with the eventlistener so i can remove it in the completeHandler?(i have several instances from slide so i have to pass it through to have the right instance). Anyone who can help me?

vincent
  • 1
  • 1

3 Answers3

4

Here are a couple of ways to pass the slide to the event listener.

  • 1/ As a property of the event

    //Assuming that:
    // 1/ you create a custom Event class that takes two parameters
    //    type: String
    //    slide:Slide
    // 2/ that you have assigned the slide object to a variable in the
    // applyTransition method , which you can then assign to the event
    transitions.dispatchEvent( new TransitionEvent( 
                                Transitions.TRANSITION_COMPLETE , slide ) );
    
  • 2/ As a property of the dispatcher

    //Assuming that:
    // you assign the slide object to a variable in the
    // applyTransition method
    private function completeHandler(e:Event):void{
      var target:Transitions = event.currentTarget as Transitions;
      removeChild(target.slide);
    }
    
PatrickS
  • 9,539
  • 2
  • 27
  • 31
0

You can use the name property of the slide if you wish.

(Though you have not described how & where slide is actually declared - sprite, mc, etc)

Using name property :

Set slide as slide.name = "instanceName" (In your first function)

Get slide as getChildByName("instanceName") (In your second function)


Alternatively you can also:

  • Set the slide as class member, accessible by all the function of the class.
  • Add reference of every slide to an array available as class member to all its functions.
loxxy
  • 12,990
  • 2
  • 25
  • 56
0

If the variable is not dynamic, you could probably use an anonymous function to pass the variable.

transitions.addEventListener(Transitions.TRANSITION_COMPLETE, function (evt:Event) {
    completeHandler(evt, variable1, variable2);
});

function completeHandler(evt, catch1, catch2) {
    //do stuff
}
Tim Joyce
  • 4,487
  • 5
  • 34
  • 50