Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can i create a function to tell a button to open a movie clip of the same name

New Here ,
Feb 05, 2015 Feb 05, 2015

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.

TOPICS
ActionScript
406
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 05, 2015 Feb 05, 2015

:


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;

}

Translate
Community Expert ,
Feb 05, 2015 Feb 05, 2015

:


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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2015 Feb 06, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2015 Feb 06, 2015

oops, that should be:

for(i=0;i<buttonA.length;i++){

buttonA.addEventListener(MouseEvent.CLICK,buttonF);

tl[buttonA.name.split("_")[0]+"_movie"].visible = false;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2015 Feb 06, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2015 Feb 06, 2015

this line:


tl[e.currentTarget.split("_")[0]+"_movie"].visible=true;


should be:


tl[e.currentTarget.name.split("_")[0]+"_movie"].visible=true;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2015 Feb 06, 2015

perfect , thank you so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2015 Feb 06, 2015
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines