-
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
}
}
-
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:
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
-
that worked, where can i find some more info on this?
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|