Skip to main content
Known Participant
November 19, 2013
Question

How can I simplify the code in this situation?

  • November 19, 2013
  • 1 reply
  • 2348 views

I want to create some interaction about ABCDEFGHIJKLM objects. If I l click A and B, the screen will show F. If I click A and C, it will show G.  If I click A and D. it will show F..etc.  When I mouseove A , it will show only L. If I mouseover B, it will show M only. In this situation, I need to create each eventListener (MouseoverA MouseOverB CLICK A, CLICK B, bothAandBClick, bothAandCClick, bothAandDclick......) Can I use other method to simplify the code?

import flash.display.MovieClip;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.ui.Mouse;

var redbtn:MovieClip=new Redbtn();

redbtn.x=321;

redbtn.y=13;

addChild(redbtn);

var yellowbtn:MovieClip=new Yellowbtn();

yellowbtn.x=130;

yellowbtn.y=106;

addChild(yellowbtn);

var bluebtn:MovieClip=new Bluebtn();

bluebtn.x=726;

bluebtn.y=89;

addChild(bluebtn);

var blackbtn:MovieClip=new Blackbtn();

blackbtn.x=236;

blackbtn.y=479;

addChild(blackbtn);

var greenbtn:MovieClip=new Greenbtn();

greenbtn.x=590;

greenbtn.y=457;

addChild(greenbtn);

var page1:MovieClip=new relationship();

var redBtnClicked:Boolean;

var blueBtnClicked:Boolean;

redbtn.addEventListener(MouseEvent.CLICK, onRedBtnClick);

redbtn.addEventListener(MouseEvent.ROLL_OVER, onRedOver);

redbtn.addEventListener(MouseEvent.ROLL_OUT, onRedOut);

bluebtn.addEventListener(MouseEvent.CLICK, onBlueClick);

bluebtn.addEventListener(MouseEvent.MOUSE_OVER, onBlueOver);

function onRedOver(evt:MouseEvent):void{

          trace("redover");

          redbtn.gotoAndStop(2);

}

function onRedOut(evt:MouseEvent):void{

          trace("redout");

          redbtn.gotoAndStop(3);

}

function onBlueOver(evt:MouseEvent):void{

          trace("blueover");

}

function onRedBtnClick(evt:MouseEvent):void{

          redBtnClicked=true;

          bothClickedF();

}

function onBlueClick(evt:MouseEvent):void{

          blueBtnClicked=true;

          bothClickedF();

}

function bothClickedF():void{

          if (blueBtnClicked&& redBtnClicked){

                    trace("two buttons are clicked");

                    addChild(page1);

                    redBtnClicked=false;

                    blueBtnClicked=false;

                    }

}

page1.trailer_sex.addEventListener(MouseEvent.CLICK, page1Click);

function page1Click(evt:MouseEvent):void{

   removeChild(page1);

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
November 19, 2013

is there a time limit between the A and B clicks that trigger F to appear?

what happens if you click A and M?  B and C?

what happens if you mouseover C?

i assume F,..,M are not visible to start.

Known Participant
November 19, 2013

I means  this

Click

A and B  go to C

A and D go to E

A and F go to G

A and I go to J

A and N go to O

B and D go to K

B and F go to L

B and I go to M

B and N go to P

F and I go to Q

F and N go to R

MouseOver

A  over then appear S

B  over then appear T

D  over then appear U

F  over then appear V

I  over then appear W

N  over then appear V

There is not time limit.

kglad
Community Expert
Community Expert
November 19, 2013

i dont' see a consistant pattern.