Skip to main content
June 6, 2012
Answered

Importing movieclips from library with arrayable instance names how???

  • June 6, 2012
  • 1 reply
  • 1221 views

The title says everything...

Here is the example:

centerx = 275;

centery = 200;

plussx = 26;

plussy = 15;

layern = 1;

terrainn = 1;

placer = 0;

GRASS = new Array();

while (layern != 2){

    _root.attachMovie("terrainG", "GRASS[terrainn]", layern); //<<<<< How can I do something like that?

    GRASS[terrainn]._x = centerx+plussx*placer;

    GRASS[terrainn]._y = centery+plussy*placer;

    terrainn++;

    layern++;

    placer++;

}

This topic has been closed for replies.
Correct answer Ned Murphy

You probably want to use something like...

GRASS[placer] = _root.attachMovie("terrainG", "terrainn"+placer, layern);

using the placer variable instead of the terrainn, since arrays start at index 0 instead of 1.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 7, 2012

You probably want to use something like...

GRASS[placer] = _root.attachMovie("terrainG", "terrainn"+placer, layern);

using the placer variable instead of the terrainn, since arrays start at index 0 instead of 1.

June 7, 2012

Thanks! that worked!

Also do you know how do I convert a string to integer? I've tried using Number() and parseInt(), they doesn't seem to work... Someone said that I should try creaning the string by running it in to "regEx" I am not sure how... WHat I know is that it is possible that my string has some hidden characters like " " or even unprintable..

Any ideas?

Ned Murphy
Legend
June 7, 2012

AS2 does not have an integer class, so if you want to convert a string to a number you can use the Number(string) approach so long as the characters are numeric.  Using parseInt can work but only when the numeric characters are in the front of the string.  If you have some other mix of alphanumeric characters, then you would need to go thru the string and revise it to only have the numeric elements.  For this you could loop thru the string and test each character in it to see if it is a number... if not, do not include it in the string destined to be the numeric result.