ActionScript 3.0 :: Pass An Argument To The Function Triggered By An Event Handler?
Mar 31, 2009
Trying to migrate my way of thinking from AS2 to CS4/AS3. Ok, I have 2 buttons on the stage. Each button does almost the same thing, so I want to create a single function, and each button calls that same function (we'll name that function "Navigate")... however, the function will need to end up doing something different dependant on which button was clicked. So, previously, in AS2, I would've added some code onto the buttons themselves with on(release) methods (see CODE EXAMPLE 1) So, each button effectively calls the Navigate function, and passes a different frame label to the function. Now, I'm trying to recreate this functionality in AS3. As you all know, on(release) has been done away with (still don't know why), but we now have to use event handlers, so I'm trying to figure out a way to pass a different frame label argument to the Navigate function. Currently I can achieve that by using a switch statement to test which button was clicked, and act accordingly (see CODE EXAMPLE 2).
[Code]...
View 2 Replies
Similar Posts:
Mar 31, 2009
Ok, I have 2 buttons on the stage. Each button does almost the same thing, so I want to create a single function, and each button calls that same function (we'll name that function "Navigate")... however, the function will need to end up doing something different dependant on which button was clicked.So, previously, in AS2, I would've added some code onto the buttons themselves with on(release) methods, like so:
Code:
// Define the Navigate function
function Navigate(myLabel){
[code].....
View 7 Replies
Nov 19, 2009
I have one event handler for several object's events. I would like to pass a value through to the function from the event listener:
PHP Code:
function chkEmpty(event:Event){
if(event.currentTarget.text==""){
thisIsBitIWantToBeAbleChange.text = "You haven't entered anything in the box, please try again"
[Code].....
Could I give the event.currentTarget a value that I could test for? So if the value is 1, I effect output1_txt, if 2, output2_txt, etc etc. If so, are there customisable values that I could use that wouldn't do anything to the display object,?
View 6 Replies
Jul 11, 2011
I want to pass parameters when an event is triggered. My function:
private function keyChange(e:KeyboardEvent, setValue:Boolean):void
so that I can use the same function to set if a key is up or down. How would I write the event listener? I tried:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyChange(,true)); however that didn't work.
View 3 Replies
Nov 11, 2009
How can I pass a 'set' function as the Function Object argument of another function?eg:
public class IdModel
{
private var _id:String;
[code].....
View 1 Replies
Jan 15, 2008
I have 3 buttons which will do basically the same thing(2 fade when one is moused over). I have it working but was wondering if there was a cleaner method instead of using a switch function within the handler.
Here's my code:
Code:
btn1_mc.addEventListener(MouseEvent.MOUSE_OVER, menuOver);
[code]....
View 7 Replies
Jul 21, 2009
im trying to pass in an optional argument into a function. The datatype of this needs to be an object... however, im not getting very far. I know i can do this....
[Code]....
View 3 Replies
Mar 14, 2009
I have recently moved from AS2 to AS3 and I am finding the transition fairly easy, however I do have a few questions, some of which may not have been possible with AS2 but I would like to achieve them in AS3
1. Is it possible to pass the name of a class as an argument in a function and then use it to create a new instance. e.g [code]
2. Carrying on from the previous question, if a class can infact be passed, can I specifying a variable type for the argument so that only classes and not instances will be accepted?
3. I have three class files that all inherit some functions and variable from another class called Ship. Is it possible to specifying a variable type so that the variable can only hold instances of classes that are inherited from the Ship class?
View 6 Replies
Mar 26, 2010
I want to be able to call a JavaScript function from a Flex app using ExternalInterface and pass a reference to a different JavaScript function as an argument.
[Code]....
View 1 Replies
Jun 8, 2010
Im trying to create a loop of items like this...
for each (var btn:Object in ViewButtonData)
{
// build element[cocde]..........
I would like to pass in current HBox to the 'HoverTab' function. Is there a way to do that?
View 3 Replies
May 27, 2011
I have a Tree, which has an itemRenderer. On the itemRenderer, driven by the XML conditions, objects are created dynamically and added as a children to nodes. These new objects shall trigger an event handler ( some click events mostly ). How do I pass the event handler to the tree and later to the dynamically created new objects inside itemRendere?
Something like:
<mx:Tree x="534" y="49" newObjectsOnClick="newObjectsOnClickHandler">
View 1 Replies
Jan 10, 2010
I have created different buttons on different movieclip. Then i assigned onPress event on each buttons. But the function of onPress event is not triggered. The arrangement of movieclips is following.
var mainMC:MovieClip = _root.createEmptyMovieClip("mainMC",0);
mainMC._alpha = 0;
var adImgMC:MovieClip = mainMC.createEmptyMovieClip("adImgMC",0);
var offerMC:MovieClip = mainMC.createEmptyMovieClip("offerMC",1);
var offerList:MovieClip = offerMC.createEmptyMovieClip("offerList",0);
[Code] .....
I have created an event as follows:
offerList.onRollOver = function(){
offerList.stopTween();
clearInterval(autoScrlTimer);
} offerList.onRollOut = function(){
duration = 0;
autoScrlTimer = setInterval(automaticScroll,duration);
ovrFlag = true
}
I doubt that the onPress event is not working because of the above piece of code.
View 4 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 13, 2010
I need to return to my original function after capturing an event (downloading something) with another function. The original function needs to return a value, which depends on the downloaded data. So, I'd like to pause original function for the time needed for the download and the eventhandler function to complete it's work, and resume it afterwards.
The obvious way is to set a flag value (both the original function and the eventhandler are within the same class) and make the original function check it until the eventhandler function changes the flag. But that would be wasteful, and my AS is slow enough already:) [other parts of the application utilise some heavy graphics]. Is there another way? Like an event that gets captured "in the middle" of the function? Or some other form of flow control?
View 2 Replies
Dec 29, 2009
So I guess the usual stuff is to have
function listenToEvent(evt: Event){
//stuff
}
[code]......
View 1 Replies
May 28, 2011
I am looking for the function or event, which is called when tree node is expanded/colapsed inside Tree object in Flex 4.5.
View 1 Replies
Jan 10, 2010
Is there a way to get the handler(s) function(s) of an event listener?
I'm trying to find a way to remove them without knowing what they are.
For example:
ActionScript Code:
if (mc.hasEventListener(MouseEvent.CLICK)){
// this object has a MouseEvent.CLICK listener
mc.removeEventListener(MouseEvent.CLICK, null );
}
Instead of null, I was hoping to find some function that retrieves the handler function.
View 7 Replies
Oct 19, 2005
Does anyone know if there is a way to get the name of the function that my code is running inside?
Code:
_btn.onPress = function () {
trace(something);
}
this would then output "onPress" or something like it...
View 2 Replies
Dec 17, 2011
Below is my AS3 code:
[Code]...
If I run add('movie123'). How do I get the string 'movie123' in the enter_frame_handler function? UPDATE This forum post (Click Here) describes the issues I am having but doesn't provide the solution I am looking for. Luckily @kapep provided a simple solution that solved the issue.
View 4 Replies
Aug 14, 2007
i have simple question about how to call a function on a class but i dont know how to do it,I have a class :
Code:
class MyClass{
private var lvSendState:LoadVars;
[code].....
View 3 Replies
May 8, 2011
I want to call the same event handler function with a click and also with a custom event. the problem is the event type that needs to be passed to the function. Is there are generic event type that can be used to call the function from both places?
Code:
menuBtn.addEventListener(MouseEvent.CLICK, menuOpen );
function menuOpen(event:MouseEvent){
[Code].....
View 3 Replies
Oct 19, 2009
I created an array with movie clips now how can i target one movie clip with event handler function . so that when i clicked on one movie clip a message should be displayed
View 4 Replies
Jun 23, 2010
I have an action listener :myText.addEventListener(TextEvent.LINK,linkClickHandler); As according to this, i need to write an event handler function seperate to handle the text link event.Now my requirement is i need to write that function in the same line isntead of giving its name.ie, something like mytext.addEventListenet(TextEvent.LINK, function(event: TextEvent) {....code comes here....});
can i do like this in AS3.What will the syntax for this if possible.Also i want to know, wether i can pass one more extra param to the event handler other than event which is the default parameter.
View 1 Replies
May 12, 2011
I'm making a tile game in flash and I need to pass event.currentTarget (the current tile) into a new function which sends the tile back to it's start position.[code]I need to call this function from other places in my code..I've tried passing the object itself to another function as a variable but it loses it's start position information !
View 2 Replies
Jun 23, 2011
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.
View 2 Replies
Aug 29, 2008
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?
View 1 Replies
Feb 6, 2011
I am running a loop to pull thumbs into a containing movieclip from an xml list. What I want to do is have the thumb's parent movieclip fade in after they are done loading, but I can't figure out how to reference the parent once it's loaded.My code(which currently doesn't work the way I want it):
var vsThumb:articleBox;
var currentarticleX:Number = 0;
var articleLinkURL:String;
[code].....
View 2 Replies
Jun 20, 2011
Since 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 Replies
Aug 19, 2009
I am trying to pass an additional arguments to my listener function, like this[code]...
View 8 Replies
May 12, 2011
I have a class file defined in my package as MyGlobals.as.[code] (I have tried adding/removing "static" and "dynamic" to no effect.)I am trying to call a touch event from the main timeline in this way:myObject.addEventListener(TouchEvent.TOUCH_BEGIN, MyGlobals.myFunctionName);(I have tried removing the class name to no effect.)When I compile I get the error 1046: Type was not found or was not a compile-time constant: TouchEvent. This error occurs on function definitions in the class file.What syntax/concept am I getting wrong? The functions were working fine when I was using constants in the timeline, but I need to be able to reuse these functions over and over again, so I wanted them to be able to take touch event variables so that I didn't have to write a different function for every touch event.I tried googling "error 1046" but I can't find anything useful.
View 3 Replies