我无法让精灵按钮以适当的深度显示。我怀疑它可能与我的Loader对象有关但无法找到解决方案。当我跟踪深度时,它是正确的索引3,但仍显示在索引0上。“关闭视频开始和关闭视频结束评论之间的代码谢谢。
import flash.display.Loader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Shape;
import flash.display.Sprite;
//----------------------------------- 300x250 Start ---------------------------------\\
//SWF Load and URL Request
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("_/media/300x250.swf");
//Function for Replay
function loadSWF():void {
//Add URL to Load Object
myLoader.load(url);
//Index 0
addChild(myLoader);
//Loader Cordinates
myLoader.x = 803;
myLoader.y = 331;
}
// Mask for Load Object 300x250
var maskSWF:Shape = new Shape();
maskSWF.graphics.lineStyle();
maskSWF.graphics.beginFill(0x0);
maskSWF.graphics.drawRect(803, 331, 300, 250);
maskSWF.graphics.endFill();
this.addChild(maskSWF);
myLoader.mask = maskSWF;
//----------------------------------- 300x250 End ---------------------------------\\
//----------------------------------- Video Start ---------------------------------\\
//Video Player Load and URL Request
var myLoaderVidPlay:Loader = new Loader();
var urlVidPlay:URLRequest = new URLRequest("_/media/vid_player.swf");
//Timer Function to Play Video Player UI
function timerListenerVidPlay (e:TimerEvent):void{
//Add URL to Load Object
myLoaderVidPlay.load(urlVidPlay);
//Index 1
addChild(myLoaderVidPlay);
//Loader Cordinates
myLoaderVidPlay.x = 803;
myLoaderVidPlay.y = 331;
}
//New Timer Object Video Background
var myTimerVidPlay:Timer = new Timer(1400,1);
myTimerVidPlay.addEventListener(TimerEvent.TIMER, timerListenerVidPlay);
//Creating NetConnection object - Set to null when local folder
var nc:NetConnection = new NetConnection();
nc.connect(null);
//New NetStream
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
function asyncErrorHandler(event:AsyncErrorEvent):void
{
// ignore error
}
//New Video Object
var vid:Video = new Video();
//Timer Function to Play Vid
function timerListenerVid (e:TimerEvent):void{
//Index 2
ns.play("./_/media/vid.flv");
vid.attachNetStream(ns);
addChild(vid);
vid.x = 818;
vid.y = 345;
vid.width = 271;
vid.height = 153;
}
//New Timer Object Video
var myTimerVid:Timer = new Timer(1500,1);
myTimerVid.addEventListener(TimerEvent.TIMER, timerListenerVid);
//------------------------------------ Video End ---------------------------------\\
//----------------------------------- Replay Start ---------------------------------\\
//Removes and Reloads SWFs for Replay
replay.addEventListener(MouseEvent.CLICK, replayClickHandler);
//Replay Advertisement
function replayClickHandler(event:MouseEvent):void
{
myLoader.unload();
myLoaderVidPlay.unload();
myTimerVidPlay.stop();
//Closes Video Stream
ns.close();
loadSWF();
myTimerVidPlay.start();
myTimerVid.start();
}
//----------------------------------- Replay End ---------------------------------\\
//----------------------------------- Close Video Start ---------------------------------\\
var closeVid:Sprite = new Sprite();
closeVid.graphics.beginFill(0xFF0000, .5);
closeVid.graphics.drawRect(703, 331, 300,250);
closeVid.graphics.endFill();
//Index 3
addChild(closeVid);
//trace(getChildIndex(this.closeVid));
//Adds hand cursor
closeVid.useHandCursor = true;
closeVid.buttonMode = true;
closeVid.addEventListener(MouseEvent.CLICK, myClickCloseVid);
function myClickCloseVid (e:MouseEvent):void{
myTimerVidPlay.stop();
myLoaderVidPlay.unload();
//Closes Video Stream
ns.close();
removeChild(vid);
}
//----------------------------------- Close Video End ---------------------------------\\
//Start Functions
loadSWF();
myTimerVid.start();
myTimerVidPlay.start();
答案 0 :(得分:0)
你正在调用addChild(closeVid);在调用addChild(myLoader);
之前调用addChild(closeVid);在调用loadSWF()之后;它调用addChild(myLoader);
这是解决问题的方法。
现在,loadSWF?这是什么名字?它具有误导性,后来(月,年)你需要检查功能体,了解它的作用。
addChild在函数中也是一个坏主意 - 为什么?这是你的问题的根源:)这个功能不只是将一个孩子添加到一个应该保持独立的显示列表。