ActionScript 2.0 :: Calling Function (with Arguments) From Parameter
Aug 3, 2010
Let's say I have a function that accepts a function and some arguments as parameters. Something like:
ActionScript Code:
function myFunction(func:Function,args:Array):Void{
// do something awesome here
};
How would I go about calling this function with the arguments in args? It's pretty simple to call a function without any arguments, but calling it with them..
As an example:
ActionScript Code:
// I'd like this call
myFunction(trace,["Hello world!"]);
When moveBars is called, the length of the 4 colored bars change to indicate how the player is doing in different areas of the game, like so; moveBars(.1,-.2,.3,-.1)
My problem; I need to store the moveBars parameter arguments in XML like so;
<myArgs> .1,-.2,.3,-.1 </myArgs>
But I can't find the way to get those 4 numbers into the moveBars parameters from the XML doc. Is there a way to do this?
I am using the asfunction to call a function and passing a parameter. The problem is in the parameter. I can give a parameter that is over 104 characters. What ever is after that 104th character doesnt pass into the string of the function.
I am using the asfunction to call a function and passing a parameter. The problem is in the parameter. I can give a parameter that is over 104 characters. What ever is after that 104th character doesnt pass into the string of the function.
In my code there's a function that shows an image on the screen (or loads the image and shows a progress bar). This function is called by clicking on a thumbnail, and it uses a parameter [e.target.name] refering to the property "name" of the thumbnail clicked, which is an integer (or I believe so). The thumbnails are placed inside the cointaner_mc MovieClip.
Code: container_mc.addEventListener(MouseEvent.CLICK, clickThumb); function clickThumb(e:MouseEvent):void{ if (my_full_images[e.target.name] == undefined){[code]...
but I want to call this function by clicking on a button, which would need to pass another type of parameter, in this case, a variable which refers to the number of the image displayed on the screen plus one.I tried this:
Code: clickThumb(image_num + 1); But it doesn't work, I get the following error:
1067: Implicit coercion of a value of type Number to an unrelated type flash.events:MouseEvent.
How could I call the function clickThumb and make it use "image_num + 1" instead of "e.target.name" ?
Could I dispatch the event (MouseEvent.CLICK, clickThumb), passing this value "image_num + 1" ?
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!
Code: // processReplace Function function processReplace(transferFiles) { var processArray:Array = transferFiles.slice();
[Code]....
Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".
It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.
I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.
Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code
i have a question i have a primary and secondary function which i want it to be dynamic so i can get the user to enter in six to seven different or as many as required argument parameters for my primary function
Forgive me for this stupid noob question but I want to call a function (loadList) that originally gets triggered after a mouseevent from another function (addToXML) that does not have an event.
The loadList function takes info from a XML var, sticks it into an array which then gets loaded into a tile list and that is working fine.
The addToXML function when called adds elements to the XML var after which I want to call the first function with the event parameter so it refreshes the items in the tile list.
I know it can do this by creating a new array and loading that into the tile list in the addToXML function, but it be much simpler to just recall the function.
but all the event constants I have tried give me error messges like "1061: Call to a possibly undefined method addEventListener through a reference with static type Function."
Let's say I have a Custom Event Class, and it has several Event types stored in static Constant:
[Code]...
Is there an easy way to validate that the type passed to the Constructor is one of the Static Constants of the Class, without having to check it against each value?
I have a movie clip that contains several movie clips, only one of which should be shown at a time. Which one is shown, depends on what buttons the user selects.Having trouble with the syntax for passing the argument in a button to the function that controls the tweening of the clips. (When I hard code the references into the function, it works, so I know the basic function is ok).There's a clip called 'slide1_mc' which contains various MC's to be shown based on user selection (in this case, using 'system' clip as the first one already showing). Here's the code in the parent clip of that item:
Code: var currSection = slide1_mc.system_mc; function changeSection(newSection):Void { TweenLite.to(currSection,.3,{_yscale:200, _xscale:200, _alpha:0});
[code]....
Here's one of serveral buttons that will control the content to be seen:
So - the initial part of my function works so I know my 'external' initializing of "currSection" is working (that clip is zooming/fading out)... but then the clip that I want to fade in isn't doing anything.
I want to add things to the display list, some will have event listeners and some not. Is it possible to make an argument optional so it doesn't throw an error if it's not there when calling the function?
I dont want it like the classic way listenerThumbs.onLoadInit = function(target_mc:MovieClip)But with the Proxy.create class, how do I get the arguments of the moviecliploader? (ex: target_mc, loadedbytes, totalbytes)Now I did it like this, but it has to be different.[code]
I'm having some trouble passing parameters with a function that is itself being passed as a parameter.In my application code I'm instancing that class five times:they are buttons in a menu.In that class, I've got an onRelease handler that does a number of things when a button is released, one of which is to invoke a function that is defined in the application level of the code.My problem is that I don't know how to send the function parameters.In my StandardButton class I have:
class StandardButton extends MovieClip { /* define properties */[code]..........
The function is successfully being "sent" to the StandardButton class, but without any parameters.How can I send parameters to the class instance with the way I've got this architected.
lets say I define a function that does a simple trace of the arguments it takes in, now is it possible to have multiple arguments? like sometimes i want to send in a String argument, sometimes a Number, and sometimes an Array.Do I need to create the same function 3 times to accommodate for the 3 different inputs or is there a way I can keep one function but send one of the 3 values.
I am creating the columns of a datagrid dynamically at run time and I need to allocate the sort compare function to those columns based on the data type of that column, is there a way I can pass some argument to that compare function which could tell the function what type of column is it going to operate on?
function a( param:* , ... args ):void ; a.length // 1 flash.utils.sdescribeType(a); //return me informations only about first parameter , nothing about '... args'.
edit: avmplus.describeTypeJSON didnt too. So , is there any other way to check for unlimited arguments than try{} block and push lot of params ?
How to pass boolean arguments to a function[code]On the stage i have all the MC - screenX, alarmsX, criticalX, majorX,warningX, redX, orangeX, greenX.But i get errors:Scene 1, Layer 'Layer 1', Frame 1, Line 171119: Access of possibly undefined property visible through a reference with static type Boolean.for each of the MC.
I have four NetStream objects that receive cuepoints from different videos. I'd like to define one function for them all instead of using four inline functions and I'm stuck with syntaxHere's the code:
I have a main class that is running an external sub class which loads my data (loads data via flash remoting on a ColdFusion server). No problems loading the data; however, I am trying to run a function from the main class on the sub class function onResult. I do not have problems running functions in the sub class in general, only in the responder result function. Problem: My problem is that I can't pass the main class through the function onResult because I get a error with the arguments.Here's what some of the code look likes:
function init(){ myService2.connect("URLgateway"); var responder:Responder = new Responder(onResult, onFault);
Is it possible to wrap a variable-length-arguments function in Actionscript?[code]but it didn't work since sprintf was called with just 1 extra argument, i.e. the Array args.