ActionScript 3.0 :: Event Listener Passing Variables - Give Access To EventType?
May 12, 2009
I'm using the following addlistener to listen for a custom event the event works if i put e.Event in the functions parameter but i don't get the passed variables however if i go into the .as folder where the dispatch originates and put EventType in the parmeters field of the function then i get all the variables.........but if i put EventType instead of e.Event in the first example then I get undefined for EventType.....how do give access to EventType?
how can i access event.target outside event listener method.say for example
my_mc.addEventListener(MouseEvent.CLICK, onC); function onC(e:MouseEvent):void { var m:MovieClip = e.target as MovieClip; } trace(m.totalframes);/// not working
now what if i want to get totalframe property of m instance, in short for every movieClip clicked.
Let's say I have 10 different buttons, a click on each button will open a different website. Currently, I have 10 different functions for 10 buttons. Is there a way to simplify the code and only have one function for all the buttons and only pass the URL to the onclick function?
button121.addEventListener(MouseEvent.CLICK, clickButton121("http://www.myurl.com")); function clickButton121(event:MouseEvent, urlString:String):void{ myURL = new URLRequest(urlString); navigateToURL(myURL); }
I can say it will be very inefficient if i have 100 buttons and having to write 100 functions.
I'm new to ActionScript and have a fairly basic question. I want an eventlistener to call a function and pass it a parameter that will send the movie to a specific frame. My code generates and invalid parameter type error. It's as follows:
TL_AboutUs_btn.addEventListener(MouseEvent.MOUSE_OVER, DropSubMenu(10)); // calls a function to drop a sub menu function DropSubMenu(sm:number) { gotoAndPlay(sm);}
Error is "1046: Type was not found or was not a compile-time constant: number."
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:
function chkEmpty(event:Event){ if(event.currentTarget.text==){ thisIsBitIWantToBeAbleChange.text = You haven't entered anything in the box, please try again hisIsBitIWantToBeAbleChange.setTextFormat(validate_frmt); } }
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,?
I would like to know if it is possible to pass a clip event on to both the function that has a listener, and to the button that is being pressed. I am finding the listener takes it and thus the button doesn't see it.I found a walk around, however, I'd like to know if it is possible say for one clip event to be seen by both objects?For example, with the mouse over a button the listener function detects the event and carries itself out, however, the button misses the event now.
I am trying to essentially pass a string as a function name into an event listener, but I am not sure how to approach this. Is there a way to convert a string into a function?
Here is some code I have for me to show you what I am doing.
package{ //some import statements public class changes extends MovieClip{
I have been focusing on PHP a lot lately and just had a client that requires an MP3 player playing multiple songs so I had to whip out my rusty actionscript skills. I have the player completed and it is working as desired. The down side is it has multiple songs. I am using separate functions for each song and separate event listeners. My main question is there a way to combine these funtions into one and just use the event listener to pass another variable to the functions? Below is a sample of one of the code for Song1. I would like to make it so anywhere there is Song1 in the code, I can make it a variable so I can put in for example (Song2, Song3, Song4, etc.) This way, I can have one or two functions handle all the songs instead of having to copy, paste and then find and replace.
// Song 1 var Song1:Sound = new Sound(); pbSong1.source = Song1; //pbSong1.visible = false; var Song1Loaded:Boolean = false;
I'm having a real difficulty in action script 3 using my xml data from an external source. I have no difficulties importing or manipulating the xml data, the difficulty lies in accessing the information in a different function.
I want to pass a variable to TriggerThis though and I know that I need to use a Custom Event to do this. I tried creating a .as file containing the following:
I've spent most of this afternoon trying to learn Custom Events so that I can pass a variable through to a function that's fired when a Fade Out has been completed.
i.e.
[Code]....
So I'm not sure that I'm even close to getting this right.
how I can pass variables to a function called when a Transition has completed?
I'm having trouble with buttons. I've tried two sets of code and get the same result: an "1120: Access of undefined property enter_btn" error. Here are the two sets of code I am using:
Code: function onEnterClick(evt:MouseEvent):void { gotoAndPlay(71); }
[code]....
I've set the instance name for the button but keep getting the error. Do I need to set up a variable first?
TypeError: Error #2007: Parameter listener must be non-null.at flash.events::EventDispatcher/removeEventListener() at project1_fla::MainTimeline/btnName()
I am having a weird problem with scope/reference. I am using a loop to preload a number of thumbs in one go, I am creating a different listener for each one on the fly and then passing event handlers for each one of them. This should not be difficult using a loop, but somehow I cannot access the the parent object on my listener and therefore I can't do much with my thumbs after they are loaded.Here is the relevant segment of my code. myThumb_mc is a temporary variable that does not exist when the loop finishes, you can copy and paste this code to test it though. It should work to that extent. (you'll need an image1.jpg to be in the same directory)
Code: var myThumb_mc = _root.createEmptyMovieClip("myThumb_mc", _root.getNextHighestDepth()); myThumb_mc.clipLoader = new MovieClipLoader(); myThumb_mc.clipLoader.loadClip("image1.jpg",myThumb_mc);[code].....
The code above works, but it does not look nice and it cannot be the right way of doing this. Long question short, how can I access the parent of a listener from a listener object? ._parent does not work.
I am trying to learn JavaScript and I am wondering whether JavaScript has a event listener just like ActionScript's ENTER_FRAME. Basically, I want this event listener to listen "all the time" not just wait for any particular instance (mouse click, keyboard event) of event.
if I have an event listerner (mouse, keyboard, enterframe,....event) that is being triggered, and when it finishes its event, something that is able to detect the finished event listener and fire out another sets of event.
It works more like MOTION_FINISH in TweenEvent, but it is only available for TweenEvent only, what if I want to detect a mousclick, keyboard, enterframe or even touch event?
My stage has about 25 buttons on it. Each button when pressed to tweens the background to some random x/y coordinates and then loads an external swf file.This is all working, but the timing is off. How can I wait for the initial background tween to end before I make the loader call to the .swf file.Currently each button's behavior is called on the MouseEvent.CLICK event which calls a function that knows its unique filename.swf. I know you can add the MOTION_FINISH even to the tween event but then I would have to call a new function and lose track of the button that initially called it.
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.
This is a very basic question but I can't seem to find an answer. I have a mouse over event and have created the buttons with the mouse overs which is working great. I created the actionscript to go to a specific web page when a user clicks the button. Now, I need to add a label to the mouse over so when someone mouse's over any area of the button, it will show them a particular name for the button.
I am sure that this can be done using actionscript in a mouse event roll over command but I can't figure out what I need to show the text. Here is where I am:
I am doing this inside a module containing viewstacks and their childs.Calling onInit() on creationComplete of module.When I am inside one of the childs of a viewstack of this module and press Enter, it doesnt not invoke the listener function at all (bp inside this does not get hit).
private function onInit():void{ this.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed); }[code]..........
This might be more of a subjective question, but is it generally best practice to have one dedicated method per event-types that you add an event-listener?
Such as:
myButton.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); myButton.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); //Somewhere else in the code...
[Code].....
And if you had a MouseEvent.MOUSE_UP, MouseEvent.MOUSE_DOWN and other relevant MouseEvents event-listeners to watch for, you could even set a switch statement to handle all the various MouseEvent types.
I have these buttons in a movie clip and I would like to have only one event listener for the parent, using event.target to point to the children. I have also tried event.currentTarget, and it didn't work.here is the code that works:
i finished air application and it is need a local permission for the installed folder ( C:Program FilesAppName ) as i am generate xml ( desktopFileStream.writeUTFBytes(newXMLStr); ) from the application and its need local permission.first time i run the application i got ( error 3001 indicates a file or directory permissions issue ); when adjusted the permission for the current user ( manually ) to fullcontrol, its work great and perfect. how to give my application folder FullControl access by code ( AS3Flash )? as i can't ask each user to give my app folder manual permission.
I have a code in AS3 that works when you rollover it. I need to use the same code but not with an eventlistener for a mouse event but a frame event when the timeline plays the clip
var coordX:Number = shaker_mc.x;var coordY:Number = shaker_mc.y;var timer:Timer = new Timer(10); shaker_mc.buttonMode = false; shaker_mc.addEventListener(MouseEvent.MOUSE_OVER,startShake);shaker_mc.addEventListener(Mous
printableInvoice.addEventListener(batchGenerated, printableInvoice_batchGeneratedHandler);Results in this error: 1120: Access of undefined property batchGenerated. I have tried it as FlexEvent.batchGenerated and FlashEvent.batchGenerated.
The MetaData and function that dispatches the even in the component printableInvoice is all right. It I instantiate printableInvoice as an mxml component instead of via action-script it well let put a tag into the mxml line: batchGenerated="someFunction()