开发者

Why am I getting the "Duplicate variable definition" error here?

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);
    }


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.


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:

  • Adobe's description
  • Another tutorial
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜