dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: referencing elements from variables ???

Hybrid View

  1. #1
    Hi,

    Does anyone know how to:

    1. create an array of buttons with different gif files
    as images.

    or

    2. reference an element as a variable using JS.



    The code I tried to make work as follows:

    on "button1" button press
    btn = "button1"

    JS action
    Element(btn).position.x = 100 --- this doesn't work
    Element("button1").position.x = 100 --- this works but I have 15 buttons and would prefer to use less code.


    All suggestions gratefully received.

    Regards,
    a_non_amous.















  2. #2
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681
    Hello a_non_amous,
    Code:
    // set the size of the array to contain 3 buttons
    aButtons = new Array(3);
    
    // load the array with the buttons
    aButtons[0] = element("button1");
    aButtons[1] = element("button2");
    aButtons[2] = element("button3");
    
    // position the buttons using an index (ndx)
    for(ndx = 0; ndx < 3; ndx ++)
    {
       aButtons[ndx].position.x = 100;
       aButtons[ndx].position.y = 30 + (ndx * 100);
    }
    HTH

  3. #3
    Kusco,

    Thanks once again.

    We will have to catch up for a beer sometime.

    Regards,
    a_non_amous.

  4. #4
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681

    Mmmmmm, beeer

    Hello a_non_amous,

    Yep, there is a beer fee

    Just forgot to mention that you will also need to ensure that the button properties button is selected too otherwise the element("") function is'nt going to work.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center