Argh: AS3 Event Dispatcher views an event NOT as a class + type property, but just as a type property. Therefore:
new CustomEvent("onRollOver") is detected (and subsequently incorrectly cast) as new MouseEvent(MouseEvent.ROLL_OVER)
Very surprising.
Ash C's software blog
Sunday, September 21, 2008
Tuesday, September 9, 2008
Elegantly call code after first frame(script) has executed?
private var __data:Object ={};
/**
* Constructor
*/
public function Content() {
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
this.addEventListener(Event.ENTER_FRAME, afterFirstFrame);
}
public function addedToStage(e:Event)
{
}
public function afterFirstFrame(e:Event)
{
__data['frames'] = (__data['frames'] == undefined) ? 1 : __data['frames']++;
if (__data['frames'] > 1)
{
this.removeEventListener(Event.ENTER_FRAME, afterFirstFrame);
if (__isReadyToStart==undefined) trace('dispatch content ready:'+this);
delete(__data.framesPlayed);
}
}
I keep finding exceptions i need to hand, eg if frame calls stop() - and its starting to get stupid. So there is no way i can handle 'unknown' frame scripts. In as2 I could call setTimeout(afterFirstFrame, 1);
Need an EXIT_FRAME
/**
* Constructor
*/
public function Content() {
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
this.addEventListener(Event.ENTER_FRAME, afterFirstFrame);
}
public function addedToStage(e:Event)
{
}
public function afterFirstFrame(e:Event)
{
__data['frames'] = (__data['frames'] == undefined) ? 1 : __data['frames']++;
if (__data['frames'] > 1)
{
this.removeEventListener(Event.ENTER_FRAME, afterFirstFrame);
if (__isReadyToStart==undefined) trace('dispatch content ready:'+this);
delete(__data.framesPlayed);
}
}
I keep finding exceptions i need to hand, eg if frame calls stop() - and its starting to get stupid. So there is no way i can handle 'unknown' frame scripts. In as2 I could call setTimeout(afterFirstFrame, 1);
Need an EXIT_FRAME
Saturday, April 12, 2008
private getter/setter scenrio
Doing some AS2 programming, and I think I have a case for using privately scoped getter/setters. The AS2 compiler crashes as it is considered improper use of get and set.
Situation: A (private) variable's definition is dependent on some other (asynchronous) event.
Technique#1: Have a channel of communication notifying for the event, and then defining the variable. I find event model code a bit obtuse in larger classes, and a bit hard to understand in some situations.
Technique#2: Every time variable is encountered in the main code, ensure it is valid. This can start out as one check, but then grow to be a heap of checks over time -i.e. a heap of unnecessary code.
Alternative: Private getter function that checks to see if the dependency has been met on an as needed basis. Their is no asynchronous communication functions, and the main code is kept clean.
The idea behind getter/setters is to allow the class to perform operations on the variable, without having to expose its "guts" to the outside word.
It's good practice to define everything you can in the constructor - but this sometimes isn't possible at that point in time, if something a given variable depends has not been defined yet.
The idea behind private getter/setters is to parcel a dependent variable definition to a getter function. This means the operations involved are not in your main code.
Situation: A (private) variable's definition is dependent on some other (asynchronous) event.
Technique#1: Have a channel of communication notifying for the event, and then defining the variable. I find event model code a bit obtuse in larger classes, and a bit hard to understand in some situations.
Technique#2: Every time variable is encountered in the main code, ensure it is valid. This can start out as one check, but then grow to be a heap of checks over time -i.e. a heap of unnecessary code.
Alternative: Private getter function that checks to see if the dependency has been met on an as needed basis. Their is no asynchronous communication functions, and the main code is kept clean.
The idea behind getter/setters is to allow the class to perform operations on the variable, without having to expose its "guts" to the outside word.
It's good practice to define everything you can in the constructor - but this sometimes isn't possible at that point in time, if something a given variable depends has not been defined yet.
The idea behind private getter/setters is to parcel a dependent variable definition to a getter function. This means the operations involved are not in your main code.
Subscribe to:
Comments (Atom)