Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AS3 loop dynamic var name

Posted on 2011-02-15
1
Medium Priority
?
519 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 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