How to create an Array of Button components in AS

First I tried this:
for (var j:uint = 0; j < 10; j++){
var testButton:Button = new Button;
testButton.label = "Test Button";
testButton.addEventListener(MouseEvent.CLICK,
function():void{trace("j = " + j);});
addChild(testButton);
But every button's mouse click returns a trace of 10. I need
the button to be aware of it's index. How do I go about doing this?
I tried making an array:
var testButton:Array = [];
for (var j:uint = 0; j < 10; j++){
testButton[j]:Button = new Button;
testButton[j].label = "Test Button";
testButton[j].addEventListener(MouseEvent.CLICK,
function():void{trace("j = " + j);});
addChild(testButton[j]);
But this gives a compile error:
"Label must be simple identifier"

You can use data property of the Button to store the index.
You can use a ButtonBar to keep track of your buttons as a
list.
You can write a clickHandler as a normal function -- as
opposed to anonymous one you have -- and pass the index of the
button that you have stored in the data property.
why you're not getting the behavior in the click handler that
you're looking for? You'll need to study the scope and context for
variables in Flex.
Hope this helps.
ATTA

Similar Messages

  • How to create a array of GUI components?

    Hello, everyone!
    I need help or advice how to create an GUI components array. As I remenber in VB this possible just by calling two or more buttons (for example) with the same name. The API will authomatically create an array: Buton[0], Button[1], Button[2] and so on...
    In Java it possible as well:
    JButton button[];
    button = new JButton[10];
    for ( int i = 1; i < 10; i++ ){
    button[i] = new JButton();
    ....and so on....
    But my problem is that I use Forte for Java v. 3.0 and when I using Frame Editor it does not allow me to call two components with the same name and at the same time does not allow to change the initialization code painted in blue color...
    Does anyone knows how to avoid this, or how to create GUI components array in Forte for Java API using Frame Editor or Component Inspector???
    All that I need is few buttons accessible by index ( button[1], button[2] etc.) I will apreciate any help or advise.
    Thank you in advance,
    Michael

    I tried using Forte after having used Windows notepad and found that I
    like notepad much better. If you seem to be having problems with Forte,
    you might just try writing this portion of code in a regular text editor
    and compiling it with a command line compiler. Hope this helps some.

  • How to create an array using reflection.

    How to create an array using reflection.
    I want to achive something like this,Object o;
    o = (Object)(new TestClass[10]);but by use of reflection.
    To create a single object is simple:Object o;
    o = Class.forName("TestClass").newInstance();But how do I create an array of objects, when the class of objects is known only by name? (Can't use Object[] because even though an Object[] array can be filled with "TestClass" elements only, it Cannot be casted to a TestClass[] array)
    Anybody knows?":-)
    Ragnvald Barth
    Software enigneer

    Found it!
    the java.lang.reflect.Array class solves it!
    Yes !!!

  • How to create an array of linklists??? ... plz

    Hi guys,
    I am trying to create a Hash table. My link list is already working. But i am still confused about how to create any array linklist for solving the collisions. Do i need to create a new instance of the linklist for each array slot? What is the better way to do?
    just need some hint to start it.
    abdul

    Yes, you need to create a new instace for each slot.
    LinkedList[] ht = new LinkedList[size];
    for(int x = 0; x < size; x++)
        ht[x] = new LinkedList();

  • How to create an array variable

    Hi folks,
    I'm developing a flowN activity , for each branch created, I need to pass different values (values I get from DB).
    For this my plan would be,
    -create an array variable , load all the values(from DB) into the array
    -pass the array to each branch in flowN activity based on the index
    As I'm newbie to BPEL, I do not know how to create an array variable.
    Could you people guide me please.
    Regards
    Viki

    Hi,
    I created my string array like
    <element name="string_array">
    <complexType>
    <sequence>
    <element name="input" type="string" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    </element>
    <variable name="arr" element="client:string_array"/>
    I am able to add values to my array variable named as "arr"
    When I use the following code snippet, it gives my the value of the entire list.
    <%ora:getNodeValue(bpws:getVariableData('arr'))%>
    But when I try retireve values one by one like <%ora:getElement('arr','/client:string_array/client:input',[0])%>, its giving me error.
    Guide to get throu' this.
    Viki

  • How to create 2D array with 3 rows and unlimit column?

    how to create 2D array with 3 rows and unlimit column?

    Here are images of what I described in my previous post
    Message Edited by JoeLabView on 11-14-2007 07:56 AM
    Attachments:
    2D-array_code.PNG ‏7 KB
    2D-array_values.PNG ‏13 KB

  • How to create a new push button in application tool bar in GMGRANT thru BDT

    Dear SAP Gurus -
    We have a requirement in 'GMGRANT' transaction. We need to create a button in the application tool bar of 'GMGRANT' transaction. Once the button is activated, if the user clicks on the button then it will go to a new screen (external screen). User can input data in to the external sceeen and upon saving, the data will be stored in to a custom table and when user clicks on 'back ' button user should come back to the GMGRANT transaction.
    Just wanted to know, how to create / activate a new button on application tool bar of GMGRANT transaction and what are the configuration and detail steps to achieve the same through BDT.
    We went through a lot of documents on BDT but do not have a proper solution.
    Could you please help.
    Thanks in advance.
    Regards,
    Atul Mohanty

    hi,
    You can find user-exits (menu exits) to add new menu item.
    But, there is no possibility to add new buttons on application tool bar.
    Regards,
    Sailaja.

  • How to create dropdown box, radio button,check box in wad

    Hi,
    How to create dropdown box, radio button,check box in wad.
    Thanks,
    cheta.

    Cheta,
    This are all standard Web Items in the WAD. Drag them onto your template and then make the changes you need to them in their Properties.
    Regards
    Gill

  • How i create popup menu when button onclick

    how i create popup menu when button onclick

    You try adding a scrip tag in your jsp code, and calling the function in the onclick attribute.
    Example:
    <script><![CDATA[
                    function confirmDelete(){
                    if(confirm("Are you sure you want to delete selected user")){
                    return true;
                    } else{
    return false;
    ]]></script>
    <ui:button action="#{View.delete_action}" binding="#{View.delete}" id="delete" onclick="confirmDelete"/>
    Cheers
    Daniel
    null

  • How to create an array list of strings by using buttons?

    HI, i need some guidance from you guys to help me out. How do i create a list of array whenever i click on a button it will generate a string and place it in an array row by row. if i dont click on the button it will ignore it and wont create the array. i have tried many technics such as looping and building array but it wont generate the list that i want.
    Attachments:
    untitled.JPG ‏97 KB

    I am not sure if I have understood your question correctly, but is the attached what you were looking for?
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies
    Attachments:
    Example.vi ‏12 KB
    example.JPG ‏100 KB

  • How to create an grid of buttons.

    Im trying to create a grid of buttons but for some reason i can see only 2 of them at the same time, but i know they are 9 on stage cause i trace numChildren
    Currently i have this:
    public class Main extends MovieClip
                        private var myBtn:SimpleButton = new SimpleButton();
                        private var img1:Bitmap=new Bitmap(new active_MouseOut());
                        private var img2:Bitmap=new Bitmap(new active_MouseOver());
                        private var img3:Bitmap=new Bitmap(new notActive_MouseOut());
                        private var img4:Bitmap=new Bitmap(new notActive_MouseOver());
                        private var myArrayContainer:Array = new Array();
                        public function Main()
                                  for (var i :int = 0; i < 3; i++)
                                            for (var j:int = 0; j < 3; j++)
                                                      myArrayContainer[j] = new MyButton(img1, img2, img3, img4)
                                                      myArrayContainer[j].x = 0 + i * (myArrayContainer[j].width + 10)
                                                      myArrayContainer[j].y = 0 + j * (myArrayContainer[j].height + 10)
                                                      this.addChild(myArrayContainer[j])
                                  trace(numChildren)
    active_MouseOut, active_MouseOver, notActive_MouseOut and notActive_MouseOver are simple bitmap Images that have AS linkage
    And MyButton class is this
    package
              import flash.display.Bitmap;
              import flash.display.MovieClip;
              import flash.display.SimpleButton;
              import flash.events.MouseEvent;
              import flash.utils.getDefinitionByName;
              public class MyButton extends MovieClip
                        private var myBtn:SimpleButton = new SimpleButton();
                        private var image1:Bitmap
                        private var image2:Bitmap
                        private var image3:Bitmap
                        private var image4:Bitmap
                        public function MyButton(active_OutState:Bitmap, active_OverState:Bitmap, notActive_OutState:Bitmap, notActive_OverState:Bitmap)
                                  image1 = active_OutState;
                                  image2 = active_OverState;
                                  image3 = notActive_OutState;
                                  image4 = notActive_OverState
                                  myBtn.upState = image1;
                                  myBtn.overState = image2;
                                  myBtn.downState = myBtn.upState;
                                  myBtn.hitTestState = myBtn.overState;
                                  addChild( myBtn );
                                  myBtn.addEventListener(MouseEvent.CLICK, onClick);
                        private function onClick( ev:MouseEvent ):void
                                  myBtn.upState = image3;
                                  myBtn.overState = image4;
    I also want to ask : Can I get the bitmapData to load in the MyButton class with this
    private var image1:Bitmap
    public function MyButton(mouseState:String)
                                   image1_Data = Class(getDefinitionByName( mouseState ));
                                  image1 = new Bitmap( image1_Data() )
    and in the Main Class to send the name of the image in the library
    myArrayContainer[j] = new MyButton( "notActive_MouseOver" )
    or I can do this only in/from the Document Class
    cause Im trying and it is giving me this
    Error #1065: Variable notActive_MouseOver() is not defined.

    well Im doing the button-making in the MyButton class cause im trying to create 9 buttons(and every button has a different image and that image has 4 states(clickable-Up, clickable-Over, notClickable-Up, notClickable-Over  )).
    And this is the only way i figured out how to do it without writing alot of code ()

  • How to create subpicture for a button?

    Hello!
    I have really tried to find the answer to this rather silly problem on my own, but without result. Please help someone!
    The situation:
    I have a menu with three choices: "Play Movie", "Scene Selection" and "Subtitles". Now, the text presenting these choices are part of the background image, created in Premiere (the program I know best). They are written with an old typewriter to get that gritty feeling.
    I want the user to scroll between these "menu items". The currently selected item should be indicated by a black circle/spot/dot before the text of the item. By default, when the menu appears, there is a black circle in front of (to the immediate left of) the item "Play Movie". The user should now be able to step with his/her remote to the other items, thereby making the black circle in front of "Play Movie" disappear and appearing instead before some of the other items. In short: the black circle is always showing before the currently selected item. OK, I got a bit verbose there, but the idea got across hopefully. One more thing: the background color is 100% white.
    Up to this point, my solution was this: I placed black circles (small images with gradation and all, very nice looking) in front of ALL THREE ITEMS. Then I convert these into buttons. Then I choose the color set for the menu so that the unselected state is 100% white, plain and simple, with 100% opacity, thereby covering the black circles that should not show. Only in the selected and activated states does opacity for the button subpicture drop to 0%, thereby revealing the black circle that should be seen.
    The problem? Well, on some DVD-players (not on the XBOX 360 though), when an item is activated, all three circles show for a brief moment before the selected action starts (for example playing the movie). It also happens in Encore Preview. This is not logical at all and looks amateurish. I don't know why it happens, but my guess is that it wouldn't if I did this the "correct" way: by creating subpictures fo the buttons in the shape of circles. I understand the nice looking gradations must go out the window but that is a price I'm willing to pay.
    But now I run into an unexpected problem: I don't understand how to create a subpicture for the button that is a black circle. It seems the documentation in Encore and on forums in general takes for granted that you know how to do this.
    What I tried ws this: I created a monochrome, small image in bmp format - a black circle on white background. But this image just shows up as a black rectangle in Encore.
    What should I do? I should add that I have no real experience with Photoshop, so go slow if you go there.
    Regards,
    Nikolaj

    Basically, when one realizes the limitations of the Sub-picture Highlights, as set by the DVD-specs., it's easy to see the "workaround."
    A couple of the aspects of Sub-picture Highlights are:
    1.) 2-bit color (either ON, or OFF), from a limited color palette, with degrees of Transparency (the opposite of PS's Opacity).
    2.) they will appear on top of anything else on the Menu, including things like Button text/graphics.
    By constructing your Sub-picture Highlight in PS, you can use Masking to define where it will be, and where it will not be. In the case that prompted my article, the poster had a series of Text Buttons, and the Sub-picture Highlights were formed from that Text. The poster did not like the look of those 2-bit jagged blocks of color overlying the Text in the Button. The workaround is to "punch a hole" in the Sub-picture Highlight, so that it is hollow, where the Button's Text appears. This is done in PS, by using the "outline" of that Text to create a Mask for the Sub-picture Highlight. The jagged aspect can be adjusted a bit, by using a degree of Transparency (set in the non-Auto Color Set back in Encore). We still have a 2-bit color Sub-picture Highlight, and it still overlays the Button's Text, but now there is a hole in it, right where the Button's Text is located, and it is seen through that hole. The introduction of Transparency has the visual effect of "softening" the look of the 2-bit color, even though the jagged edges are still there - they just look softer. I went on to show how one could even use a second Sub-picture Highlight, that is just a bit larger than the first, and with more Transparency to simulate a "glow." Now, we cannot have a real "glow," because we are limited to that 2-bit color for the Sub-picture Highlight, but we can simulate it.
    Much of what a designer does is really slight of hand - illusion. They all have to work within the limitations of the DVD (or BD) specs., but with a bit of creativity, planning and some work in PS and Encore, they can create enough smoke and use enough mirrors to fool the user into believing that what they think they see skirt the DVD-specs. They do not, but that's where the illusion comes in.
    We get a lot of questions from people, who claim that one commercial DVD, or another, has full-color Sub-picture Highlights and they complain that Encore cannot do that - only 2-bit Sub-picture Highlights. What they are seeing, but do not realize it, is a dupe Menu, with a full-color graphic, and no real Sub-picture Highlight visible. Jeff gives full details on doing this. Same for those who have seen a Button with a duo-tone thumbnail, that turns full-color, when the Button is navigated to. Wow, how did they do that, and why can't Adobe Encore do that? Well, what they saw was a dupe Menu, with a full-color thumbnail and no visible real Sub-picture Highlight.
    Jeff shows how to create what appears to be at least a 3-color Sub-picture Highlight. It's really just 3 regular 2-bit color Sub-picture Highlights, with Masking to create the illusion that he beat the DVD-specs. Neat! [Being from the USA, I also liked that he used the US flag, but he could have chosen the French "Tri-color," or any other flag, without artwork.]
    These are all just tricks, but if the user buys into the illusion, who's to know?
    Enjoy,
    Hunt
    PS - though many of the great, older posts were lost, when the forum changeover happened, I strongly suggest reading the posts here. You can bypass ones that do not offer you anything, but almost every possible illusion has been discussed at least one time, and likely many, with some different workflows offered by those, who replied. Great reading.

  • How to create an array in if/else or case structure without 0's ?

    Hello,
    I've been trying to do this for a while now.
    I only managed to think of this in three ways:
    1. (What I'm doing right now Create the array by going through a for loop, which populates the array by auto indexing. It populates with correct number if true and with a '0' if false. The idea was to delete the 0's later on in the code. This however seems highly ineffective.
    2. Make use of a shift register, which automatically adds the correct number to an array. The problem is that the array will keep growing and growing and at the very least would tremendously slow down my program. At worst, it would crash.
    So, my question is: How do I create an array that if a comparison is true, it puts the element in and if not it does nothing ?
    I've attached a PNG snippet of my code.
    Kind Regards,
    David.
    Solved!
    Go to Solution.
    Attachments:
    Get_Indices.png ‏24 KB

    Pladio wrote:
    I've been trying to do this for a while now.
    You did not explain what "this" is. Can you give some typical inputs and expected outputs? Populate your controls and indicators with typical data and make it the default efore attaching.
    Pladio wrote:
    So, my question is: How do I create an array that if a comparison is true, it puts the element in and if not it does nothing ?
    Your code show three different comparisons. Which one are you talking about.
    Pladio wrote:
    I've attached a PNG snippet of my code.
    That code makes very little sense. Why is there a shift register if the data in it never changes? What is the purpose of the inner FOR loop? Why are you creating a 2D array?
    Do you want to remove all rows where the corersponding SD is zero, for example?
    LabVIEW Champion . Do more with less code and in less time .

  • How to create an array in bpel?

    I am trying to integrate a web service into open-esb. The web service consumes an unbounded array of a "userInfo" data structure. The issue is that although I can create bpel to receive a message like this, due to type incompatibilities I need to create a different array within bpel to pass to the webservice.
    To date I have not found a way to create an array within open-esb's bpel. After extensive googling I have found that other ESBs define their own proprietary extensions to add nodes to an array.
    Thus I have two questions:
    First, does open-esb support creation of arrays? and if so, how do I create the array and add nodes to it?
    Second, and perhaps more importantly, is using an <assign> activity the best way to transfer a potentially large array from one variable to another (i.e., will it perform well)? Or should I use XSLT to transform the array from one wsdl type to another? And if XSLT is the answer, how can I do this within open-esb?
    Thanks in advance,
    Steve
    PS. Based on the various googlings Ive been doing this question seems to be frequently asked. If someone will help me find a solution I plan on writing a short "how-to" article for posting back to the community. Given that arrays are one of the most basic data structures I hope the article will be useful for others struggling with this issue.

    I think this is all covered in Steve-Nies other thread concerning this subject, entitled "Need help with BPEL please" (http://forum.java.sun.com/thread.jspa?threadID=5116270&tstart=0)

  • How to create Componet array in NetBean?

    I want to create ten or more text field with same format.
    Also want to use NetBean to done it with out typing the code self.
    How can I do?
    I mean whether easy and fast method to create componet array in netbean.

    I want to create ten or more text field with same
    format.
    Also want to use NetBean to done it with out typing
    the code self.Why not? because it's the fastest, simplest and safest way.
    How can I do?
    I mean whether easy and fast method to create
    componet array in netbean.Just like oyu'd do it without Netbeans.
    If you still want to do it in Netbeans, I suggest reading the manual. This is not a Netbeans product support forum, and I'm definitely not inclined to help as you don't want it done by writing code yourself.

Maybe you are looking for

  • [SOLVED] Puzzled: Web site visible on network but not outside network

    Edit: Ok, nevermind . . . somehow the problem has resolved itself. Perhaps my ISP was having a bad hair day or something. I'm puzzled by this small problem I'm having. It is NOT a critical problem or anything, just something I'd like to solve. I've i

  • 10.1.0.2.0 to 10.2.0.1.0 upgrade

    Hi, I couldn't find similar post, so decided to write: 1. Is it possible to upgrade Oracle 10.1.0.2.0 to 10.2.0.1.0? 2. If so, can you provide links for downloading appropriate files? 3. If so, are there required any additional, special actions to up

  • Employee photo upload from BSP

    Dear experts, I'm trying to upload employee photos from a BSP. However, as they have to be stored on the content server and linked to the employee number, I don't know which FM's are need to be called. I'd thank you if you can provide me a step by st

  • Combo box to target frames

    I am trying to figure out how to use the comboBox to target different frames. For instance - Label One goes to Frame 1, Label Two goes to Frame 2, etc. I am very limited in my flash knowledge base so please forgive me if there is an obvious solution

  • One error when compiling

    im trying to sort this code out. Im now getting one error now when compiling it. cannot resolve symbol }Link link = >new< Link (texts[i][j]); it doesnt like the new for some reason import java.awt.*; import java.awt.event.*; import javax.swing.*; imp