all groups > flash (macromedia) > march 2006 >
You're in the

flash (macromedia)

group:

Use a variable to call a function


Use a variable to call a function Trensic
3/15/2006 10:06:17 PM
flash (macromedia):
I need to be able to set a variable that refers to a function name and run the
function from the variable name. (Example: testvar = ?somefuncitonname();?
then just user testvar to call the function)

The reason I would like to so this is if there is a data connection problem
then I would like to give the user a way to try again. There are many
functions that could be called and instead of setting a var and doing multiple
if statements I could use variable to set the function that I am calling and
if it fails use the variable to call the function if the user hits ok on an
alert. ((sorry about the run on there))

EXAMPLE:

// Define action after alert confirmation.
function AlertClickHandler(evt_obj:Object) {
if (evt_obj.detail == Alert.OK) {
trace("the alert ran");
checkone = 1;
this;
delete alert_Function;
}
}
// Define alert window
function AlertWindow() {
Alert.show(alert_ErrorMessage, alert_ErrorType, Alert.OK | Alert.CANCEL,
this, AlertClickHandler, "stockIcon", Alert.OK);
delete alert_ErrorMessage;
delete alert_ErrorType;
}

var GroupsTypes_sr:Service = new Service("http://yogi/flashservices/gateway",
new Log(Log.Debug), "logic.objGetGroupsTypes", null, null);
function getGroupsTypes() {
var GroupsTypes_pc:PendingCall = GroupsTypes_sr.getGroupsTypes();
GroupsTypes_pc.responder = new RelayResponder(this, "getGroupsTypes_Result",
"getGroupsTypes_Fault");
}
function getGroupsTypes_Fault(fault:FaultEvent):Void {
alert_ErrorMessage = "We could not connect to the data connector
(groupstype). Press OK below to try again or CANCEL to close this window";
alert_ErrorType = "System Error";
alert_Function = "getGroupsTypes()";
AlertWindow();
}

You can see a few lines above the "alert_Function" is variable containing the
function I would like to call if this data function fails and go to alert.

I am new to Flash MX 8 but did work a bunch in flash 5 and early mx versions.
I have done this with coldfusion and vb but cannot figure this one out.

I have tried:
this.alert_Function;
this;
?

Thanks Much
Re: Use a variable to call a function Wolf van Ween
3/15/2006 10:26:00 PM
You use eval(). But it doesn't work on all functions, for instance not on
"trace".
There was a long thread about this a few months ago, I'm sure you can find it
by searching for eval.
Good luck
Wolf
Re: Use a variable to call a function Trensic
3/15/2006 10:39:32 PM
Thanks Wolf I tried eval earlier just left it out of my examples or what I tried... It did not work but I will try and find this thread and see whats going on.

AddThis Social Bookmark Button