ActionScript 3.0 :: Passing Additional Parameters To Function Listeners?
Apr 28, 2006
hboxvar.addEventListener("mouseDown",dosomething(3 43));
hboxvar.addEventListener("mouseDown",dosomething(1 23));
hboxvar.addEventListener("mouseDown",dosomething(1 2342));
public function dosomething( somenumber:Number ):void {
//do something here
}
I try to do above function but I need to pass variable from hboxvar but not from inside function suggested by macromedia.
any one frustated with this way of passing multiple parameter which depends on what to pass in flex 2 using addEventListener ?
[URL]
Passing additional parameters to function listeners You can pass additional parameters to function listeners depending on how you add the listeners. If you add a listener with the addEventListener() method, you cannot pass any additional parameters to the listener function, and that listener function can only declare a single argument, the Event object (or one of its subclasses).
View 9 Replies
Similar Posts:
Jan 28, 2009
I have already created a custom mouse event which seems to work fine. It is simply a mouse event which passes an additional sound object. The problem is I am passing this event to another class which checks for collision of a movie clip with another and if true it adds the sound to an array. What I think is happening is a type conversion problem between my customEvent and the MouseEvent. [code]...
View 3 Replies
Sep 28, 2011
I have a 16x16 grid of buttons, and want to add an event listener to each of them so when clicked it will return its unique grid position number (anything between 0-255);
What I have so far:
public static const GRID_SIZE:Number = 16;
private var i:int;
private var j:int;
// Constructor
public function Grid()
[Code] .....
Unfortunately every time the listener function is called by each button, it uses the last two values of i and j, which in this case return 255 for every button.
View 4 Replies
Jun 21, 2009
I'd like to know what's the different using global functions and functions with param..Why using params? When the as3 developer uses it?
View 3 Replies
May 20, 2008
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:
Code:
ns1.onCuePoint = callCuePoint;
ns2.onCuePoint = callCuePoint;
[code].....
View 4 Replies
Feb 3, 2006
way to say the same in just a few line of code? 25 lines of code people
[AS]menuAS = function () {
//TIOCCHA
menuBar.menu01.menu01_btn.onRelease = function() {
[Code]....
View 6 Replies
Apr 7, 2009
i am loading an image with a loader, and in onComplete function i would like to call calculateRatio function and pass it Loader.content.width and Loader.content.height so it can compare it with the current stage width and height and resize image proporcionally to fit the screen. how would i go about passing that parameters?
[Code]....
View 4 Replies
Mar 4, 2004
{Flash MX 2004 Pro}
[Code]...
The above does not work. Infact the function is not even called. How can I pass parameters to such functions. I dont wanna do the following:
[Code]...
View 1 Replies
Feb 26, 2009
Code:
function enableButtons():void
{
for (var i:uint=0; i<40; i++)
[Code]...
I have 40 buttons on the stage. Their names are contained in the Array musicGrid. What I'm trying to do with this code is attach an EventListener to each button so that it will call the function mgMouseBehavior with a parameter to identify the button. For example, I want the button at musicGrid[0] to call the function mgMouseBehavior(0). I want the button at musicGrid[32] to call the function mgMouseBehavior(32), and so on.
However, if you try to add parameters to mgMouseBehavior in the addEventListener, for example:
Code:
musicGrid[i].addEventListener(MouseEvent.CLICK, mgMouseBehavior(i));
Then you get Error 2007: Parameter listener must be non-null. How would I accomplish what I'm trying to do?
View 2 Replies
Aug 17, 2010
I'm attempting to write a performance testing function that can take any function, run it X times and spit out how long it took that function to run in AS3. I've got it working just fine if a function doesn't take any parameters but it comes up with an error otherwise.Here's the code:
public static function testFunction(targetFunction : Function, object : Object, ... parameters)
{
[code]........
View 1 Replies
Mar 4, 2004
{Flash MX 2004 Pro}
[AS]
myMovieClip_mc.onPress = foo(true);
function foo(state:Boolean) {
Do something
}
The above does not work. Infact the function is not even called.How can I pass parameters to such functions.I dont wanna do the following:
[AS]
myMovieClip_mc.onPress = function(true) {
//
}
View 1 Replies
Jul 23, 2009
Look at the simple code below:
Code:
stage.addEventListener(MouseEvent.CLICK,traceMe);
function traceMe(evt:MouseEvent)
{
trace ("hello world!");
}
What if I want to pass a parameter to the traceMe function? There is a way to do that?
View 2 Replies
May 9, 2009
Consider the function below:
function personal(Name:String,age:int,city:String):void{ trace(Name+" is "+age+ " years old and lives in "+city+ ".")}
The parameters can only(???) be passed in the order they are declared in the function as
[code].....
View 13 Replies
Feb 12, 2010
I've got an XML file that is loading in data and is calling functions.
how to call the methods from classes with variables set from the XML file:
var functionToCall:String = xml.functions.func[0].to_fire.toString();
myClass[functionToCall]();
This calls the function perfectly.
I was wondering if there is anyway to pass parameters into the function as well through variables. Some functions may have no parameters, some functions could have 5... so the xml could be like this:
[Code]....
View 5 Replies
Jul 24, 2011
I have a function at the server side that loads an XML and makes a photo/link array from it.I want to pass this array to the clients swf to use it for a photoGallery.nd the array = [1,2,3,4] to the client and trace it at the client side?
View 1 Replies
Jan 31, 2008
I am wanted to know how can i pass a parameter to the function which I'm calling using Delegate class. I know to pass params having static values such as true / false or a static string "hello".
Code:
var myFunc:Function = btn.onRelease = Delegate.create(tihs, releaseHandler);
myFunc.str = "hello";
function releaseHandler()
[code]....
Here str can be retrieved as 'arguments.caller.str' inside the function.But in case i want to pass the reference of the 'btn' button. Then how can i do this ?
View 3 Replies
Dec 18, 2008
I have an FLVPlayback component with several ActionScript cue points designated along its timeline. I've written a listener that successfully executes a function whenever the video reaches one of my cue points. However, I'd like it to do different things depending on which of the cue points it has reached.
Here is my code:
Code:
// these are the cue points that I'm adding to my video
_root.thevid.addASCuePoint(33, "show1");
_root.thevid.addASCuePoint(43, "hide1");
[Code]....
Essentially, I would like for the function to accept a String name from the cue point, and then decide which action to take (either showing or hiding something). I don't know the correct syntax for accepting information from the cue point. Should I pass the cue point into the function as an object, then parse its name from within the function?
View 1 Replies
Dec 2, 2009
I have benn programming in AS2 for a while, but I'm moving to AS3, and I'm having some trouble with syntax and mostly with management of parameters and variables (actually I tried to work with functions in packages without good results T.T). The game has four different types of shooters, and all of them use the same bullet (shoot function). I have succeeded on disappearing the target (a coin in this case) when it is hit by the bullet, but the problem is that I can't quite find the way to dissapear the bullet properly. I keep receiving this message:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at eco_adm9_fla::MainTimeline/moveBullet()
[code].....
View 3 Replies
Jan 1, 2012
I'm making a function, and I want to pass it's handling less restrictively, kinda like jQuery I guess.
Code:
function cfunc(min, max)
{
return (Math.floor(Math.random()*(max-min))+min);
[Code]....
Now I know that alternately, I could pass them individually to the function and then join them all together as one, but I'd prefer to use one variable and pass the data through it, kinda like a scripting engine.
View 1 Replies
Feb 15, 2009
I have a series of identical buttons. I want each one to delete a certain item from an array.But the function that deletes the item from an Array is obviously also the MouseEvent function that the listener looks at, which to my knowledge can only take one parameter.
View 5 Replies
Jun 18, 2009
I have shortened this example to keep it simple, otherwise I wouldnt be doint this
I need to pass different variables to function inForLoop each time.
Code:
function someFunction():void {
for (var i:int = 0; i < columns; i++) {
for (var j:int = 0; j < rows; j++) {
[Code]....
View 3 Replies
Sep 20, 2009
im sure other ppl have been faced with this dilemma. say that you are attaching an event listener to an object which obviously if revoked, will call a function. now how do you send additional params with listeners?so you get something like:
Code:
public function eventHandler(e:Event, additionalParam:*){}
i have a solution for this and that is to attach it to the caller so it could be accessed with e.target.variable but i dont know if this is the way to go.
View 5 Replies
Apr 26, 2009
can anyone tell me how to load external .swf using loadClip method with additional parameters?[code]
View 3 Replies
Mar 14, 2012
I have a menu which is created from an XML file. I'm using LoaderMax to grab the data and do the magic:
[code]...
View 1 Replies
Sep 3, 2009
Suppose I want to create a bunch of buttons using a loop. But I want each button to do something different. Suppose the buttons are numbered and I simply want each button to print out its unique number when clicked. Heres what I have so far:
Code:
var t:CTextField;
for (var i:int = 1; i <= 100; i++) {
t = new TextField();
[code]...
Ive tried many different things to get this to work, but none of them worked so I wont bother posting them all. At best, I got it so every single button traced "button 100 was clicked". I sort of understand why that happened, but I dont know how to make it work properly. Once again, all I could find was people saying "use custom events", but I think I need a lot more details than that. For example, I dont see how changing
Code:
t.addEventListener(MouseEvent.MOUSE_DOWN, buttonClicked);
to
Code:
t.addEventListener(MySpecialMouseEvent.MOUSE_DOWN, buttonClicked);
View 14 Replies
May 9, 2010
Is it possible to pass parameters through for instance a MouseEvent.CLICK, or Event.ENTER_FRAME, if so then how?
View 3 Replies
Oct 23, 2010
Would it be possible for something like this to happen?
Code:
addEventListener(KeyboardEvent.KEY_DOWN, loop);
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event, key:KeyboardEvent) {
//do something
}
I get the error
ArgumentError: Error #1063: Argument count mismatch on Turret/loop(). Expected 2, got 1.
View 1 Replies
Nov 11, 2009
I am fairly new to AS3.
vancouverMC.dotsBttn.addEventListener(MouseEvent.M OUSE_OVER, mcIn(vancouverMC));
vancouverMC.dotsBttn.addEventListener(MouseEvent.M OUSE_OUT, mcOut(vancouverMC));
function mcIn(mcName:MovieClip):void{
mcName.gotoAndPlay("in");
mcName.ringMC.gotoAndPlay("on");
} function mcOut(mcName:MovieClip):void{
mcName.gotoAndPlay("out");
mcName.ringMC.gotoAndPlay("off");
}
Why this is Not Working?
View 2 Replies
Jul 6, 2011
I got a huge problem trying to color objects that are flying around in my space game. When I shoot and hit them - the affected enemies shall blink. The graphics are pre-rendered (i.e. there's an rotation array and function where the degrees and their appropriate rotation for the objects are stored / calculated for better performance).
So - my idea was to enhance that rotation function with a functionality for additional coloring; but the colored AND rotated objects shall be stored apart of the normal rotated objects. To accomplish this I made a nested array: in row one there are 360 rotated graphics of one object and in row two there are 360 graphics of a rotated and colored object.
[Code]...
View 1 Replies
Aug 19, 2009
I am trying to pass an additional arguments to my listener function, like this[code]...
View 8 Replies