Solved

AS3 loop dynamic var name

Posted on 2011-02-15
1
512 Views
Last Modified: 2012-05-11
Hi,

why won't the below code work?

I keep getting this error:
syntax error: expecting semicolon before leftbracket.


Thanks.
for(var i:int=0; i < e.length; i++)
	{
		//trace(e[i].channel);
		var test[i]:TextField = new TextField();
		test[i].text = e[i].channel;
		addChild(test[i]);
		
	}

Open in new window

0
Comment
Question by:Solutionabc
1 Comment
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 34897754
Either you do this:
for(var i:int=0; i < e.length; i++)
        {
                var test:TextField = new TextField();
                test.text = e[i].channel;
                addChild(test);
        }

Open in new window

or this:
var test:Array = new Array();
for(var i:int=0; i < e.length; i++)
        {
                test[i] = new TextField();
                test[i].text = e[i].channel;
                addChild(test[i]);
        }

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question