你有兩個問題在這裏,我真的不明白,爲什麼你這樣的工作,但是,
1:當我嘗試編譯你的代碼時,我得到一個編譯時間錯誤:
在Y末尾錯過了一個「}」我們班。
我刪除了什麼不習慣:
package {
import flash.events.MouseEvent;
import flash.display.SimpleButton;
import flash.display.MovieClip;
public class ClickButton extends SimpleButton {
public function ClickButton() {
}
public function GotoSession(sesBut:SimpleButton,frameLabel:String,sceneName:String):void {
sesBut.addEventListener(MouseEvent.CLICK,gotoSes);
function gotoSes(event:MouseEvent):void {
MovieClip(root).gotoAndStop(frameLabel,sceneName);
// and if You want to remove the ClickButton instance :;
// ADD those two lines :
sesBut.removeEventListener(MouseEvent.CLICK,gotoSes);
MovieClip(root).removeChild(sesBut);
// DO NOT forget to remove the Listeners before to remove an instance!
}
}
}
}
我想,你有你的庫按鈕鏈接到ClickButton類,如下所示:
所以:
var btn1:ClickButton = new ClickButton();
addChild(btn1);
btn1.GotoSession(btn1, "menu", "Home");
stop();
如果我點擊btn1,這會讓我感覺t他在「菜單」標籤處顯示「Home」。
這工作就像一個魅力。
的的FrameLabel「菜單」
:
stop();
trace("currentScene.name = " + this.currentScene.name);
trace("currentFrameLabel = " + this.currentFrameLabel);
/*
OUTPUT :
currentScene.name = Home
currentFrameLabel = menu
*/
[編輯]
如果我設置能見度爲false,然後再以真實的,我也有同樣的問題,如果我想改變阿爾法財產mc_1。 這適用於我的文件:
import flash.display.MovieClip;
stop();
trace("currentScene.name = " + this.currentScene.name);
trace("currentFrameLabel = " + this.currentFrameLabel);
var mc_1:MovieClip = mc_1;
// If I don't add this line, I have the same problem when I set the visibility to true
var mc_2:MovieClip = mask_mc;
var mc_3:MovieClip = red_mc;
// I do the same for mc_2 labeled "mask_mc"
// mc_1 is now always recognized as a MovieClip as mc2.
mc_1.visible = false;
mc_1.visible = true;
// No more problem if I add the line var mc_1:MovieClip = mc_1;
// If I don't do this, I cannot access mc_1 as a MovieClip
mc_1.alpha = 0.5;
mc_1.mask = mc_2;
mc_3.alpha = 0.5;
mc_3.visible = false;
mc_3.visible = true;
mc_3.alpha = 0.9;
// It seems that You have to declare the MC variables before to change the properties
[/編輯]
,但我不明白你行:
//btn1.GotoSession(home, "menu", "Home");
家爲空(您沒有任何參考一個名爲home的ClickButton)......
:)。非常感謝。有用。 – Rajesh
爲你而歡快@Rajesh 我從來沒有在AS3創建過一個場景,所以我現在甚至都沒有創建一個,這對我來說是最困難的。 但我認爲你可以改善你的代碼... – tatactic
所以這就是你想問在http://stackoverflow.com/questions/40603368/accessing-root-from-the-class-in-action-script- 3?現在更清楚了!爲你的問題+1。 – tatactic