2009-06-04 81 views
1

我想將一個視頻對象放在一個movieClip實例(「mc」)上面,但在另一個movieClip實例(「mc_top」)下面。如何控制Flash視頻的深度(圖層位置)?

我通過將「New Video ...」從庫中拖到舞臺上,併爲其指定實例名稱「flashVid」來實例化_root.flashVid對象。

我創建mc,然後繪製一個藍色框,然後創建mc_top並繪製一個黃色框。 flashVid實例從一開始就位於舞臺(_root)上。現在我如何獲得「mc」以上但「mc_top」以下的flashVid?

// Create movieclips and paint boxes. 
var mc:MovieClip = _root.createEmptyMovieClip("test", 
               _root.getNextHighestDepth()); 

mc.beginFill(0x0000ff, 50); 
mc.lineStyle(2, 0x0000ff, 100); 
mc.moveTo(0,0); 
mc.lineTo(400, 0); 
mc.lineTo(400,400); 
mc.lineTo(0,400); 
mc.lineTo(0,0); 
mc.endFill(); 

var mc_top:MovieClip = mc.createEmptyMovieClip("test_top", 
               mc.getNextHighestDepth()); 
mc_top._x = 200; 
mc_top.beginFill(0xffff00, 50); 
mc_top.lineStyle(2, 0xffff00, 100); 
mc_top.moveTo(0,0); 
mc_top.lineTo(400, 0); 
mc_top.lineTo(400,400); 
mc_top.lineTo(0,400); 
mc_top.lineTo(0,0); 
mc_top.endFill(); 

// Flash video code (using Video object on stage, no components) 
var nc = new NetConnection(); 
nc.connect(null); 
var ns = new NetStream(nc); 
ns.play("http://dl.getdropbox.com/u/295386/Stormpulse/my.flv"); 

// Tell flashVid to play what's coming through the netstream. 
_root.flashVid.attachVideo(ns); 

回答

0

這個答案是從大衛·斯蒂勒的quip.net

在AS2中,視頻類不提供任何深度相關的屬性 或moethods(此對比,例如,與MovieClip。 swapDepths() 方法)。因此,如果您想用AS2, 更改視頻的深度,則必須將視頻對象包裝到影片剪輯中。您必須 爲該包裝影片剪輯指定一個實例名稱,因此您可以使用swapDepths()更改其深度 。這也會改變您對attachVideo()方法的參考。

例如

// instead of this ... 
_root.flashVid.attachVideo(ns); 

// ... you'll have to use this ... 
_root.wrapperMC.flashVid.attachVideo(ns); 

...其中「wrapperMC」代表任何實例名稱你給了 包裝影片剪輯。那有意義嗎?

另外要注意的是 手拖到舞臺上那部電影剪輯始終較低,縱深,比 的attachMovie()或createEmptyMovieClip()連接到舞臺的電影剪輯。所以一定要用代碼將它們全部附在 上,或者用手將它們全部拖到舞臺上。否則,您必須通過首先使用swapDepths()將 「手動」將手動拖動的影片剪輯壓入 附加/創建的剪輯的較高深度。

// Declare a reusable variable to manage the 
// attachment of three movie clips 

// Here's the first usage (note the depth of 3) 
var mc:MovieClip = this.attachMovie("contentAbove", "upperSquare", 3); 

// Here's the second (the video wrapper, depth of 2) 
mc = this.attachMovie("wrapper", "videoWrapper", 2); 
// move this one down a tad 
mc._y = 80; 

// Here's the third (depth of 2) 
mc = this.attachMovie("contentBelow", "lowerSquare", 1); 
// move this one down even more 
mc._y = 160; 

// Now wire up the video 
var nc:NetConnection = new NetConnection(); 
nc.connect(null); 
var ns:NetStream = new NetStream(nc); 
videoWrapper.flashVid.attachVideo(ns); 
ns.play("http://dl.getdropbox.com/u/295386/Stormpulse/my.flv"); 
0

較短的做法是

MovieClip.prototype.swapDepths.call(_root.flashVid,_root.getNextHighestDepth()); 

一般解決問題,試試這個代碼:視頻

Video.prototype.swapDepths = MovieClip.prototype.swapDepths; 
Video.prototype.getDepth = MovieClip.prototype.getDepth; 

事後情況下將有兩種方法可... 在變量上沒有編譯錯誤嚴格鍵入到視頻,您將需要更新您的內部函數(在flash IDE通道 - 在你的硬盤只是搜索Video.as,你應該從找到他們......然後同時複製swapDepths則的聲明getDepth MovieClip.asVideo.as)...

我不會詳細解釋。你應該看看在類功能呼叫方法和了解原型在AS和AS2(和JS和AS3一點)是如何工作的?

格爾茨

back2dos

1

所有你需要做的就是把視頻放在一個空的movieclip中(如上面所建議的那樣),並在深度方面操縱該movieclip。很簡單。