A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS 2.0 // Event handeler inside class constructor.

  1. #1
    Member
    Join Date
    Dec 2002
    Location
    Seattle
    Posts
    47

    AS 2.0 // Event handeler inside class constructor.

    I have a class that has a sound object in it.
    i'm trying to configure the .onSoundComplete event to trigger a method in the class.
    the onSoundComplete is declared/defined in my class construstor.
    but for some reason the event handeler scope is not allowing the the other class properties or methods to be accessed.

    class alpha{
    var mysound:Sound
    function soundOver(){
    trace("sound is over")
    }
    function alpha(){
    mysound=new Sound()
    mysound.onSoundComplete=function(){
    soundOver()//doesn't work
    this.soundOver()//doesn't work
    _parent.soundOver()//doesn't work
    }
    }

  2. #2
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173
    You need to store a reference to the class in the Sound object.

    Code:
    mySound = new Sound();
    mySound.owner = this;
    
    mySound.onSoundComplete = function() {
        this.owner.soundOver();
    }
    If you get a compiler error objecting that Sound has no owner property, use this construction instead:

    Code:
    mySound['owner']
    Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com

  3. #3
    Member
    Join Date
    Dec 2002
    Location
    Seattle
    Posts
    47
    that worked, where can i find some more info on this?

  4. #4
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173
    You're welcome.


    Try a book on object-oriented programming.
    Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com

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