2012-10-02 28 views
0

查看周围SO的答案,但真的很挣扎。我已经尝试了下面的代码中的变体,即从舞台切换到this.stage甚至root.stage,但没有运气。ArgumentError:错误#2025:提供的DisplayObject必须是调用者的孩子

任何帮助,非常感谢。

完整的错误我得到的是:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. 
at flash.display::DisplayObjectContainer/setChildIndex() 
at flash.display::Stage/setChildIndex() 
at Banner/next_image_loaded() 

package { 
    import flash.display.*; 
    import flash.events.*; 
    import flash.net.*; 
    import flash.utils.*; 
    import gs.*; 
    import gs.easing.*; 

public class Banner extends MovieClip 
{ 
    var xml_url:URLRequest; 
    var xml_loader:URLLoader; 
    var img_loader:Loader; 
    var img_data:Array; 
    var img:Bitmap; 
    var new_img:Bitmap; 
    var strapline:strap; 
    var banner:bottom_banner; 
    var button:tech_button; 
    var current_image:Number = -1; 
    var done:Boolean = false; 

    public function Banner() 
    { 
     this.xml_url = new URLRequest("Banner.xml"); 
     this.xml_loader = new URLLoader(this.xml_url); 
     this.xml_loader.addEventListener(Event.COMPLETE, this.xml_loaded); 
     this.xml_loader.addEventListener(IOErrorEvent.IO_ERROR, this.err); 
     return; 
    }// end function 

    private function xml_loaded(event:Event) 
    { 
     this.img_data = new Array(); 
     var _loc_2:* = new XML(event.target.data); 
     var _loc_3:* = 0; 
     while (_loc_3 < _loc_2.image.length()) 
     { 

      this.img_data.push(_loc_2.image[_loc_3]); 
      _loc_3 = _loc_3 + 1; 
     } 
     this.img_data = this.randomise_array(this.img_data); 
     this.next_content(); 
     return; 
    }// end function 

    private function randomise_array(param1:Array) : Array 
    { 
     var _loc_2:* = new Array(); 
     while (param1.length > 0) 
     { 

      _loc_2.push(param1.splice(Math.floor(Math.random() * param1.length), 1)); 
     } 
     return _loc_2; 
    }// end function 

    private function next_content() 
    { 
     if (this.current_image == (this.img_data.length - 1)) 
     { 
      this.current_image = 0; 
     } 
     else 
     { 
      var _loc_2:* = this.current_image + 1; 
      this.current_image = _loc_2; 
     } 
     this.img_loader = new Loader(); 
     this.img_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.next_image_loaded); 
     this.img_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.err); 
     this.img_loader.load(new URLRequest(this.img_data[this.current_image])); 
     return; 
    }// end function 

    private function next_image_loaded(event:Event) 
    { 
     var _loc_2:Number = 0; 
     this.new_img = event.target.content; 
     stage.addChild(this.new_img); 
     if (this.strapline) 
     { 
      stage.setChildIndex(this.strapline, (stage.numChildren - 1)); 
     } 
     if (this.banner) 
     { 
      stage.setChildIndex(this.banner, (stage.numChildren - 1)); 
     } 
     if (this.button) 
     { 
      stage.setChildIndex(this.button, (stage.numChildren - 1)); 
     } 
     if (this.current_image == 0 && this.done != true) 
     { 
      this.button = new tech_button(); 
      this.button.x = 28; 
      this.button.y = 257; 
      //stage.addChild(this.button); 
      var _loc_3:Boolean = true; 
      this.button.buttonMode = true; 
      this.button.useHandCursor = _loc_3; 
      this.button.addEventListener(MouseEvent.CLICK, this.goToTechPage); 
      TweenLite.from(this.button, 0.5, {alpha:0, delay:1.5}); 
      this.banner = new bottom_banner(); 
      this.banner.x = 0; 
      this.banner.y = stage.stageHeight - 40; 
      stage.addChild(this.banner); 
      this.strapline = new strap(); 
      this.strapline.x = 232; 
      this.strapline.y = 195; 
      stage.addChild(this.strapline); 
      TweenLite.from(this.strapline, 1, {x:stage.stageWidth, ease:Expo.easeOut, delay:0.75, onComplete:this.fade_strap}); 
      this.done = true; 
     } 
     else 
     { 
      _loc_2 = 0.75; 
     } 
     TweenLite.from(this.new_img, 1, {autoAlpha:0, ease:Expo.easeOut, onComplete:this.swap_clips, delay:_loc_2}); 
     return; 
    }// end function 

    private function goToTechPage(event:MouseEvent) : void 
    { 
     navigateToURL(new URLRequest("report.htm"), "_self"); 
     return; 
    }// end function 

    private function fade_strap() 
    { 
     TweenLite.to(this.strapline.bg_mc, 1.5, {alpha:0.85}); 
     return; 
    }// end function 

    private function remove_strap() 
    { 
     this.strapline.parent.removeChild(this.strapline); 
     this.strapline = null; 
     return; 
    }// end function 

    private function swap_clips() 
    { 
     if (this.img) 
     { 
      stage.removeChild(this.img); 
     } 
     this.img = this.new_img; 
     this.new_img = null; 
     setTimeout(this.next_content, 6500); 
     return; 
    }// end function 

    private function err(event:IOErrorEvent) 
    { 
     if (this.img_data) 
     { 
      this.next_content(); 
     } 
     return; 
    }// end function 

} 

}

+2

为什么你注释掉'stage.addChild(this.button);'?我期望,因为按钮被分配,这一个是错误的行。 – Vesper

回答

1

这是一个很大的代码,有人要读通过,您可以缩小其中的错误是在重点用trace("trace 1")发生点你的代码(每次更改数字)。当你执行你的代码的输出窗口将显示你的痕迹,即:

trace 1 
trace 2 
trace 3 
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller 

这告诉你第三跟踪之后发生的错误一段时间。你得到的错误告诉你它正在next_image_loaded函数中发生,所以请尝试在那里运行一些痕迹,并用结果更新你的文章。

3
//stage.addChild(this.button); 

似乎 '按钮' 没有被添加到载物台(在next_image_loaded()方法),因此

if (this.button) 
{ 
    stage.setChildIndex(this.button, (stage.numChildren - 1)); 
} 

引发错误,虽然 '按钮' 可以存在(!= NULL) ,它不添加到舞台

尝试用if语句如下:

if(button != null && button.stage != null) 

编辑:作为维斯珀已经POIN在此期间同步

相关问题