这有效:
subnavData = new Array( {"title":"PROCESS", "func":this.changeSlide, "param":this.showProcess}, {"title":"OVERVIEW", "func":this.changeSlide, "param":this.showServices, "hasChild":true}, {"title":"CREATIVE DIRECTION", "func":this.changeSlide, "param":this.showBranding, "childOf":1}, {"title":"SOCIAL INTERACTIVE", "func":this.changeSlide, "param":this.showOnline, "childOf":1}, {"title":"LIVE EVENTS", "func":this.changeSlide, "param":this.showLiveEvents, "childOf":1}, {"title":"CONTENT STRATEGY", "func":this.changeSlide, "param":this.showPerformance, "childOf":1}, {"title":"CASE STUDIES", "func":this.changeSlide, "param":this.showCaseStudies}, {"title":"CLIENTS", "func":this.changeSlide, "param":this.showClients} );
但这不是:
subnavData = new Array( {"title":"OVERVIEW", "func":this.changeSlide, "param":this.showServices, "hasChild":true}, {"title":"CREATIVE DIRECTION", "func":this.changeSlide, "param":this.showBranding, "childOf":0}, {"title":"SOCIAL INTERACTIVE", "func":this.changeSlide, "param":this.showOnline, "childOf":0}, {"title":"LIVE EVENTS", "func":this.changeSlide, "param":this.showLiveEvents, "childOf":0}, {"title":"CONTENT STRATEGY", "func":this.changeSlide, "param":this.showPerformance, "childOf":0}, {"title":"PROCESS", "func":this.changeSlide, "param":this.showProcess}, {"title":"CASE STUDIES", "func":this.changeSlide, "param":this.showCaseStudies}, {"title":"CLIENTS", "func":this.changeSlide, "param":this.showClients} );
...当被这个函数处理时:
private function makeNewSubNav($data:Array):void { group = new Array(); for(var i:Number = 0; i < $data.length; i++){ var obj:Object = new Object(); obj.active = false; obj.mc = new MovieClip(); if($data[i].childOf) { obj.childOf = $data[i].childOf; obj.mcB = new SubMenuTopButton(); obj.mcB.arrow.x = -obj.mcB.arrow.width; obj.mcB.txtmask.x += 10; obj.mcB.y = group[obj.childOf].subMasked.height; var childbg:Sprite = new Sprite(); childbg.graphics.beginFill(0xfdddf0, 1); childbg.graphics.lineStyle(); childbg.graphics.drawRect(0,0,167, 21); childbg.graphics.endFill(); obj.mcB.addChildAt(childbg, 0); group[obj.childOf].subMasked.addChild(obj.mc); } else { obj.childOf = false; obj.mcB = new SubMenuTopButton(); navContainer.addChild(obj.mc); } obj.mc.addChild(obj.mcB); obj.mcB.txtmask.tf_name.text = $data[i].title; obj.mcB.buttonMode = true; obj.mcB.mouseChildren = false; obj.mcB.num = i; obj.callback = $data[i].func; obj.param = $data[i].param; obj.mcB.addEventListener(MouseEvent.CLICK, navPress); obj.mcB.addEventListener(MouseEvent.MOUSE_OVER, navOver); obj.mcB.addEventListener(MouseEvent.MOUSE_OUT, navOut); if($data[i].hasChild){ obj.hasChild = true; obj.subContainer = new MovieClip(); obj.subMasked = new MovieClip(); obj.subMask = new MovieClip(); obj.subMask.graphics.beginFill(0x0000FF,1); obj.subMask.graphics.lineStyle(); obj.subMask.graphics.drawRect(0,0,width,1); obj.subMask.graphics.endFill(); obj.subMask.height = 0; obj.subContainer.addChild(obj.subMasked); obj.subContainer.addChild(obj.subMask); obj.subMasked.mask = obj.subMask; obj.subContainer.y = obj.mc.height; obj.mc.addChild(obj.subContainer); } group.push(obj); } group[0].active = true; adjustHeight(); }
我知道这与零值有关。我只是不知道该怎么做。孩子应该形成一个子菜单。任何想法?
答案 0 :(得分:2)
在我看来,由于childOf为0,if ($data[i].childOf)
失败
尝试以下任何一项:
if ($data[i].hasOwnProperty('childOf')
if ($data[i].childOf != undefined)
if ($data[i].childOf != null)
答案 1 :(得分:1)
我敢打赌问题就在这一行:
if($data[i].childOf) {
并且您的语言将0视为等同于false。因此,找到另一种表示 - 可能是负值作为标志,或更明确的测试。