Flash tip of the day

Out of context: Reply #20

  • Started
  • Last post
  • 47 Responses
  • kingsteven0

    this is a bit obvious but i have to show people all the time... when you define a function for an event handler any variables declared in the same scope are copied across.

    var self = this;
    _root.gui.menu.homeBut.onRelease... function(){
    self.openPage("home");
    }
    function openPage(pageName){
    trace(pageName);
    }

    • Not sure I follow. What does this achieve? Working example? Please forgive me if it's blatantly obvious and I'm just not getting itIvI_13
    • oh, it's totally obvious... not a great example. i create a variable called self which stores a reference to 'this'kingsteven
    • self is then available as a reference back to the current class/mc from within the onRelease function.kingsteven

View thread