dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Dynamically Addressing Elements

  1. #1
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590

    Dynamically Addressing Elements

    Hi Forum,

    Is it possible to do something like the following:

    Instead of:

    element("Terry").x=0;
    element("June").x=0;

    Is there a way I can do something like:

    variableelementname="Terry";
    element(variableelementname).x=0;
    variableelementname="June";
    element(variableelementname).x=0;

    This is so that I can avoid having to address lots of elements individually. I tried it, but it says I need to have the " in the brackets of the element name. Is there a trick to doing this, or is it just not possible?

    Thanks in advance,

    Morgan.
    Please note that my domain has changed to http://www.morganmultinational.com

  2. #2
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590

    Answering Own Question

    Perhaps I ought to stop answering my own questions

    I thought about the problem another way, and found I could use an array to address the elements dynamically instead. It just goes to show, sometimes you can get to the other side faster by going round the mountain rather than over it.

    I've attached an example, since it might help someone else.

    M.
    Attached Files Attached Files
    Please note that my domain has changed to http://www.morganmultinational.com

  3. #3
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681
    Hello ForumNewbie,

    You're almost there in the first example you tried.

    You can do this to access elements as well...

    myelement = element("someelement");
    myelement.x = myvar;
    myelement.y = myothervar;

    And, as you have already mentioned you can use arrays to access elements.

    myarray = new Array;
    myarray(0) = element("myelement");
    myarray(0).x = myvar;
    myarray(0).y = myothervar;

    myarray(1) = element("myotherelement");
    myarray(1).x = anothervar;
    myarray(1).y = yetanothervar;

    HTH
    Cheers,
    kusco
    (3DFA Support Team)

  4. #4
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    Yep.

    Those arrays are working perfectly now.

    Thanks,

    M.
    Last edited by ForumNewbie; 01-19-2005 at 11:52 PM.
    Please note that my domain has changed to http://www.morganmultinational.com

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