Можно ли отследить какая кнопка была нажата последней и в зависимости от этого перейти к определенному кадру. И как одно из условий, если никакая кнопка не была нажата.
Код AS3:
//ButtonContainer.as
package {
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.events.Event;
public class ButtonContainer extends MovieClip {
public var button1:SimpleButton;
public var button2:SimpleButton;
public var button3:SimpleButton;
public var button4:SimpleButton;
private var _index:int = 1;
public function ButtonContainer() {
// constructor code
button1.addEventListener(MouseEvent.CLICK, buttonsHandler);
button2.addEventListener(MouseEvent.CLICK, buttonsHandler);
button3.addEventListener(MouseEvent.CLICK, buttonsHandler);
button4.addEventListener(MouseEvent.CLICK, buttonsHandler);
}
private function buttonsHandler(event:MouseEvent):void{
switch(event.target.name){
case "button1":
this.setChildIndex(this["button1"], this.numChildren-1);
this.setChildIndex(this["button2"], this.numChildren-2);
this.setChildIndex(this["button3"], this.numChildren-3);
this.setChildIndex(this["button4"], this.numChildren-4);
_index = 1;
break;
case "button2":
this.setChildIndex(this["button2"], this.numChildren-1);
this.setChildIndex(this["button1"], this.numChildren-2);
this.setChildIndex(this["button3"], this.numChildren-3);
this.setChildIndex(this["button4"], this.numChildren-4);
_index = 2;
break;
case "button3":
this.setChildIndex(this["button3"], this.numChildren-1);
this.setChildIndex(this["button2"], this.numChildren-2);
this.setChildIndex(this["button1"], this.numChildren-3);
this.setChildIndex(this["button4"], this.numChildren-3);
_index = 3;
break;
case "button4":
this.setChildIndex(this["button4"], this.numChildren-1);
this.setChildIndex(this["button2"], this.numChildren-2);
this.setChildIndex(this["button1"], this.numChildren-3);
this.setChildIndex(this["button3"], this.numChildren-3);
_index = 4;
break;
}
this.dispatchEvent(new Event(Event.CHANGE));
}
public function get index():int{
return _index;
}
}
}
Код AS3:
//MenuItem.as
package {
import flash.display.*;
import flash.events.*;
import flash.external.ExternalInterface;
public class MenuItem extends MovieClip {
public var buttonContainer:ButtonContainer;
public var slogan:MovieClip;
public function MenuItem() {
// constructor code
this.addFrameScript(0, addedFrameScript);
this.addFrameScript(24, addedFrameScript);
this.addFrameScript(50, addedFrameScript);
this.addFrameScript(76, addedFrameScript);
this.addFrameScript(102, addedFrameScript);
buttonContainer.addEventListener(Event.CHANGE, buttonContainerHandler);
gotoAndPlay(2);
// Загрузка в контейнер по умолчанию
slogan.slogan.text = "Мы работаем, чтобы радоваться за Ваш бизнес";
ExternalInterface.available ? ExternalInterface.call("loadHtmlContenet", {catid:1, id:163, Itemid:3}) : null;
}
private function buttonContainerHandler(event:Event):void{
if(event.target is ButtonContainer){
var container:ButtonContainer = event.target as ButtonContainer;
var avalable:Boolean = ExternalInterface.available;
switch(container.index){
case 1:
gotoAndPlay(2);
slogan.slogan.text = "Мы работаем, чтобы радоваться за Ваш бизнес";
avalable ? ExternalInterface.call("loadHtmlContenet", {catid:1, id:163, Itemid:3}) : null;
break;
case 2:
gotoAndPlay(26);
slogan.slogan.text = "Мы работаем, чтобы радоваться за Ваш бизнес";
avalable ? ExternalInterface.call("loadHtmlContenet", {catid:1, id:164, Itemid:3}) : null;
break;
case 3:
gotoAndPlay(52);
slogan.slogan.text = "Мы работаем, чтобы радоваться за Ваш бизнес";
avalable ? ExternalInterface.call("loadHtmlContenet", {catid:1, id:165, Itemid:3}) : null;
break;
case 4:
gotoAndPlay(78);
slogan.slogan.text = "Мы работаем, чтобы радоваться за Ваш бизнес";
avalable ? ExternalInterface.call("loadHtmlContenet", {catid:1, id:166, Itemid:3}) : null;
break;
}
}
}
private function addedFrameScript():void{
stop();
}
}
}