ArgumentError: Ошибка № 2025: Предоставленный DisplayObject должен быть дочерним элементом вызывающего объекта.

Я пробовал варианты в приведенном ниже коде, то есть переход с stage на this.stage или даже на 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

}

person Nagra    schedule 02.10.2012    source источник
comment
почему вы закомментировали stage.addChild(this.button);? Я ожидаю, что, поскольку кнопка выделена, это строка с ошибкой.   -  person Vesper    schedule 02.10.2012


Ответы (2)


Это много кода, который нужно прочитать кому-то, вы можете сузить область возникновения ошибки, используя 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, поэтому попробуйте запустить там несколько трассировок и обновите свой пост с результатами.

person Simon McArdle    schedule 02.10.2012

//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)

РЕДАКТИРОВАТЬ: как тем временем Веспер уже указал

person g10    schedule 02.10.2012