ActionScript 3.0 :: Pass Additional Arguments To An Event Listener Function?
Aug 19, 2009I am trying to pass an additional arguments to my listener function, like this[code]...
View 8 RepliesI am trying to pass an additional arguments to my listener function, like this[code]...
View 8 RepliesSince when using sql lite if you try and do a function at the same moment it throws an error, im just trying to make a function that will check if its executing, and if it is try again in 10 milliseconds, this exact function works fine if i dont have to pass any arguments to the function but im confused how I can pass the vars back into the function it'll be executing.[code]
View 4 RepliesIn AS2, I often found it useful to pass arguments to a function on a button press like so:
btn.onRelease = function(){
doSomething("arg1", "arg2", "arg3");
}
I searched the interweb for DAYS trying to find how to accomplish this via an event listener in AS3, but everything I found suggested creating a custom Event. The problem with this, is you have to decide the arguments you wish to pass in advance, and I wanted to create them dynamically on the fly ( for example: passing a string that a user entered into a textfield to some function for processing ).
So last night I spent hours scouring forums - and UREKA! I finally found something that I was able to tweak to send a variable number of arguments of any data type. I've never posted on a forum, but it was such a breakthru that I had to share it with the world.
Here is the code:
btn1.addEventListener( MouseEvent.CLICK, function onClick(e:Event ) { displayArgs(e, new Array("Larry", "Curly", "Moe") ) } );
btn2.addEventListener( MouseEvent.CLICK, function onClick(e:Event ) {
[Code]....
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].....
private function myFunction(numIn:Number){
trace ("numIn " + numIn);
}[code].....
This won't work, but can you see what I'm trying to do? It's kind of like a function pointer, or when you pass a function name into an event listener.
How do i pass a variable to a function from an event listener which is inside a function Below is a function that is called when after loading some variables
function dataOK(mydataevent:Event):void{
var j:int = 0;
do {
trace(j);
[Code]....
This is a simplified version of the original code. The above function generates an error because j is undefined in the function. I am wanting to get the variable j when the button is pressed.
How do I pass the variable j to the Button_Click function?
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 RepliesI'm working on a website navigation wherein I want that on clicking the navigation buttons, a movie clip eases out to that clicked button to show the current page. I'm able to move the movieclip to the button's location but I need to remove the event listener once the movieclip stops over the navigation button.
Code:
import flash.events.Event;
btnStart.addEventListener(MouseEvent.CLICK, startMovie);
function startMovie(e:Event):void {
ball.addEventListener(Event.ENTER_FRAME, moveBall(btnStart));
} function moveBall(bt:SimpleButton):Function {
[Code] .....
I've written an event listener that passes 2 arguments with it. Now, after the condition is met,I've to remove the event listener but with no success..Here's the code:
//Function animateChar called on Enter Frame event with 2 arguments
www.addEventListener(Event.ENTER_FRAME, animateChar(184, 86), false, 0, true);
//Here's where animateChar is defined
private function animateChar(__x, __y):Function { return function(e:Event):void { var t = e.target; t.x += (__x - t.x)/speed; t.y += (__y - t.y)/speed; if ((Math.round(t.x) == __x) || (Math.round(t.y) == __y)){ t.removeEventListener(Event.ENTER_FRAME, animateChar); // Not working.. } } }
I have this code:
var service:HTTPService = new HTTPService();
if (search.Location && search.Location.length > 0 && chkLocalSearch.selected) {
service.url = 'http://ajax.googleapis.com/ajax/services/search/local';
service.request.q = search.Keyword;
[Code]......
I want to pass the search object to the result method (onServerResponse) but if I do it in a closure it gets passed by value. Is there anyway to do it by reference without searching through my array of search objects for the value returned in the result?
I'm having a little problem with how to use the argument sent to a function.I have this:
Code:
_root.onEnterFrame = function() {
setPanning(1);
[code].....
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?
View 1 Replies[Code]...
I have an object that has all the elements I would want to pass arguments: var args:Object = { 'dog', 11, myArray }; and I want to be able to pass the contents of args to doSomething without making any changes to doSomething (assume it's someone else's function) and I'd like to do it in a way that doesn't assume I will know anything about the contents of args.
I have an array with some values and i want to pass this values to a function arguments.
example
var theArray:Array = new Array("test1","teste2","teste3");
function hello(t:Number,a:Array){
// do something
test(a)
[Code]....
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 headed some problem which can't solve. It's simple. I'm making slideshow, and wanna pictures to be dynamically loaded. List of images is stored in list.xml - a valid xml file. Now, here is piece of the code:
var imgno :Number ; //the var which tells the number of images listed in list.xml
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
[Code]....
So, the triggered function processXML cannot change value of any variable which stands out of her. Is there a way to export (in this case) information about amount of images listed in list.xml to some of the variables that I can use later (for example imgno).
I have 3-4 swf those i want to load one after another like a slideshow.What i want to do is get the total frames of loaded swf and want to pass that value to Timer object's delay parameter. i have converted total frames to milliseconds so i can use it in timer constructor. But i am not getting the value of that variable outside of my Event.COMPLETE listener method. Here is my code what i have done
[Code].....
I'm moving on to my next massive programming project and I'm trying to decide whether I should code it in as 2.0 or 3.0. I came across the new click event model in 3.0. Right now it's looking like a pain in the butt to me. So now I have to make a function and add it as an event listener? what the hell? What's the benefit? I understand stuff like this makes AS a more complete language but it's kinda annoying.
View 1 Replieshow do i use two event listeners on one function. For example, i want a mouse_move and enter_frame event listener with one function
View 2 RepliesI need to upload a file from my Flex interface to a folder located on the server.
I use the following [code]...
Problem: I need to pass an additional argument to my upload.php script (actually a String - the name of the folder I want it to be uploaded). Is there a way to do this?
I'm trying and it doesn't seem to like it. I'm guessing it's not possible?[code]...
View 5 RepliesI am working on a game for my university project and I have run into a bit of trouble. I have the following code here:
function launchBall() {
this.stage.addEventListener(KeyboardEvent.KEY_DOWN ,launchBallHandler);
function launchBallHandler(e:KeyboardEvent):void {
if (e.keyCode==32) {
[Code].....
Its set up so that when a ball goes off screen, it resets to a coordinate and launchBall is called.
LaunchBall then adds the event listener to see when the Space key is pressed and that starts the ball moving again. The problem I have now is I cant seem to get rid of that eventListener. I have tried removeEventListener and that doesn't seem to work. I have tried:
if (ball.xVel>0 && ball.yVel>0) {
removeEventListener(KeyboardEvent.KEY_DOWN,launchB allHandler);
just below that code and that doesn't work either. It's not spitting any errors out at me but I am completely stumped.
I just started a course that does a little flash. To teach us they have us build a brick breaker game. I have come to a part were I have to remove all the Listener that were created for the game. Each level is a movie clip and when the level is over the level instance is removed from the child. From what I understand when the level is removed the Event.REMOVED_FROM_STAGE becomes true and the function attached should be called however it is not. Here is the code of the function that sets the listener and the function to be called:
[Code]...
I have a method which registers an event listener to each of the MovieClips in an array I have. The method is inside a class, and so is the listener function. The problem is, I'm getting an error that's says "Access of undefined property handleNavToggle", even though is declared.
[Code]...
So I guess the usual stuff is to have
function listenToEvent(evt: Event){
//stuff
}
[code]......
In AS2 we can add additional event handler on same event as below code does.
on (rollOut, dragOut) {
// Statement 1
}
Now , I am workin in AS3 . So, how to add additional event handler on event in AS3
Let's say display Object's instance name is "myBtn"
Here I have include only Mouse Out only, Now I want to add additional event handler
myBtn.addEventListener(MouseEvent.MOUSE_OUT, myBtnEvent);
myBtnEvent(event:MouseEvent):void
{
// Statement 1
}
I'd like a movie clip called "following_cursor_mc" to follow the cursor, regardless of which of several different frames the playhead may be on. I've reproduced the code below on each frame in which I would like the cursor to be followed by "following_cursor_mc" but these errors are thrown for each of the frames:
1021: Duplicate function definition.
Just wondering how to set up an event listener to trigger a function when a movieclip reaches a certain y position?
Say the movieclip is called ball_mc.
I'm trying to return XML from an event complete back to the main function, but can't figure out how to do it.Here's the functions I'm calling:Main File:
public var mySendAndLoad:SendAndLoad = new SendAndLoad();
mySendAndLoad.sendData(url,variables)
The mySendAndLoad class:
[code]........
How would you remove an event listener from a nameless function?[code]
View 7 Replies