Hi!
We are constructing an application composed of 2 SWF... one of it will be the UI and will get the content and send the events to other SWF.
Is there any way (using the reflection API) of getting all events triggered by that app??
Some think like that:
login_bt_submit.onPress=function(){ dispatch(this._name); } form1_bt_submit.onPress=function(){ dispatch(this._name); } form2_bt_submit.onPress=function(){ dispatch(this._name); } form3_bt_submit.onPress=function(){ dispatch(this._name); } form4_bt_submit.onPress=function(){ dispatch(this._name); } ... formN_bt_submit.onPress=function(){ dispatch(this._name); }
But we dont want to write code to every button we want to "listen". Is there any clever way?
Best Regards
As2lib Reflection reflects the API, that is classes, its members etc. and not instances. So this probably won't help you much.
Some things you may do:
1. Not very intuitive, but shorter.
login_bt_submit.onPress = form1_bt_submit.onPress = form2_bt_submit.onPress = function(){ dispatch(this._name); }
2. Costs some performance.
var eventHandler:Function = function() { dispatch(this._name); };
for (var i:String in this) { if (this[i] instanceof MovieClip) { var button:MovieClip = this[i]; button.onPress = eventHandler; } }
3. Do it dirty and overwrite the onPress method in MovieClip.prototype (this may cause trouble because all MovieClips will have the onPress handler).
4. Create a subclass of MovieClip and implement the onPress method there. Then link your buttons with that class.
The forth approach is the most object-oriented and cleanest one. It is much easier to comprehend, debug, maintain than the other solutions.
Greetings, Simon
Log in to post a comment.
Hi!
We are constructing an application composed of 2 SWF... one of it will be the UI and will get the content and send the events to other SWF.
Is there any way (using the reflection API) of getting all events triggered by that app??
Some think like that:
login_bt_submit.onPress=function(){
dispatch(this._name);
}
form1_bt_submit.onPress=function(){
dispatch(this._name);
}
form2_bt_submit.onPress=function(){
dispatch(this._name);
}
form3_bt_submit.onPress=function(){
dispatch(this._name);
}
form4_bt_submit.onPress=function(){
dispatch(this._name);
}
...
formN_bt_submit.onPress=function(){
dispatch(this._name);
}
But we dont want to write code to every button we want to "listen". Is there any clever way?
Best Regards
As2lib Reflection reflects the API, that is classes, its members etc. and not instances. So this probably won't help you much.
Some things you may do:
1. Not very intuitive, but shorter.
login_bt_submit.onPress = form1_bt_submit.onPress = form2_bt_submit.onPress = function(){
dispatch(this._name);
}
2. Costs some performance.
var eventHandler:Function = function() {
dispatch(this._name);
};
for (var i:String in this) {
if (this[i] instanceof MovieClip) {
var button:MovieClip = this[i];
button.onPress = eventHandler;
}
}
3. Do it dirty and overwrite the onPress method in MovieClip.prototype (this may cause trouble because all MovieClips will have the onPress handler).
4. Create a subclass of MovieClip and implement the onPress method there. Then link your buttons with that class.
The forth approach is the most object-oriented and cleanest one. It is much easier to comprehend, debug, maintain than the other solutions.
Greetings,
Simon