• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why will this code only trace strings?

Community Beginner ,
Jun 23, 2012 Jun 23, 2012

Copy link to clipboard

Copied

The following code randomizes the array "doors". It works fine if the array is strings. However,

if I remove the quotation marks, it traces "[object Symbol1_1]" instead.

var doors:Array = [red_button, blue_button,yellow_button];

var randomDoors:Array = new Array(doors.length);

var randomPos:Number = 0;

for (var i:int = 0; i < randomDoors.length; i++)

{

    randomPos = int(Math.random() * doors.length);

    randomDoors = doors.splice(randomPos, 1)[0]; 

}

trace (randomDoors);

Tracing (randomDoors.name) returns the  statement "undefined". How can I trace "doors" without converting the elements to strings?

TOPICS
ActionScript

Views

620

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 23, 2012 Jun 23, 2012

the array class doesn't have a name property.  when you use trace(randomDoors.name), you're asking flash to find the name property of that array.

so, either use:

for (var i:int = 0; i < randomDoors.length; i++)

{

trace(doors.name);

}

or create your own function or class to do what you want so you don't have to repeatedly create a for-loop to trace what you want.

Votes

Translate

Translate
Community Expert ,
Jun 23, 2012 Jun 23, 2012

Copy link to clipboard

Copied

assuming those doors elements have names, loop through that array and trace each elements name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 23, 2012 Jun 23, 2012

Copy link to clipboard

Copied

Thanks for the reply, but I'm not sure what you mean by that.

I have tried tracing one element at a time with the ".name" appendix and that returns an element of the array without it being in strings.And as I said, if I just put quotation marks around the elements in the "doors" array, then the array works fine.

I'm just a little confused by which array you're talking about and how I should trace it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2012 Jun 23, 2012

Copy link to clipboard

Copied

LATEST

the array class doesn't have a name property.  when you use trace(randomDoors.name), you're asking flash to find the name property of that array.

so, either use:

for (var i:int = 0; i < randomDoors.length; i++)

{

trace(doors.name);

}

or create your own function or class to do what you want so you don't have to repeatedly create a for-loop to trace what you want.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines