Copy link to clipboard
Copied
I am new to the actionscript side of flash,
I am working on a map that has say 20 popups(movieclips) and the countries are the buttons, i have just been informed i need to add 60 more.
Below is an example of the code i have been using
english_movie.visible=french_movie.visible=turkish_movie.visible=false
english_btn.addEventListener(MouseEvent.CLICK, englishButtonClick);
french_btn.addEventListener(MouseEvent.CLICK, frenchButtonClick);
turkish_btn.addEventListener(MouseEvent.CLICK, turkishButtonClick)
function englishButtonClick(event:MouseEvent😞void {
english_movie.visible=true;
english_movie.play();
french_movie.visible=turkish_movie.visible=false }
function frenchButtonClick(event:MouseEvent😞void {
french_movie.visible=true;
french_movie.play();
english_movie.visible=turkish_movie.visible=false }
function turkishButtonClick(event:MouseEvent😞void {
turkish_movie.visible=true;
turkish_movie.play();
english_movie.visible=french_movie.visible=false }
Im thinking there must be an easier way to do this than replicating the code over and over.
Any help would be much appreciated.
:
var tl:MovieClip=this;
var mc:MovieClip;
var i:int;
var buttonA:Array=[english_btn,french_btn,turkish_btn,...];
for(i=0;i<buttonA.length;i++){
buttonA.addEventListener(MouseEvent.CLICK,buttonF);
tl[buttonA.name.split("_")[0]+"_movie"].visible = false;
}
function buttonF(e:MouseEvent):void{for(i=0;i<buttonA.length;i++){
tl[buttonA.name.split("_")[0]+"_movie"].visible = false;
}
tl[e.currentTarget.name.split("_")[0]+"_movie"].visible=true;
}
Copy link to clipboard
Copied
:
var tl:MovieClip=this;
var mc:MovieClip;
var i:int;
var buttonA:Array=[english_btn,french_btn,turkish_btn,...];
for(i=0;i<buttonA.length;i++){
buttonA.addEventListener(MouseEvent.CLICK,buttonF);
tl[buttonA.name.split("_")[0]+"_movie"].visible = false;
}
function buttonF(e:MouseEvent):void{for(i=0;i<buttonA.length;i++){
tl[buttonA.name.split("_")[0]+"_movie"].visible = false;
}
tl[e.currentTarget.name.split("_")[0]+"_movie"].visible=true;
}
Copy link to clipboard
Copied
Hi thank you so much for taking your time to help me with this , im getting an error
TypeError: Error #1006: addEventListener is not a function.
Copy link to clipboard
Copied
oops, that should be:
for(i=0;i<buttonA.length;i++){
buttonA.addEventListener(MouseEvent.CLICK,buttonF);
tl[buttonA.name.split("_")[0]+"_movie"].visible = false;
}
Copy link to clipboard
Copied
Thanks for replying im afraid its something else now.
on a click of one of the buttons i get ;
ReferenceError: Error #1069: Property split not found on flash.display.SimpleButton and there is no default value.
Copy link to clipboard
Copied
this line:
tl[e.currentTarget.split("_")[0]+"_movie"].visible=true;
should be:
tl[e.currentTarget.name.split("_")[0]+"_movie"].visible=true;
Copy link to clipboard
Copied
perfect , thank you so much
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now