Make the button generate code work in a loop

I am trying to generate instances of a movieclip in my library on the stage and give them all the single variable and instance names in order to control later and perform certain actions based on the name of the clicked button. I can do it with the following code, but I wanted to use a loop instead to be more effective. Can someone help me to make this code work in a loop? Thank you!

(labor code)

var image1_mc:testButton;
var image2_mc:testButton;
var image3_mc:testButton;
var image4_mc:testButton;

image1_mc = new testButton ();
image1_mc. Name = "image1_mc"; the name of the instance
image2_mc = new testButton ();
image2_mc. Name = "image2_mc";
image3_mc = new testButton ();
image3_mc. Name = "image3_mc";
image4_mc = new testButton ();
image4_mc. Name = "image4_mc";

addChild (image1_mc);
addChild (image2_mc);
addChild (image3_mc);
addChild (image4_mc);

image2_mc.x = 50;
image3_mc.x = 100;
image4_mc.x = 150;
image1_mc.y = 500;
image2_mc.y = 500;
image3_mc.y = 500;
image4_mc.y = 500;


(Here is my attempt of a loop, but it does not of course because I'm not sure that it is even possible to use a variable to name a variable: D)

for (var i: Number = 0; i < 4; i ++)
{
var (' _mc image "+ (i + 1) +" "): testButton = new testButton();
addChild ("image"+(i+1) +"_mc");
'image' +(i+1) + "_mc".name = "image" + (i + 1) + "_mc";
'image' +(i+1) "_mc".x plus i * 75;
}

Hey thanks that pointed me in the right direction. I had not yet used the tables. I managed to do the work. It generates now 4 buttons which return unique names when you press. I also added within the table event listeners. Yet more concise! Here's the code: (interesting bands forum [of the] media if you do not attach code: D)

Tags: Adobe Animate

Similar Questions

  • How to make the buttons doesn't work in every scene?

    Hello

    I created four separate buttons (actionscript3) and I coded each button so when one is active, it climbs to a different scene. The four buttons are present on all the stages (I copy - paste all the buttons of the original scene at each additional stage) so I was hoping that, whatever the stage, the user can click on each button to operate. Each button works on the first click (the first stage), but the question is when that one is turned on and the buttons, it climbs to a new scene is no longer are clickable (roll over the State remains functional, but none of them work to be clickable to access another scene). I copy / paste my code used below, I hope this question makes sense, I want to just that my buttons to work independently of the scene. Thank you!

    Here are the codes that I used, I placed it on the first frame of the first scene:

    tulip_btn.addEventListener (MouseEvent.CLICK, onClick);

    function onClick(e:MouseEvent) {}

    gotoAndPlay (1, "scene 2");

    }

    rose_btn.addEventListener (MouseEvent.CLICK, onCami);

    function onCami(e:MouseEvent) {}

    gotoAndPlay (1, "scene 4");

    }

    lily_btn.addEventListener (MouseEvent.Click, onLily);

    function onLily(e:MouseEvent) {}

    gotoAndPlay (1, "scene 5");

    }

    poppy_btn.addEventListener (MouseEvent.CLICK, onPoppy);

    function onPoppy(e:MouseEvent) {}

    gotoAndPlay (1, "scene 6");

    }

    When you go to another scene, it's as if it's a new button, which does not have the mouse listener. If you were using a movieclip instead of a button, you can place the script inside the movieclip. It would be wise add the listener when the movieclip is added to the scene and remove the listener when it is removed.

    There is a different way, you may work well. You can name your buttons and the same scenes. Then, in the intro scene, you could have a script like this:

    import flash.events.MouseEvent;

    Stop();

    stage.addEventListener (MouseEvent.CLICK, clicked);

    function clicked (e:MouseEvent) {}

    gotoAndPlay(1,e.target.name);

    }

    Now you can copy the four buttons, which might be called rose, Lily, Tulip, poppy, and clicking on any one of them would you bring to the scene with the same name.

  • How to make the button to set the properties of auto-scale one of the Axes on the graphical indicator so I can turn on or off when I press on it. In the Labview web UI designer

    How to make the button to set the properties of auto-scale one of the Axes on the graphical indicator so I can turn on or off when I press on it.

    I need to change the adjustment vaguely Autoscale property for my graphic indicator. Can someone help me please.

    Thank you!

    Hello

    I have confirmed that there is currently no way programmatically enable/disable autoscaling for axes on the LabVIEW graphical indicator generator of the user Web interface. We noted this to possibly be implemented in the future; Sorry for the inconvenience.

  • Make the button invisible when flv starts again

    Hello

    Please, is - can anyone help me and tell me how do to have a button instance become invisible when you click the play button on the skin.swf file? Maybe there is another way to do what I'm doing.

    I have a Flash 8 file with a pointing to an FLV file FLVPlayback component. I use an outer skin for controls. When the video ended I displaying a button, but if the person wants to play the video again the button must again become invisible. I guess I need to create an actionscript that says: If the video is in progress (at all) the button is invisible. But how?... is the big question for me.

    Any help would be great.

    Thank you
    thepopguy

    This is possible. You need actionscript to check the status of the video, if it plays then the button is invisible. This is what we call an event listener. You must give the component an instance name - like vid. Then, use this code on the frame:

    Wait reading sequence
    var vidList:Object = new Object();
    vidList.playing = function() {}
    Button1._visible = false;
    other actions go here
    }
    vid.addEventListener ("play", vidList);
    stop;

    Listen to movie stop
    var vidList2:Object = new Object();
    vidList2.stopped = function() {}
    Button1._visible = true;
    other actions go here
    }
    vid.addEventListener ("order", vidList2);
    stop;

    ============
    This code will actually listen to the playback of the sequence, and then it will make the button invisible. He listens for the film to stop, and it makes them visible again.

    Sample:
    http://www.johnkalnin.com/FlashHelp/vid-isPlaying-Inv.html

    Flash 8 source:
    http://www.johnkalnin.com/FlashHelp/vid-isPlaying-Inv.fla

  • My pc is slow and it makes the noise when it works

    Hello

    My pc is slow, when I'm typing and all open programs. It takes time for any program to open and it makes the noise when it works.

    My pc is a Windows Starter 7 mini laptop.

    Hello

    Problems of material software medium noise is not physical and makes no noise.

    Check with support from the manufacturer of your system, their online documentation and drivers, diagnostics,
    and ask questions in the forums (if any) on known problems.

    There may be some performance issues that could be helped with the software however the material
    problems need to be addressed first.

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">

  • When I go to my creative cloud application, it said that I have no internet? try it again the button does not work

    When I go to my creative cloud application, it said that I have no internet? try it again the button does not work

    Log, activation, or connection errors. CS5.5 and later, Acrobat DC

    https://helpx.Adobe.com/x-productkb/policy-pricing/activation-network-issues.html

  • Make the button load words from the list

    Hey guys!


    Just a note, I don't know about programming and I am new to Flash so please tell you the possible answers in the most simple way, thanks!

    So I do an application that when you click a button, it will be to randomly select a who, what, when, where and why from a list that I do.

    So say there's a button that says new idea.

    When I click the button it is:

    Who:

    Who:

    When:

    Where:

    Why:

    Say a small list of who's 1, 2 and 3

    A small list of what is 4, 5 and 6

    A small list of when is 7, 8 and 9

    A small list hence is 10, 11, 12

    And a small list of og is why the 13, 14 and 15

    How can I do so when I click on the new button idea it (by chance), will select one who, what, when, where and why of their list?

    Please help tell me what to do to make the button do place a word in a list, to what I'm asking!

    Please, I beg you!

    Thank you!!!

    To make a random selection from a list, you must first have the list.  A table is a good list, so for each category, create a table and fill each with any choice you intend.

    For the an elements to choose randomly from the list, you can use mathematical methods taken Actionscript supported by.

    var whoList: Array = [1,2,3];

    var randomWho = whoList [Math.floor (Math.random () * whoList.length)];

    Please do not start new assignments for the same topic

  • Is it possible to make the buttons work in Acrobat Reader for iPhone and iPad?

    Hello

    I shopped in the forums, and although several threads are on the same question, I can't find a conclusive answer. I try to open an interactive pdf with buttons (show/hide actions) on my iphone in Acrobat Reader. However, the functions do not work, then they work fine on my Mac. Am I right in thinking that it is impossible to have buttons in interactive PDF work on my iOS devices? All applications are up to date. The buttons were created in inDesign.

    Thanks in advance for your support.

    Hi jom13880393

    I apologize for the issue.

    However, the navigation buttons options you speak is not available in the app and there is no solution for it right now.

    Kind regards

    Supriya

  • So I try to import a button into a document in Dreamweaver, HTML in fireworks, but the button does not work.

    The button itself works perfectly in two Fireworks preview mode, and if I open the button by double clicking on it in the menu of sites in Dreamweaver. There was therefore nothing wrong with the button it loads if I load up by itself in dreamweaver. But, when I use Insert > image > fireworks html and select it, it just doesn't work. I tried to make new buttons, remove everything on the site and have just the button and the Web page with a folder for images, but nothing seems to work and I can't find an answer online.

    I use a Mac and using Dreamweaver CC

    Fireworks generated code is blind.  And these scripts MM working capital have been an unfortunate error of judgment.  The programmer should have taken this code on the back, and he's driving a tank.

    You're better off using Fireworks for images only.

    DW to generate your HTML, CSS and JavaScript code.

    Nancy O.

  • What system use Muse to make the contact form widget work?

    Hello

    I'm a graphic designer working with a coder to create a new website using Muse. My coder was asked what Muse system uses to make the widget of the contact form.  Looking at the code of the page looks like ASP dot net and when the user clicks the button the form data is sent to a script called "FormProcessv2.aspx". If so what version?  (for example, ASP 1.0 or 2.0 or 3.0) Muse use "dot net" or ".NET" or similar in the documentation? If so then would you say what version (1.0 or 2.0)?

    Can someone help me with these questions?

    Thank you very much

    Emma

    It is unclear what the URL/code page you look at? Muse does not ASP. Muse uses PHP for form processing and relies on PHP sendMail to send the form as an e-mail information.

  • Make the button not read back symbol

    I'm sorry for everything that you Pro Edge there.

    I had a Flash designer for many years, but never a great coder, but is now trying to get on board.

    IM start with something very simple.

    4 buttons that play releated symbols with my ways caveman able to make it work.

    * Except that after the symbol shows. I can click on the new button and the symbol goes to 0, clicking again and she plays again. Is there a simple way that after I clicked the button to read the symbol that I can not click on the button again after the symbol is done playing.

    I hope that one of you will not want to help out me.

    Thank you!

    Eggert

    Here are my files

    https://DL.dropbox.com/u/2093612/button_troubles.zip

    You can use unbind().

    See your publication with unbind() - look in the window code to see composition ready, then at the beginning of each symbol.

    https://www.dropbox.com/s/xq6q6txnbdza0je/button_troubles.zip

  • Script to make the button stay on State hit until the other is clicked!

    Hello

    Got a little problem that I can't solve.

    I have a line of 5 buttons including each links to a different page. These buttons are currently in a clip.

    However, I would like to create an effect where when a user clicks on it remains highlighted. that is still on the State of success, until the user clicks one of the buttons.

    I would have thought it would be somethink that I could find online, but carnt seem to find anywhere.

    I found the code to make a point to stay on when you click on it, but it works on its own in the entire movie clip, so it has no effect when you click on other buttons on!

    Have tried the script below, but I'm sure that this will not work because it is not a link to the other buttons at all.

    on {(press)

    if (this ._currentframe == 1) {}
    this.gotoAndStop (2);
    { } else {}
    this.gotoAndStop (1);
    }
    }
    Thanks for any help!

    You are welcome.  Here is a slightly condensed version of the same thing...

    var lastBtnUsed;

    Btn1.onRelease = btn2.onRelease = btn3.onRelease = btn4.onRelease = function() {}
    processBtns (this);
    }

    function processBtns (newBtn) {}
    If (lastBtnUsed! = null & lastBtnUsed! = newBtn) {}
    lastBtnUsed.gotoAndStop (1);
    }
    lastBtnUsed = newBtn;
    newBtn.gotoAndStop (2);
    }

  • Button/UiLoader Code works not as I want it.

    Can someone tell me why my forward (next_btn3) button does not work?  I have a uiLoader (printLoader) that loads three images.  Everything works fine, I can see the button but can not use it.  Thanks in advance.

    next_btn3.addEventListener (MouseEvent.CLICK, nextImage3);

    var imageNumber3:Number = 1;

    function checkNumber3 (): void {}
    next_btn3. Visible = true;
    back_btn3. Visible = true;
    {if(imageNumber3==3)}
    trace (imageNumber3);
    next_btn3. Visible = false;
    }
    {if(imageNumber3==1)}
    trace (imageNumber3);
    back_btn3. Visible = false;
    }
    }
    checkNumber3();
    function nextImage3(evtObj:MouseEvent):void {}
    imageNumber3 ++;
    printLoader.source = "images/print_images/image"+imageNumber3+".jpg";
    checkNumber3();
    }

    back_btn3.addEventListener (MouseEvent.CLICK, backImage3);

    function backImage3(evtObj:MouseEvent):void
    {
    -imageNumber3;
    printLoader.source = "images/print_images/image"+imageNumber3+".jpg";
    checkNumber3();
    }

    I have no idea why you're rename and reposition buttons, or what could be the first over the current state of the design, so I can't offer any ideas.  The only suggestion I can offer is that you get the buttons where you want to be they, made your code to work with them rather than trying to make them work with the code.

  • New Notebook Laser Mouse 7000 - click on the button does not work so it is unusable

    If this is the wrong forum, please let me know. I couldn't find an obvious forum for mice. My old wireless mouse does so after much research, I chose a Laser Mouse 7000 and ordered online. I have download the drivers, follow the instructions for setting up and pressing the buttons, the installer with ALL THE BUTTONS by DEFAULT, reset and CLICK does not work. It acts like I am struck by right click. I tried moving, rearranging button settings, nothing works. When I go into control panel it says it is not working properly, but this certainly isn't. I also restarted x 2 to try to make the problem go away.

    It is a defective material, so should I just sent to the seller? That I've already lost too much time on this stupid thing. If I didn't always have a wireless mouse, I would not be able to use my PC

    Windows vista 64-bit standard

    Oh, I try the product. I have to enter the product number. It is very very small and very difficult to read, but I can enter the product correctly, I think. But here is the message that I will be back:

    "The product ID does not match the selected product.
    The product ID you entered is for Microsoft Wireless Notebook Laser Mouse 7000 (all languages), which is different from Microsoft Wireless Laser Mouse 7000 (all languages) you selected for support. Please enter the ID number of the product for Microsoft Wireless Laser Mouse 7000 (all languages) or click Select the product to select the right product. »

    WTF?

    Hello

    Microsoft Hardware Support access in the United States is 1-800-936-5700

    Dial the number and when he asks PID just say you don't know. You will need to give to the
    Tech answers so have a magnifying glass very convenient. There could be a more easy to read number on
    the receiver.

    Believe it or not, I had exactly the same experience with my entire keyboard and mouse, and I am
    in the meantime the new series arrived. Rob - bicycle - Mark Twain said it is good.

  • BlackBerry smartphone how to remove all the data on my blackberry when the buttons do not work?

    I have a Blackberry Curve 8330.  Yesterday the buttons stopped working.  I could use the phone only via Bluetooth.  Based on the information from this forum, I tried a number of hard resets and updated operating system.  None worked.  Verizon is to exchange the phone, but I don't want to send the phone back with all my info on this subject.  Is it possible to erase all the information on the phone without using the keyboard and the normal delete process memory?

    You can make a backup of the device using Desktop Manager > back up everything first.

    Then, you can use JLCmder to reset to factory settings:

    Follow the instructions in this link:

    http://www.BlackBerryForums.com/General-BlackBerry-discussion/18789-Jl_Cmder.html

    At last-

    This looks like what I've seen several times on a device with moisture damage.

    Even sitting on a countertop bath during a hot steamy shower or bath can cause the trackball and keyboard problems until this THAT well dry.

    Really, it is more common than you think.

    1 the battery immediately! Do not turn on your BlackBerry device.

    2. allow the device to dry in a warm, dry place for 3 to 5 days * (see below)

    3. DO NOT "check it every day" by placing the battery in. Leave what would to dry completely. It takes time. Replacing the battery to check it can damage only (humidity + power = disaster).

    3. If the unit is hot after the drying period, let it cool to room temperature before placing the battery in the.

    * Suggestions on your BlackBerry in a warm dry place (open, with battery):

    • Place the BB in a container of dry uncooked rice, and then you can also place it in one of the locations mentioned below.
    • On top of all heat dry emitting electronic components: TV or CRT, LCD, TV cable box / Satellite or plasma monitor
    • On the dashboard of your car on a day sunny

Maybe you are looking for