Actionscript 3.0 :: Multiple Buttons Referring To The Same Function?

Feb 20, 2009

I'm fairly new to AS3 and CS4, and I'm trying to figure out how to write code that isn't needlessly repetitive. I'm not sure exactly how to streamline it, or if that's possible in my case. My issue in particular is with buttons. I have 40 buttons that perform the same function with a single variable, so I'd like to figure out if I can accomplish that without writing 40 separate functions.This is the current version: http:[url]......Here's the full code, with the relevant part in the last commented section:

Code: Select all// Library button opens library

libraryButton.buttonMode = true;
libraryButton.addEventListener([code].......

It seems that something like that might work, but I don't know how to go about setting my variables up in an array or otherwise putting them in a state where an incremental statement could refer to them.The bigger issue, though, is whether I need to make a separate function for each button.Each button will do the same thing, just with one variable.When the user clicks a button, I want it to perform a function that will update text fields with text pulled from XMLList variables.Each button is given a unique identifier that corresponds to an index in the XMLList.So clicking the button just needs to establish that identifier as a variable n, so that the function can, for example, update the titleText text field with the text contained at titleList[n].

For the purposes of this example, let's just say that I want the mgInteraction function to trace the identifier (name, array index, or whatever) of the clip that's being interacted with (mg0/mg1/mg2/mg3). Is there a way to set this up to work with a single function, or do I need to create 40 unique functions, one for each button?The flash, if need be, is here:
http:[url].......

View 1 Replies


Similar Posts:


IDE :: One Function, Multiple Buttons

Nov 16, 2008

I have three buttons. My goal is that each button will load and play a sound file from the internet. Here is what I have:

function loadPlaySnd(pSpecifier1:String):void {

arguments;

SoundMixer.stopAll();[code]....

Every Button I press goes to the same sound file. The best I can figure, is that the file I loaded the first time I pressed a button has been uploaded, and from there I cannot load another file over that variable when I try another button.

View 2 Replies

ActionScript 2.0 :: Referring To Multiple Movie Clips By Their Instance?

Feb 6, 2009

how would i use the same event for the collision of one thing against multiple objects from the same movie clip without having to name every single one differently, and make an event for every single one? i'm making a game where a box bounces off obstacles.

View 0 Replies

Actionscript 3.0 :: Referring To Variables In Parent MC In Multiple Child MC's?

Nov 7, 2010

I have several .as files. The first that loads is Main.as;

package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{

[code]....

So this MC gives the user the ability to type in their name and store it into the parents playerName variable. With the intention that I can refer to it at any point later in any other MC. It stores it okay, a trace proves that, but a problem comes when this movieclip is replaced by the new one ZoneSelector;

package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;

[code]....

As you can see, there's hardly anything in the this .as file. But everytime the trace(MovieClip(parent).playerName) tries to run I get the following error;

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ZoneSelector()
at Setup/onbeginGameButtonClick()

It's as if the ZoneSelector runs its entire script before the playerName is set..or something like that.

View 7 Replies

ActionScript 3.0 :: Multiple Buttons With Same Function

Jul 24, 2009

I have a group of 50 buttons (named Bottle01 > Bottle50) that I want to have the same code on. The code I want is to, when pressed, put the buttons individual name into a variable and then move to a point later in the timeline. I have just started using as3 as I need this to work through Air and have been googling all afternoo and have cobbled something together, but it doesn't seem to work that well. This is the code I have sofar which is probably very wrong:

[Code]...

View 2 Replies

ActionScript 2.0 :: [FMX] One Function For Multiple Buttons?

Oct 22, 2004

I am building an interactive world map, and for ease of updating am slapping all the functions in a frame on the main timeline.

Say I have a the word "Belgium" with a generic button symbol underneith it (instance name of Belgium of course), and also the maps shape of Belgium, as a button labeled, say Belgium_Map , each requiring several functions for rollovers, movement etc, is it possible to simple write one expresion and apply it to both buttons?

My code looks something like this:

buttons.belgium.onPress = function(){
map:scale_target = "250";
map_target = "-1050";
map:y_target = "-280";

[code]....

So can I apply it to my completly separate button with the path map.europe.belgium as well, without having to write out all that crap again for each, when they execute the same things?

View 2 Replies

ActionScript 2.0 :: {FMX} One Function For Multiple Buttons?

Oct 22, 2004

Say I have a the word "Belgium" with a generic button symbol underneith it (instance name of Belgium of course), and also the maps shape of Belgium, as a button labeled, say Belgium_Map , each requiring several functions for rollovers, movement etc, is it possible to simple write one expresion and apply it to both buttons?Im sure, like most things that one gets stumped on, it is pretty simple, however Im not sure of the syntax..My code looks something like this:

buttons.belgium.onPress = function(){
map:scale_target = "250";
map_target = "-1050";

[code]......

View 2 Replies

ActionScript 3.0 :: MovieClip Buttons Referring To Main Timeline?

Sep 1, 2009

I've got what I think isn't a real tough one however I can't seem to get this working.
 
I have a MovieClip. This movie clip has 21 buttons. These 21 buttons should be forwarding the user to frames 60-81 on the maintime line.
 
The actionscript I've added is not providing any errors however it's working either as these buttons don't do anything unfortuanlty.
 
Below is a sample of the code i've placed within the MovieClip itself, as the buttons and the button names are contained in the movieClip.
 
AS3 Code Being Used

button1_btn.addEventListener(MouseEvent.CLICK, button1Click);function button1Click(e:MouseEvent):void{    gotoAndStop(55)}
 
This code is listed for each button instance and to forward the user to a frame on the main timeline (NOT the timeline in the MovieClip itself).
 
Again, this code is contained in the MovieClip itself and not on the main timeline, as the buttons exist in the movieClip I.E. button1_btn to button21_btn
 
Lastly, to provide a visual idea of what i'm expereincing, please refer to screenshot embeeded in this message or the attachment (same thing).

View 4 Replies

ActionScript 3.0 :: Abstract Multiple Buttons To Use The Same Function?

Jul 16, 2009

I'm building a demo that has a keyboard in it. Obviously, people will type stuff with it and it will go into a dynamic text field. So I have a full keyboard (a movie clip named "keyboardStandard") made up of button symbols. That is placed in the same frame as the text field. Then I wrote this code, using the Q key ("keyQ"):

Code:

keyboardStandard.keyQ.addEventListener(MouseEvent.CLICK, addQ);
function addQ(ev):void {
enterPlayerID_txt.appendText("Q");
}

This works just fine, the Q goes into the text field. However, I sure as heck don't want to write 26 event listeners, then 26 more functions, even if it is copy paste. That's just gnarly. Plus, there are actually 3 keyboards - a numeric and special char one as well I need to handle.I seems passing a parameter from the event listener is not doable?

View 4 Replies

ActionScript 1/2 :: Single Function For Multiple Buttons?

Feb 21, 2012

My problem is that I am trying to use the following functions on 10 different logo movieclips. Each logo movieclip has a popup up box (another mc) within its timeline with a description in. When I hover over the logo movieclip i want it to call the forward frames function and on hover out call the rewindframes function.

function forwardFrames() {
onEnterFrame = function () {
if (_currentframe != 15) {
nextFrame();

[code]....

View 4 Replies

ActionScript 2.0 :: Apply A Function To Multiple Buttons?

Nov 19, 2008

this is a REAL basic one for you: This is my script:

count = 0;
btn_01.onRelease = function() {
if (count<=20 && this._currentframe == 1) {
_root.count += 1;
this.gotoAndStop(2);

[Code]...

Instead of applying it to just one button I want to apply it to many on the stage, how do i add the names of the buttons to the function? I tried separating with commas but no luck

View 2 Replies

ActionScript 3.0 :: Referring To An Object Outside Of The Function In A Listener?

May 31, 2011

I have four buttons named button1, button2, button3 and button4.  I want the code to trace the name of the button when the button is clicked.  This is just an eample of what I'm doing in my project.  The project itself is too convoluted to put up and explain.  My problem that needs to be solved is, how do I refer to the button in the Function?
 
var c:int;
var buttonName:String;
for (c = 1;c < 5;c++) {
buttonNum = "button"+c;

[Code]....
 
When I say "trace(this)", the code doesn't know what "this" is because I've taken this[buttonNum] out of the loop by having to put it in a Function.  How do I call to the object that is in the listener that called the Function?

View 8 Replies

ActionScript 2.0 :: Referring To External Object Within Function?

Jul 9, 2006

I have a class with a method "movePaneTo". I want to create a tween and do multiple things at every step not just change a movieclip property. Tweening a property of the class seems to be working but how do I refer to the class that initiated the tween from the onMotionChanged handler, so that the trace would display the current value?Should I be using a listener for the onMotionChanged?What's this kind of function (the one assigned to "onMotionChanged") callled? [code]

View 4 Replies

ActionScript 3.0 :: Have Multiple Buttons And Edit Them All In A Single Function

Sep 18, 2007

I have a single movieclip named button, and I want to use a "for" to multiply that movieclip, that way I can have multiple buttons and edit them all in a single function.

It would be something like this:

var _button = new button;
for(i=0; i<5;i++){
_button[i]:button = new button;
addChild(button[i]);
}

View 4 Replies

ActionScript 3.0 :: Re-usable Function Triggered By Multiple Buttons?

Mar 25, 2009

I am working on a presentation that has multiple scenes each having say 100 frames. Every 10 frames there is content on the stage, i.e. a 'slide'. There are left and right arrow buttons to take the user of the presentation forward and backward - much like a powerpoint presentation.Many of the 'slides' contain another button (instance name infoBTN) that can be rolled-over, and when this happens an info bubble pops up to display some information in the form of a graphic (instance name infoBubble).This operation works fine for one button, but I don't really want to have to call a new function and variable name and have new instance names on each subsequent frame that features a similar button with an identical operation.

how can I call the function just once and re-use it over and over again? There will only ever be one button of this nature on a given frame,This is the working code I have on the timeline for this particular frame:

Code:
// INFO BUTTON MOUSE EVENT
var fadeIn:Tween = new Tween(infoBubble, 'alpha', Regular.easeOut, 0, 1, 0.75, true);

[code]........

View 9 Replies

ActionScript 3.0 :: Write A Function That Is Used By Multiple Buttons And Accepts A Variable?

Feb 11, 2009

i want to write a function that is used by multiple buttons and accepts a variable when it is called by a given listener..

ActionScript Code: this.fileBTN.addEventListener(MouseEvent.MOUSE_OVER, menuSet("fileMenu"));
function menuSet(what:String){
trace(what);//should trace back "fileMenu"
}

View 7 Replies

ActionScript 3.0 :: Multiple Buttons Call Same Function To Link To Unique URLs??

Feb 11, 2011

So, I have tons o' buttons that each need to link to unique URLs, and I'd like to minimize coding as much as possible. The code below works, but I will have to do this about 50 times.Can I associate the URLs with the instance names of the buttons and then reuse the same function?In the event you didn't already guess, I'm a newbie to AS3

cap_mc.CapTeam_btn.addEventListener(MouseEvent.CLICK, capPage);
function capPage (evtObj:MouseEvent) {  trace("clicked") var url:String = "http://www.mydomain.com";  var request:URLRequest = new URLRequest(url); 

[code].....

View 8 Replies

ActionScript 2.0 :: Multiple Targets - Make A Function That Runs On Mouse Click On Either Of The Buttons

Apr 24, 2006

I have 4 buttons with instance names: 'alfa', 'bravo', 'charlie' and 'delta'. I want to make a function that runs on mouse click on either of the buttons. I tried this, but could remember exactly how it should look:

[Code]...

View 12 Replies

Flash :: Using An External Class With Multiple Frames On The Timeline And Multiple Stage Placed Buttons

Sep 21, 2010

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.

View 2 Replies

ActionScript 2.0 :: Multiple Conditions - An Object Will Go To A New Frame If Multiple Buttons Are Pressed?

Aug 12, 2009

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?

View 4 Replies

Professional :: Multiple Buttons Linking To Multiple Pages From One Movie?

Aug 28, 2011

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---\

[Code]....

View 5 Replies

Using Multiple Movie Clips For Separate Buttons And Mouse Over Buttons?

Nov 24, 2009

I am using Flash CS4 with ActionScript 3 and I am fairly new at it. I am struggling with two things.
 
1. How can I start a movie clip while scrolling over a button? I know how to start a movie clip when a button is clicked.
 
2. How can I use multiple movie clips for seperate buttons?

[URL]

View 3 Replies

ActionScript 2.0 :: Multiple Buttons Activating Multiple Items?

Jan 5, 2010

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].......

View 1 Replies

ActionScript 3.0 :: Multiple Videos To Play With Multiple Buttons?

Feb 4, 2010

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")

[code]....

View 2 Replies

AS3 :: Multiple URL Request Buttons?

Jun 12, 2008

Found this code on the site from nunomira regarding URL request...code works, but when I try to duplicate it for 3 buttons hey go fritzy!Do I need something in between?

Home_btn.addEventListener(MouseEvent.CLICK,clickHa ndler1);
function clickHandler1(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.ebay.co.uk"));

[code]....

View 8 Replies

ActionScript 2.0 :: Multiple Xml From Buttons?

Aug 16, 2007

Using Flash 8 and as2.0 I am trying to create a simple (!) app. that lets a user click one of ten buttons to go to a gallery.

On frame 1 of the .fla I have ten buttons, and on frame 2 a target mc. Frame 2 also has the script to create an xml 'object'. In the same folder as the .swf, I have ten xml files.

How can I get each button when clicked to 'pass' the url for the specific xml file to the xml script in frame 2? My xml script works pertectly if I key in the url, ie

View 4 Replies

IDE :: Multiple Buttons Don't Work

Feb 19, 2010

I'm designing a website for a Reiki/Spiritual advisor thingymebob and I have a menu on the left of my page of buttons and when I click a button it displays the contents of the button on the stage. Easy enough, so to speak, but the code I have written should send the viewer to a certain frame in the timeline where the tween begins.

When I play the swf and click the home button it works perfectly on the first page and if I go down the menu and click every other button in order they too all work fine, but as soon as I start clicking any other button randomly there is no tween effect and it seems to send me to the wrong page(!) plus straight to the clear text on the stage without any fading in tween. As though it has just gone to the last frame of the tween.

Here's the code below. I've asked the spiritual advisor for guidance and he sent me here, so please prove him right - ha ha!

stop();
myHome.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndPlay(281);

[code]....

View 1 Replies

ActionScript 2.0 :: Referring To URL In XML?

Dec 21, 2006

This is my problem: I've got a couple of movieclips, when I click on them I want them to open the URL that I've typed in my XML-file.(The photos are thumbnails stored inside of the movieclips)Here's my XML:

Code:
<?xml version="1.0"?>
<select name="photos">
<option photo="film14" url =">[code]....

How do I refer to the url-code in the actionsscript?

View 4 Replies

ActionScript 3.0 :: Tween For Multiple Buttons?

Feb 9, 2009

I am using tweenLite in my Fla and I have set up this code sofar which is working fine:

Code:
function tweenTopicUp(topic):void {
var myTween:TweenLite = new TweenLite(topic, 0.6, {alpha:0.5, ease:Expo.easeOut});[code].........

The problem is that i have about 10 buttons (topic1, topic2, etc.) to go. I know I need to do something with Array but I can't seem to get it working .

View 2 Replies

CS3 :: Multiple Buttons Run Single Clip?

May 16, 2009

What I have done:

1/ A very simple Flash movie

2/ 5 very basic rollover buttons

What I want to happen:Everytime I'd hover the mouse on each button, I would like the background animation to run. And have the animation stop on mouseout for each button.I was able to make it on one button via this tutorial: [URL]But this doesn't seem to work with multiple buttons involved.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved