views:

158

answers:

2

It think Flash is telling me that my array tabData is getting duplicated, but I only set it up once in the var section of my code:

This is the line with the error:

for (var i in tabData) {

TabMenu class

private var tabData:Array = []; // <- tabData created here

public function drawTabMenu(w, h, color, videoHDiff, ypos):void
    {           
        trace("drawTabMenu --------------");

        for (var i in Global.xml..tab) {
            tabData.push( {id:Global.xml..tab[i].@id, video:Global.xml..tab[i].vid} );
        }

        // DRAW GRAPHICS CODE HERE...

        //draw the tabs
        for (var i in tabData) { // < line throwing error

            var tab:MovieClip = new TabDefault();
            var active:MovieClip = new TabActive();
            tabArray.push(tab);
            tab.video = tabData[i].video;
            tab.addChild(active);
            i < 1 ? active.visible = true : active.visible = false;
            tab.y = topShadow.y + 5;

            // add in the textfield here
            // addChild(tf);

            // resize the tab background to textfield
            tab.x = i < 1 ? 10 : tabArray[(i-1)].x + (tabArray[(i-1)].width+3);
            tab.active = i < 1 ? tab.active = true : tab.active = false;
            topShadow.addChild(tab);

            tab.mouseChildren = false;
            tab.buttonMode = true;
            tab.addEventListener(MouseEvent.CLICK, tabClick);
        }

        // set default thumbnails here
        trace("FIRST TAB DATA: "+tabData[0].video);
    }
+3  A: 

I don't know flash, but is the fact that you use i as the loop variable in both loops a problem? I think it shouldn't be - certainly wouldn't be in Java - but maybe that's it.

Also, unrelated to your problem, this line:

tab.active = i < 1 ? tab.active = true : tab.active = false;

would be easier to read like this:

tab.active = i < 1;

Again, assuming flash works like languages I know better.

Carl Manaster
BAM! That was it :) I just thought the error was talking about tabData, when it was talking about i
Leon
You can still use i for both loops, just don't use `var i` in the second one.
Selene
+2  A: 

i is the duplicate variable, not tabData. Actionscript allows only function scope, not block scope as in many (most) other languages.

Promoting apparently block level scope variables to function scope is called hoisting.

Resources:

Michael Brewer-Davis