ActionScript 3.0 :: Fasting A String As A Function?
Jan 26, 2009
First post, frequent lurker. I'm wondering if it's possible to cast a string as a function in AS3, for example
var foo:String='myFunctionName';
var dynamicFunction:Function;
// pseudoCode (this used to be done with eval() in ancient versions of AS).
dynamicFunction=Function(foo);
dynamicallyCreatedMovieClip.addEventListener(Mouse Event.ROLL_OVER,dynamicFunction)
Scenario: 4 areas on 1 stage which are quite similar (eg webcamconference, each area has the same functions)
Buttonobjects are numbered(eg area 1 has playbutton1,mutebutton1,namebutton1,namelabel1, etc)
every area gets a close-Button which closes/shuts down the area.(close1,close2,close3...)i want to archive the following:
if(close1.isPressed){ function invisall(1); }[code]....
this should do the trick via dynamic Nr at the end of each default button(eg playbutton) but ofc
"playbutton1"._visible=false;
doesnt work because playbutton1 is still a String.how can i take the String as a Buttonname /ButtonObject? do i need to write an new function? this would destroy the purpose of less code. for now i will split the area into frames that i put on the stage.
Is there a good way to get the name of a function in as3 in a String or as a String. I have seen sneaky ways by forcing an Error call and stack trace, but that is not what I am look for.
I want to have a loader function that passes the loaded data to the correct function. So I can do this:[code]Is there any way to type the second variable to avoid the clumsy switch routine, like so:Function (sendTo) ();
Is it possible to call a function from a string? such as if I passed the name of a function to this function, is there a command to convert the string to a function call? :
I'm trying to create a simple xml search function that searches an xml file for a string, and if that string is found in the xml, display the node which contains that string in a text box.I have the simple search function working, but what I can't do is return the specific node. Right now, the function is returning all the xml data instead. If someone could take a look and possibly lend some guidance as to how to return the specific daya, I would be much oblidged. Hope this makes sense, if not, let me know and I'll do my best to clarify.[code]
I really need to reference the variable while INSIDE the onRelease function, because I need to apply some actions based on how many times the button has been pressed.
I have a class that has a timer function built into it. When this timed function is called, I would like to be able to call another function when the timer is finished (which I would do in the TIMER_COMPLETE handler).
If I pass the name of the function to my class function, could I use that string(?) to call the function at the end of my timer?
How to display the correct digits. For instance, if the answer is 97%, I want the display to show 97, not 11. Please feel free to view the SWF or look at the FLA file to see[code]...
im making a function that limmits text to a specified number... only problem is i cant seem to pass in the text var that contains the text
Code: var textF1:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam neque purus, aliquam sed, sagittis tincidunt, adipiscing ac, urna. Ut libero urna, nonummy sodalesxxx";
I have an online app that allows a user to select as many strings as they want from a dynamic textbox, then run a function on them. Can you do that without a for loop so that it runs the function on them all at once?
I would like to download a function as a string from my server into a Flash swf-document on the computer of a customer. So this download would be executed client-side. Then I would like to 'execute' the string, just as I do with the 'eval'-function in php/javascript.The important thing here is that the function is not stored client-side on the harddisk (like the swf-document) and that the function only remains in the computer memory.
I thought I would share a simple pad string function I created briefly... I know that there may be other similar functions already out there but I decided to make it anyway. It's basically a ripped off as3 version of the str_pad() php function.
[code]causes this error with mtasc compiler:type error String has no field myFunction it must be possible to add new functions to a class via prototype.is there any configuration i can do for mtasc to be able to compile this code?
I've got different functions in actionscript 3, one function generates random numbers each time there's a button click. But with another button I want to call the random number which is generated at that moment. I have to call the random number from another function then, but these are two different functions so it just considers it as an undefined property.
[Code]...
But I can't call randomnummer1 because it's inside another function. So I get the property undefined error.
my goal is to keep my output window organized so i can follow all my traces more easily. so i wrote a couple of custom functions to achieve that. one of them would be: to more easily trace the following variable for example
ok so i have this function basically it adds text to a given position in a textfield. it adds the text in the correct position but the problem is that it is screwing with the formatting i've applied to the textfield.
here is my code:
ActionScript Code: txt.text = "hello world"; // adds text at the character index specified and returns the new string. function addText(txt:TextField, txtToAdd:String, index:Number):String{
[Code].....
i also have a function which deletes but that isn't important right now. i was trying to avoid using html text but at this point i'd willing to give virtually anything a try.
I am using AS 2 in Flash CS3 and XML. I have the function named in the XML file which I would like to be called via a rotating banner. However I can't seem to convert the string (read via the XML file) to convert to the function name. a trace reveals that the correct string is being called: _parent._parent._parent.loadFunction. urls[count] is the array that stores the function name. Here is the script:
I need to be able to get the int returned on this. If I serach for any letter as a string I get the search function working right. If I run it like it is below I get back 0, which I should get 3.
If I have the name of the function I want to run in a string called function_name and the params I want to pass to the function in another string called function_params, how would I could this to go in a button with the following code:
mc.button1.addEventListener(MouseEvent.MOUSE_DOWN, button1_handler); function button1_handler(Event:MouseEvent):void { // Dont know what to put here
I'm wondering if its possible in flash to be able to call a static class function via its name as a string. I know for you're usual case you can do this to call the function 'func'
Code: this["func"](); func():void { trace("I'm a function"); }
However I'm wanting to do this from another static function and in a static function you obviously can't use the 'this' keyword. I've tried just omitting it, or replacing it with the class name but neither work.
I'm using the Gaia Framework to develop a website, I'm still getting used to it but it's been great so far. There's a part in a page class where I want to call certain functions to initialize some effects on every deeplink. I'm doing good, but I need to call a function through concatenating some strings. Please have a look at some code of my class and read the comments for a better understanding:
Code: private function FUNC_que():Void{ SEC_que.b1._width = 0 stringTyper(SEC_que.t1, st1, 15, 8) var ts2 = new TextShuffle(SEC_que.t2, st2,SEC_que.b1);
I'm trying to make children of a tile and put them in their respective locations. To do that, I need to know what kind of tile is to be created, but if I just use my old method:[code]I will have to use a chunk of code like this for every single imaginable tile. Obviously, that is not efficient! So I'm trying to optimize it by having what tile type is to be posted saved in a string, then using the string to refer to what child is to be created, something like below:[code]how to make the above code work. Surely, there is a way to do this?