ActionScript 3.0 :: Multiple Buttons With Very Similar Functions
Feb 5, 2011
I'm using the below code to have a button that adds a MC to the stage. The problem is that I have over a dozen of these buttons and I'd rather not have to write out the event listener and function for every single button. Is there a way to use a single function for all the buttons and just change what MC is added based on which button is clicked? So if the user clicks on the draw5 button the function adds the deck5 MC to the stage?[code]
I am adding a different listener to each button in the menu and there are several menus as well, then each one of those functions adds a different child depending on the button and also pushes several values to the Array list, in this example called objectsOnStage. I will be running this structure function 40 times with each of the highlighted elements changing accordingly.
//Listener and function for Button01 menu01.button01( MouseEvent.MOUSE_DOWN, button01Function); function button01Function(event:MouseEvent):void {
[code]....
My original thought was to keep all those changing values in an Array list and run a loop for the function/listener, but I just cant make it go.
I am creating a map of the US. I've created a button for each state and named each button with it's 2 letter state code (AL, AK, AR, etc) in the library. I would like for each button to link to a directory on the site with a similar name, /site/map/AL, for example.
Rather than set up each button individually with script like: on (release) { getURL("/site/map/AL", "_parent"); }
Is there a way to consolidate the 50 buttons in to a few lines of code? If the destination directory were to change in the future I would then only have to change a couple of lines of code instead of 50 instances. I'm thinking the name of the button could be read and passed in to the button function, but I'm no programmer and not familiar enough with Actionscript to know where to start.
I am building a Flash site with a boombox animation. I have the below code I am using. I am using just two frames. First frame, is where I put the code in the actions layer, boombox is still. In the second frame, I placed my movie clips on layers (woofers vibrating & tape deck spins). No code in second frame. So, if you hit the play, previous or forward button a song goes on and the animation start. If you press the pause button, animations stop with music. I have created 2 functions per button.
2 questions: 1 - Is this the best way to do it? If I press the buttons quickly, sometimes a song gets stuck and I can't stop, forward, etc. I was wondering if this was the code?
2 - I am tweening in my pages using AS3 - not timeline. I have a music and video page (each a movieclip). Is there a way that once I tween in the new movie clip (non-music of vid page) that the music or video can shut off?
I have been trying to figure out this by myself for a while and needless to say, I have been completely unsuccessful. I have various a loop that creates multiple movie clips called: movie1, movie2, movie3, movie4... (you get the idea...) i want to assign roll over,roll out, press functions to all of theme.g. when you press on one movie, it highlights it.but I am trying to find a summarized way over writing each one out:
movie1.onRollOver=function(){ something happens }
someonne once told me to use chartAt to do this, to reference different mcs, but I cant figure out how to do it.
I've been trolling the web all day looking for button FX sounds similar to 2 advanced. Can't find any and my deadline is running out. Nothing I have on hand is right for this job.
If u have these or similar FX for buttons etc can u send a wav or aiff???
Iam having 3 buttons in stage and three corresponding movieclips. When I clicked on one button, it should play its corresponding movieclip from the second frame. (Same case for the rest of the buttons).Here the action for the three buttons are almost same, only the movieclip differs. In AS2, I can optimize the script for the above activity as below
for (var i = 1; i<=3; i++) { _root["btn_"+i].onRelease = function() { myname = this._name.split("_")[1];[code]..........
My Question is ===>is there any way to add the Event listeners for all the 3 buttons using "for loop" instead of initializing it for each buttons seperately ? [Imagine if we have more than 10 buttons and it will be very boring to add the listener for each button in a seperate line ].
I have a site that has multiple pages of similarly sized buttons. These are magazine covers. I'd like for the mag covers and links they point to (loaded swfs) to be dynamically loaded via a text file, if possible. The client always has new magazines she's been in and to manually load the newest buttons first is time consuming.
I have a problem when making flash applications with more than one frame that has symbols placed on it in that I can't declare all of the event listeners for the objects at the same time and I have found that even if I put them all on the first frame, add the event listeners, then click through to the next frame then the buttons won't work on that frame.
Does anyone have any idea how I could solve this? I did consider myself a fairly competent AS3 programmer until I realised I had no idea how to handle this sort of thing. Solved: I initialised the clips from my external class and then addChild'd and removeChild'd them as I needed to and placed their x and y on addChilding.
i have an if statement, an object will go to a new frame if multiple buttons are pressed
PHP Code:[code].....
now i want it so that if one condition is met the mc will goto frame 2, if 2 conditions are met, frame 3 and if 3 conditions are met, frame 4.i know i could do this with a lot of if statements but i have a lot of movie clips to use this code on, so is there any way to write an if statement that will trigger different options if multiple conditions are met?
I have a flash movie with 3 buttons I am trying to link relativley to pages within my site, I have one working fine but can't get the others to link and when I try it makes the one that is working, work no more..
Below's the code I am using for the one that is working;
import flash.events.MouseEvent;var getIndex:URLRequest = new URLRequest("../index.html"); //---Enter Button---\
I have a map with a list of items to the side. I want the list to work as buttons and highlight both the button and the particular image on the map... and when you click you link to a certain location.I also want to be able to MouseOver the map, have both the image on the map and the corresponding 'button' from the list highlight - but when you click, you go to a different location than if you would have clicked from the list.I have it set up - but something is conflicting. Here is how I have my code set:
Code: BUTTON_ONE.onEnterFrame = function(){ if (this.hitTest(_root._xmouse, _root._ymouse, true)) { this.nextFrame();[code].......
I am creating a stand alone DVD to be used with Flash player. I am wanting to add different videos that play with different buttons. The following is the code I have for the video to play when the corresponding button is clicked..... My problem is how do I get that video to "leave" and stop playing when another button is pushed to play a different video.
Educators_btn.addEventListener(MouseEvent.CLICK,clickEducators); function clickEducators(evtObj:MouseEvent) { gotoAndStop("OE")
I have multiple buttons with the following script applied which waits a second while a transition animation plays then loads a new image into the container... There seems to be a problem with having this code applied to multiple buttons unless I make the function and interval identifiers unique (i.e. transitiondelay1/waitFunction1,transitiondelay2/waitFunction2, etc.). I don't really want to have to do this to each button.[code]
I have used the loader script to load an external swf into current project. I have added a button to unload the external file when wanted, and was wondering if you could have multiple functions for that button, so that when you click it to unload it works as a 'home' button as well, and takes the user back to the mainpage again?Might be wise to mention that im kinda new to adobe flash and as3, and not sure if the way i have used to load the external swf was the easiest. Seems like a few have had some issues with this subject before me as well.
How would I manage to enable a button to perform several operations? I want a button to do the following.
I want it to change colour etc, when it is hovered over, I also want it to activate anther flash file on the page via local connection on release. How do I allow the button to set up different actions? Do I need to make 2 separate invisible buttons? And have action script applied to both of them for the 2 commands? How for example would I be able to extend this so that I can have the button doing several things? Say:
1) On rollover it changes colour 2) On rollover it activates a flash mc on the page 3) On Click it changes colour 4) On release it takes the user to another page
how to make button do multiple things at the same time. i.e when button is pressed it animates object1 and object2 i have a buttons that opens a sliding door (code is:
on (release) { control.gotoAndStop(2); }
so it opens a door where sound control is and i want for the same button at the same time to open lets say another door somewhere in the same stage with a music tracks in ther
I'm trying to fiqure out a way to have multiple SetInterval functions. what I'm trying to do is have text highlight a sentence using the setinterval function than after the number of chars needed are highlighted I want to be able to clear the interval and then start with the next sentence through another setInterval.
The program I'm trying to write is somewhat of a text to speech. I have a audio clip and a static text box. the audio is supposed to sync with the highlight of the text. the only way i could fiqure to generate the sync with a highlight was through setSelection as a loop.
Code: var i:Number = 0; var my_snap:TextSnapshot = test.getTextSnapshot(); var count:Number = my_snap.getCount() my_snap.setSelectColor(0xffff00);
I have lots of buttons on the stage but they all do the same thing, ie. CLICK & DOUBLE_CLICK.How can I group these functions so that if a button in a certain group is clicked then the functions of buttons in all other groups are disabled?
Most flash games and interactive animations that use keyboard events are made to respond in different ways to different keys.I am working on games for toddlers, who basically just bang on the keyboard indiscriminately. The trouble I'm having is setting up keyboard eventlisteners (key_up) that each perform different function.We're talking games like: when key pressed, ducky dances; when key pressed, doggy dances; when key is pressed, ducky and doggy go to sleep. I've attempted removing the listener before adding the next one:
stage.addEventListener(KeyboardEvent.KEY_UP, doSomething); function doSomething(evt:KeyboardEvent):void {make it do something;
I really need a Timer that shoots multiple functions. The Timer Class just handles one function and therefore is not good enough for my project. The Timer should work something like this:
After 1 seconds fire functionOne After 4 seconds fire functionTwo ...and so on...
Time is really crucial in my project (down to milliseconds) so I really can't use the Timer Class and fire "new" Timers all the time because Flash needs some milliseconds to process all the code and in the end it sums up to kind of a lot of time.
can you make a button have multiple functions? as in if i click a button one and imahe will pop up and then click that same button and another different image will pop up??
As I've been working with AS I've developed a collection of utility functions. For example:
$ cat utils/curried.as package utils { public function curried(f:Function, ...boundArgs):Function {
[Code]....
And I've found that, some times, I want to keep more than one public function in each file... But ActionScript restricts me to one public definition per file, if that file defines its self as being part of a package.
So, without creating a class with static methods, how could I get more than one public function in a single .as file?
Sorry if the subject doesn't make much sense but I basically want to perform several if the statement when on movie clip is clicked. an example of an onRelease trigger that activates two if then statement that change the frames of 2 movie clips.
I�m trying to use Listeners to capture the MouseUp event based on Helen Triolo�s sample at [URL]I reused her code and loaded the listener�s array (with MC names that will listen to the MU event) from a textfile.My problem is that I don�t have these MCs on the _root. They�re located deep in the MC hierarchy, this way: MCComponent-->MC1-->MC2-->MCs I want to address for listening (I have about 250 MCs in this level of depth which I want to to address for listening)So, when defining the MouseUp function for each MC to respond to, I couldn�t address the MCs. I tried in different ways without any result.
This is the code:
// set up responders for each listener // listeners is the Array with MC names which I loaded from // the textfile for (var i in listeners) {
[code].....
Is there any way of making this work? Is there something missing in this code ? Note: I cannot put these MCs on the root because of other functionalities that they need to accomplish...By the way..., what about RollOver and RollOut ? Can they be captured too ? I�ve read about capturing MouseUp, Move and Down but not Rollovers...