大家好,我是奶綠茶
台灣各家入口網站大多都還只支援 FlashAS2 的素材
在製作時, 會在最上方的圖層上蓋了個透明的 Button 元件
此時下方的其他元素滑鼠事件都會失效,這時可以透過奶綠老師提供的方法
讓物件擁有onRollOver,onRollOut事件
原理:改用 onEnterFrame 不斷的 hitTest 來判斷
圖層:milkmidi_as,筆者的語法,固定加在最上一個圖層即可
轉載請註明出處
SourceCodeDownload
台灣各家入口網站大多都還只支援 FlashAS2 的素材
在製作時, 會在最上方的圖層上蓋了個透明的 Button 元件
此時下方的其他元素滑鼠事件都會失效,這時可以透過奶綠老師提供的方法
讓物件擁有onRollOver,onRollOut事件
原理:改用 onEnterFrame 不斷的 hitTest 來判斷
圖層:milkmidi_as,筆者的語法,固定加在最上一個圖層即可
// milkidi MovieClip protoypte extends
MovieClip.prototype.bannerMode = function(over:Function , out:Function ):Void{
trace("milkmidi bannerMode: "+this);
var isOver:Boolean = false;
this.onEnterFrame = function ():Void {
if( this.hitTest( _root._xmouse, _root._ymouse,false )){
if( !isOver ){
over.apply( this );
isOver = true;
}
}else{
if( isOver ){
isOver = false;
out.apply( this );
}
}
}
}
MovieClip.prototype.play2 = function(pFrame:Number , pSpeedFactor:Number, pCallBack:Function):Void{
var _frame :Number = pFrame || this._totalframes ;
if (this._currentframe == _frame) {
if(pCallBack != undefined) pCallBack.call(_clip);
return;
}
var _emptyMC_ :MovieClip = null;
if (this["_emptyMC_"] == undefined) {
_emptyMC_ = this.createEmptyMovieClip("_emptyMC_", this.getNextHighestDepth());
}else {
_emptyMC_ = this["_emptyMC_"] ;
}
var _clip:MovieClip = this;
_emptyMC_.onEnterFrame = function():Void{
var i:Number = pSpeedFactor || 1;
while (i--) {
if (this._parent._currentframe == _frame){
this.onEnterFrame = null;
this.removeMovieClip();
if(pCallBack != undefined) pCallBack.call(_clip);
break;
} else {
this._parent.nextFrame();
}
}
};
};
MovieClip.prototype.playBack = function(pFrame:Number, pSpeedFactor:Number, pCallBack:Function):Void{
var _frame:Number = (pFrame == undefined) ? 1 : pFrame;
if (this._currentframe == _frame) {
if(pCallBack != undefined) pCallBack.call(_clip);
return;
}
var _emptyMC_:MovieClip
if (this["_emptyMC_"] == undefined) {
_emptyMC_ = this.createEmptyMovieClip("_emptyMC_", this.getNextHighestDepth());
}else {
_emptyMC_ = this["_emptyMC_"] ;
}
var _clip:MovieClip = this;
_emptyMC_.onEnterFrame = function():Void{
var i:Number = pSpeedFactor || 1;
while (i--) {
if (this._parent._currentframe == _frame){
this.onEnterFrame = null;
this.removeMovieClip();
if(pCallBack != undefined) pCallBack.call(_clip);
break;
} else {
this._parent.prevFrame();
}
}
};
};
場景上有個 btn 元件btn.onRollOver = function () :Void{
trace("over");
}
btn.onRollOut = function ():Void {
trace("out");
}
// 改用 奶綠茶的寫法
btn.bannerMode(
function ():Void {
trace("bannerMode over");
// 正播到最後一個影格
btn.play2();
},
function ():Void {
trace("bannerMode out");
// 倒播回第一個影格
btn.playBack();
}
);
祝大家學習愉快轉載請註明出處
SourceCodeDownload
留言
我有一個跟這個類似的問題,是用as3寫的
就是我做了一個主選單的影片片段覆蓋整個畫面
因為這樣導致整個底部的按鈕都失效
所以我在最上層做了透明圖層
讓底部圖層變成假背景滑鼠滑過透明圖層會執行下面的假背景
但是這樣又出一個問題
當我把我的主選單滑出時
之前上面的透明圖層會覆蓋到主選單
導致主選單的按鈕無法使用
我有試著寫當主選單滑出時,透明按鈕的監聽會消失,但總是無法成功
請問我該怎麼解決這個問題呢
怕您看不懂我有把我的問題和檔案寄到您的信箱請你看看
感謝你;-)