我坚持你的代码(没有类,方法,成员,addChild,......)。我没有使用 Flash 或 SDK 尝试最终草案。
我假设你有:
- 3 个影片剪辑对象:
enlyrvult
, itlyrvult
, mtlyrvult
;
- 3 InteractiveObject (SimpleButton, MovieClip, ...) 对象:
engvult
, itvult
, mtvult
;
- 当我们从这里开始时,它
enlyrvult
正在播放(如果不是:enlyrvult.play();
或enlyrvult.stop();
)。
itlyrvult.stop(); // or itlyrvult.gotoAndStop(1);
mtlyrvult.stop(); // or mtlyrvult.gotoAndStop(1);
engvult.addEventListener(MouseEvent.CLICK, playMC1);
itvult.addEventListener(MouseEvent.CLICK, playMC2);
mtvult.addEventListener(MouseEvent.CLICK, playMC3);
// play enlyrvult
function playMC1(e:MouseEvent):void {
// stop them
itlyrvult.stop();
mtlyrvult.stop();
// play me
enlyrvult.gotoAndPlay(mtlyrvult.currentFrame);
// hide them
itlyrvult.gotoAndStop(1); //frame one is empty
mtlyrvult.gotoAndStop(1); //frame one is empty
// My trigger is out, theirs are fine
engvult.mouseEnabled = false;
itvult.mouseEnabled = true;
mtvult.mouseEnabled = true;
}
// play itlyrvult
function playMC2(e:MouseEvent):void {
// stop them
enlyrvult.stop();
mtlyrvult.stop();
// play me
itlyrvult.gotoAndPlay(enlyrvult.currentFrame);
// hide them
enlyrvult.gotoAndStop(1); //frame one is empty
mtlyrvult.gotoAndStop(1); //frame one is empty
// My trigger is out, theirs are fine
itvult.mouseEnabled = false;
engvult.mouseEnabled = true;
mtvult.mouseEnabled = true;
}
// play mtlyrvult
function playMC3(e:MouseEvent):void {
// stop them
enlyrvult.stop();
itlyrvult.stop();
// play me
mtlyrvult.gotoAndPlay(itlyrvult.currentFrame);
// hide them
enlyrvult.gotoAndStop(1); //frame one is empty
itlyrvult.gotoAndStop(1); //frame one is empty
// My trigger is out, theirs are fine
mtvult.mouseEnabled = false;
engvult.mouseEnabled = true;
itvult.mouseEnabled = true;
}
或者,你想要多少(300?)...
// add to your import:
import flash.utils.Dictionary;
// in your const/var section
const STARTING_FRAME:int = 1;
var dict = new Dictionary(); // mapping and memory
var currentTrack:MovieClip; // we will know who's last
initAll();
playTrack(enlyrvult, STARTING_FRAME, engvult);
function clickHandler(e:MouseEvent):void {
var playheadFrame:int = currentTrack.currentFrame; // we remember position
var trigger:InteractiveObject = (e.currentTarget as InteractiveObject); // who shot me ?
var nextTrack:MovieClip = (dict[trigger] as MovieClip); // who's next ?
resetAll(); // and again.. (http://en.wikipedia.org/wiki/Sisyphus)
playTrack(nextTrack, playheadFrame, trigger);
}
function playTrack(mc:MovieClip, fram:int, iObj:InteractiveObject):void {
currentTrack = mc;
currentTrack.gotoAndPlay(fram);
iObj.mouseEnabled = false;
}
function resetAll():void {
for (var key:InteractiveObject in dict) { key.mouseEnabled = true; }
for each (var value:MovieClip in dict) { value.gotoAndStop(1); } // diff-> each
}
function initAll():void {
dict[engvult] = enlyrvult;
dict[itvult] = itlyrvult;
dict[mtvult] = mtlyrvult;
//dict[avult] = alyrvult; //<- new one like this: dict[trigger]=lyrMC; add as much as you can!
for (var key:InteractiveObject in dict) {
key.addEventListener(MouseEvent.CLICK, clickHandler);
}
resetAll();
}