5

AS3 Listen to events when data is changed?

 2 years ago
source link: https://www.codesd.com/item/as3-listen-to-events-when-data-is-changed.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

AS3 Listen to events when data is changed?

advertisements

Hopefully you will excuse me if this is a simple/silly question. I started learning action script about 6 days ago and already working on a small project :D

Anyways, there is a property that changes occasionally to reflect the name of a level in a game (object._I._M.text). It could take a minute to change, or a max of two minutes, depending on how fast all players are able to finish the level.

I want to be able to listen for the change in this property to fire off another function. I have found very few answers to this online, and the examples I have found were very incomplete and poorly written. Does anyone know how I could do this?

I have tried ...

theobject._I._M.addEventListener(Event.CHANGE, myfunction);

To no success. Thanks for any help or advice, I am going to get back to learning while I await responses :D


I would probably use getters/setters, or just declare one method to change the text of that textfield so that you can dispatch an event every time.

function changeLevel(text:String):void {
   levelTf.text=text;
   dispatchEvent(new Event("levelChange"));
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK