0

我已经尝试过以下代码的变体,即从stagetothis.stage或 even切换root.stage,但没有运气。

我得到的完整错误是:

    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

}
4

2 回答 2

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

似乎“按钮”没有添加到舞台(在 next_image_loaded() 方法中),因此

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

抛出错误,虽然 'button' 可能存在 (!= null),但它没有添加到舞台

尝试使用 if 语句,如下所示:

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

编辑:正如维斯珀同时指出的那样

于 2012-10-02T13:31:36.193 回答
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函数中发生,因此请尝试在其中运行一些跟踪并使用结果更新您的帖子。

于 2012-10-02T12:52:47.240 回答