ActionScript 3.0 :: Pass More (like "...rest" Unknown Number) Of Args To Another Function?
May 24, 2009I have a function:
Code:
function test(arg1:int, ...rest) {
function anotherTest(rest); // -> Seems not working
[code]......
I have a function:
Code:
function test(arg1:int, ...rest) {
function anotherTest(rest); // -> Seems not working
[code]......
I have a project that uses a lot of remoting calls and I'm hoping to abstract the process. I've hit a problem with passing parameters to the final call...[code]...
I know how to loop through the ...rest param to obtain their values but I'm struggling at how to construct the final gateway.call() which could have 1 arg or 10.
Basically what I'm trying to create is a custom timer that uses frames rather than milliseconds. But I can't figure out how functions like setInterval calls the function you passed along with the arguments. First I create a reference to the function I want to execute after a certain interval and name it fc, then I create a list of arguments my function want to pass using Array, but then how do I put those arguments in fc()?
View 2 RepliesI'm making multiple similar calls with similar results to one remote object. Because these calls are so similar and very changeable, I've been keeping the name of the remote method in a config file, and when I need to make the call I use getOperation() on the remote object, and call send() on the operation object. However, the requirements have changed so that not all of the calls will have the same number of parameters. Because send uses ..., will I be able to continue using the same formation and pass an array, or will send() treat that as passing one argument of type array?
View 2 Repliesis there anyway to pass the setInterval id number into the function you are wanting to run.
I want the function i run to run clearInterval when a certain test suceeds.
I'm making numerous ExternalInterface calls to JavaScript methods and have a helper function for doing so:
[Code]...
However this means the JavaScript method will only be passed one argument - the array of arguments - meaning I have to change the JavaScript to accomodate this, e.g. instead of:
[Code]...
I want to pass a rest in a netconnection call, something like this:
public function requestData(service : String, ...params) : void
{
nc.call(service, params);
}
this doesn't work since the call is expecting each parameter to be separated by commas, like:
nc.call(service, params[0], params[1], params[2]);
I've read some posts about apply, but I can't find a solution for this specific case.
I'm trying to load a known number of variables. So I set up this code in flash[code]...
View 1 RepliesI'm trying to load a known number of variables. So I set up this code in flash[code]...
It recive "antal"which is how many variables there are. The variables name are named produkt_0 produkt_1 produkt_2 produkt_3 and so on..
So it collect the varibales correct i've checked this by set loader.data.produkt_load to loader.data.produkt_0. But since I don't know how many I just can't set loader.data.produkt_load to loader.data.produkt_0. Insted I want produkt_load be a variable like it is in my code, but it seems that loader.data.produkt_load became undefined, why this? Can't you set a variable that change in loader.data.hereismychangingvariable?
i wanted to a load unknown number of variables from a text file
View 1 Repliesto pass an unknown number of variables to a function and do the same thing with each one.
[Code].....
Does anyone know how to load an unknown number of photos into an array from a specific file path? I want to then use them in a photo carousel.
View 3 Replieshow to do this
function foo(x:*, ...args):* {
}
function bar(x:*, ...args):* {[code].....
how to expand args ? when I call bar(1,2,3), I wish it call foo(1,2,3), but it call foo(1,[2,3])
I have an object MyTester, that has an instance of another class MyClass, and I want to test MyClass API through it:
public class MyTester {
internal var myObj:MyClass;
public function MyTester() {
[Code].....
How can I cancel the switch and make it work for any number of arguments?
I've made an user login, working with php and MySQL. When the user logs in, he can see all of his details, loaded from a database. Here he can press a button to change this content. After changing it, he needs to press the "save" button to load the new data into the database. But everytime the user presses the save button, it's adding an extra line to the data into the database, which results in an error of displaying the data. Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0 Fatal error: Unknown: Failed opening required 'google_verify.php' (include_path='.:/usr/local/lib/php') in Unknown on line 0
View 1 RepliesI'm trying to convert some C# code I have and one problem I can't find a solution for is to have a function take parameters of unknown types.
C# code:
PHP Code:
public T Maximum<T>(T v1, T v2){ return v1 > v2 != null ? v1 : v2;}
A straight translation to AS3 would look something like this, for making it easier to understand for people that might be confused by C# syntax.
[Code]...
This way you can send in anything as the parameters (notice the <T>), be different classes for example, depending on what situation you want to use it, instead of writing a lot of duplicate functions for every possible parameter type.
Is there a way to do this in AS3? Edit: Seems like I managed to find a solution right after I wrote this. Seems like one can use "*" as parameter type.
For example i have function declared in AS3.0 class:
private function log():void{
// working with arguments directly here
}
I'm calling:
log('some stuff',object,array,etc);
Then i'm calling:
log('ok');
Ofc FlashBuilder throws exception with: type 1137: Incorrect number of arguments. Expected no more than 0
In javascript it's possible. But in AS not, isn't it's ECMA based? Why so strict...
Update
Ok nvm. Created like that atm: log(m1:*=null,m2:*=null,m3:*=null,m4:*=null,m5:*=null):void{}
I'm trying to extend the functionality (not extend the class itself) of the netconnection.call() function by enclosing a netconnection instance in a class.What I'm attempting to do is have a function that I have defined as "call" make a call to mynetconnection.call("", null, ...rest). For example:
Code:
public function call(method:String, ...rest):void {
this.mync.call(method, null, rest);
}
I have tried repeatedly to do this, and it's not working. The rest parameter feeds the parameters into an array, but is there any way to undo that on the inside of the method and pass a pseudo-list of parameters to nc.call() so that it will see it correctly?Is it possible to duplicate the functionality of a ...rest parameter into another function?
I have a function that uses the ... rest argument as follows:
public function dispatchActions(... actions):void
{
var params:Object = new Object();
params.actions = actions; // I also tried casting ie. = (actions as Array)
this.target.dispatchEvent(new ActionEvent(ActionEvent.dispatchActions, params));
}
I call it using myActionObject.dispatchActions("all"); The problem is that when a listener receives the dispatched params object and try to access the actions array, it does nothing. If I try to trace evt.params.actions it traces blank and if I try to trace evt.params.actions[0] it traces undefined.
ex:
function actionsListener(evt:ActionEvent):void
{
var actions:Array = (evt.params.actions) as Array; // I also tried without casting
trace("actions", actions, "actions 0", actions[0], "action 1", actions[1]);
}
This is the output: actions actions 0 undefined actions 1 undefinedI don't understand why I can't pass the ... rest argument through an object as an event parameter. How can I make this work?
my functions in this fla i have. I use the function to create a random number and the char move accordingly depending on the number.
View 4 RepliesI'm working on a function that replaces an existing movie clip with a symbol from the library and then designates an "updater" function for the new instance. I have the first part working as intended, but I'm not sure how to approach creating the "updater" function.I've considered using event listeners, but I'm not sure if that is my best option.The following is a excerpt from my code. This code is on the timeline of a movie clip. The movie clip is on the main timeline with an instance name of slideUpPanel_mc.
ActionScript Code:
var window_mc:MovieClip = window_mc; //window_mc as it exists on the timeline
var windowUpdateFunc:Function; //reference to updater function in window_mc
[code].....
I'm a professional flash game developer and my week planning is to learn AS3 (kinda..I've just started something but there is one minor problem.... I can't find a way to pass args with eventListener
[Code]...
I want to pass a number value to a Timer. How do I do this? My number and integer values for other variables work fine.
I get null object reference and coercion of value, because I'm not passing to 'timer' properly. I don't want to say my variable's a number, I want to say it has a number value.[code]...
Is there any way to determine if a (anonymous) function has defined the ...(rest) parameter in ActionScript 3? I know there's the function.length property, but it only counts the explicitly defined arguments.
View 2 RepliesI'm new to ActionScript and am having trouble hooking up callbacks to take extra, dynamic args.The basics are: I have a method that takes a couple of parameters, uses a RemoteObject to send an operation to get a third value, and I want to pass all three (the operation result and the original two) to another callback.[code]This does allow passing extra args, but it is adding a new listener each time createMeeting is run. So I would need to remove the old listener, but I don't have a handle on the old callback since it was dynamically created/anonymous (I'm not sure of the correct AS terms).I guess I could create a custom event dispatcher that kept track of the previous listener. But maybe removing and adding new listeners each time is the wrong solution to begin with. How would you set up a listener like this when the extra parameters you want to pass to the callback will be changing?
View 9 RepliesIs there a way to get Flash to know what frame it's on and pass that as a variable? I can't use counters because I'm using a random frame function.
View 3 RepliesI'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.
I've got a function wich can accept a varible number of parameter with a rest operator. I want create an object passing the argument collected with the rest operator directly to a constructor without create an object and call an initializing function and without passing the entire array but the parameters ah I do with apply() function.
[Code]...
(Spoiler alert: It's not an issue of my package statement not reflecting the location of my class file.) When I have a class linked to a MovieClip in my library and that class takes an argument in its constructor method. That class will compile properly ONLY when it's located in my top-level directory (same dir as the .fla and Document.as files). If I move that class to a deeper directory, say com.place, the compiler will generate error "1136: Incorrect number of arguments. Expected 0.
[Code]....
My question is can you write a function in an XML document and then load that XML document into Flash and call that said function?
View 5 Replies