A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: array referencing question

  1. #1
    Senior Member
    Join Date
    Oct 2002
    Location
    Location Location
    Posts
    161

    array referencing question

    Ok, i thought I had this figured out, but no.

    Let's say I have an array : _root.stuff.thingy.myArray
    it contains 10 names for MCs running around in _root.stuff ... MC1, MC2, etc...
    Let's say there's a dude trying to use his teeth to eat those MCs: _root.dude.teeth

    when i make the dude's teeth close, I want to do a for loop hitTest on all 10 MCs, so i started writing:
    code:
    for(i=0;i<10;i++){
    if(_root.dude.teeth.hitTest(_root.stuff.myArray[i]) {
    _root.stuff.myArray[i].gotoAndPlay("open");
    }
    }



    but this obviously won't work because it doesn't target the array. How do I write this?

  2. #2
    Junior Member
    Join Date
    Dec 2003
    Posts
    28
    hmm, with that code you are only really targeting something like
    code:
    if(_root.dude.teeth.hitTest(MC1) {

    on each iteration, if you use a direct path like _root[_root.stuff.myArray[i]] you are targetting _root.MC1 which is more likely to be the correct path. (assuming MC1 is on the _root)
    [m]

  3. #3
    Senior Member
    Join Date
    Oct 2002
    Location
    Location Location
    Posts
    161
    MC1 is in _root.stuff
    the array with it's name is in _root.stuff.thingy.myArray

  4. #4
    Senior Member
    Join Date
    Oct 2002
    Location
    Location Location
    Posts
    161
    the thing is, I know how to get the name of the MC out of the array, but how do I get that name into _root.dude.teeth.hitTest(the name of the MC properly targeted)

  5. #5
    Junior Member
    Join Date
    Dec 2003
    Posts
    28
    try
    code:
    _root[_root.stuff[_root.stuff.myArray[i]];


  6. #6
    Senior Member
    Join Date
    Oct 2002
    Location
    Location Location
    Posts
    161
    thanks for the help. it was the bracketing I didn't know about. Yasunobu gave me a similar answer

    _root.dude.teeth.hitTest(_parentMC[_root.stuff.myArray[i]])

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