我已经尝试过以下代码的变体,即从stage
tothis.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
}