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

Moving scene to left and right - MOUSE_OVER

New Here ,
Jan 21, 2014 Jan 21, 2014

Hi guys,

i dont work in Flash for a 2 years and i forgot lots of my AS 3.0 knowledge.

What is the most effective way to make my scene moving to left and right?

I start file like this:

- wide movieclip "Scena_mc"

- at left and right side there are movieclips for navigation ("Nav_L_mc" and "Nav_R_mc")

/////////////////////////////////////////////////////////

Nav_L_mc.addEventListener(MouseEvent.MOUSE_OVER, Nav_L_Over);

Nav_L_mc.addEventListener(MouseEvent.ENTER_FRAME, run);

function Nav_L_Over(e:MouseEvent){

          Scena_mc.x += 10;

}

function Nav_R_Over(e:MouseEvent){

          Scena_mc.x -= 10;

}

//////////////////////////////////////////////////////

but how can I do it repeatly as lond as the mouse is over?

Thaks guys a lot

TOPICS
ActionScript
896
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 , Jan 21, 2014 Jan 21, 2014

use:

/////////////////////////////////////////////////////////

Nav_L_mc.addEventListener(MouseEvent.MOUSE_OVER, Nav_L_Over);

Nav_L_mc.addEventListener(MouseEvent.MOUSE_UT, Nav_L_Out);

function Nav_L_Over(e:MouseEvent){

Nav_L_mc.addEventListener(Event.ENTER_FRAME, run);

          Scena_mc.x += 10;

}

function run(e:Event):void{

Scena_mc.x+=10;

//use a boundary check

}

function Nav_L_Out(e:MouseEvent){

        Nav_L_mc.removeEventListener(Event.ENTER_FRAME, run);

}

////////////////////////////////////////////////

...
Translate
Community Expert ,
Jan 21, 2014 Jan 21, 2014

use:

/////////////////////////////////////////////////////////

Nav_L_mc.addEventListener(MouseEvent.MOUSE_OVER, Nav_L_Over);

Nav_L_mc.addEventListener(MouseEvent.MOUSE_UT, Nav_L_Out);

function Nav_L_Over(e:MouseEvent){

Nav_L_mc.addEventListener(Event.ENTER_FRAME, run);

          Scena_mc.x += 10;

}

function run(e:Event):void{

Scena_mc.x+=10;

//use a boundary check

}

function Nav_L_Out(e:MouseEvent){

        Nav_L_mc.removeEventListener(Event.ENTER_FRAME, run);

}

//////////////////////////////////////////////////////

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 ,
Jan 22, 2014 Jan 22, 2014

Thanks a lot! i find similiarly solution yesterday, but it wasnt working... in your code was also error "Access to properties ENTER_FRAME, possibly undefined, through a reference with static type Class." but I googled it and find the bug - ENTER_FRAME is an Event, not MoiuseEvent.

noow it looks like this and its working totaly great:

////////////

Nav_L_mc.addEventListener(MouseEvent.MOUSE_OVER, Nav_L_Over);

Nav_L_mc.addEventListener(MouseEvent.MOUSE_OUT, Nav_L_Out);

function Nav_L_Over(e:MouseEvent){

Nav_L_mc.addEventListener(Event.ENTER_FRAME, run);

          Scena_mc.x += 10;

}

function run(e:Event):void{

Scena_mc.x+=10;

//use a boundary check

}

function Nav_L_Out(e:MouseEvent){

        Nav_L_mc.removeEventListener(Event.ENTER_FRAME, run);

}

////////////////////////////

Thanks a lot!

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 ,
Jan 22, 2014 Jan 22, 2014

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
New Here ,
Jan 22, 2014 Jan 22, 2014

Unexpectedly I'm fighting now with the Bounce Checkers...

do you have some smart solution?

Edit:

I invented this:

/////////////////////////

navL_mc.addEventListener(MouseEvent.MOUSE_OVER, navL_Over);

navL_mc.addEventListener(MouseEvent.MOUSE_OUT, navL_Out);

function navL_Over(e:MouseEvent){

          if(scena_mc.x == 0){

                              scena_mc.x += 0;

                    }

          else if(scena_mc.x <= 0){

                              scena_mc.x += 10;

                              navL_mc.addEventListener(Event.ENTER_FRAME, runL);

                    }

}

function runL(e:Event):void{

          if(scena_mc.x == 0){

                              scena_mc.x += 0;

                    }

          else if(scena_mc.x <= 0){

                              scena_mc.x += 10;

                    }

}

//////////////////////////////////

and it works

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 ,
Jan 22, 2014 Jan 22, 2014

but the movement of the scene is chopped, not smooth do anybody know any solution how to fix it? probably with different way than "scena_mc.x += 10;"

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 ,
Jan 22, 2014 Jan 22, 2014

the boundary check should be in runL and you typically do not want to do an exact position check.

if you don't understand how to implement your boundary check(s), what are the boundaries and what do you want to happen if a boundary is reached?

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 ,
Jan 22, 2014 Jan 22, 2014

I know what are the boundaries, but I dont have lots of sexperience with AS - I dont know lots of possibilities, so I have to invented my own solution in my head and use google, if it is possible

If you can give me "lerarning lesson" abou implementing boundaries, I will by glad to you

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 ,
Jan 22, 2014 Jan 22, 2014

what are the boundaries and what do you want to happen if a boundary is reached?

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 ,
Jan 22, 2014 Jan 22, 2014

of course... teoretically I know how to do it, but I dont know the concrete tags for boundaries and cognations to scene and make the scene stop at the boundaries...

Im sory for my stupidity, Im just an artist learning code because of final exams

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 ,
Jan 22, 2014 Jan 22, 2014

i can't see your app.  i do not know the x value of scena_mc when your app starts and at what value of x scena_mc should stop changing its x value because of a boundary.

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 ,
Jan 22, 2014 Jan 22, 2014

scene_mc start at x = -550... x wide is 2164 px

now I have this and its working...

/////////////////////////////////////////

navL_mc.addEventListener(MouseEvent.MOUSE_OVER, navL_Over);

navL_mc.addEventListener(MouseEvent.MOUSE_OUT, navL_Out);

function navL_Over(e:MouseEvent){

          if(scena_mc.x == 0){

                              scena_mc.x == 0;

 

                    }

          else if(scena_mc.x <= -10){

                              scena_mc.x += 10;

                              navL_mc.addEventListener(Event.ENTER_FRAME, runL);

                    }

}

function runL(e:Event):void{

          if(scena_mc.x == 0){

                              scena_mc.x == 0;

                    }

          else if(scena_mc.x <= -10){

                              scena_mc.x += 10;

                    }

}

function navL_Out(e:MouseEvent){

          navL_mc.removeEventListener(Event.ENTER_FRAME, runL);

}

//

navR_mc.addEventListener(MouseEvent.MOUSE_OVER, navR_Over);

navR_mc.addEventListener(MouseEvent.MOUSE_OUT, navR_Out);

function navR_Over(e:MouseEvent){

          if(scena_mc.x == -1164){

                              scena_mc.x == -1164;

                    }

          else if(scena_mc.x >= -1154){

                              scena_mc.x -= 10;

                              navR_mc.addEventListener(Event.ENTER_FRAME, runR);

                    }

}

function runR(e:Event):void{

          if(scena_mc.x == -1164){

                              scena_mc.x == -1164;

                    }

          else if(scena_mc.x >= -1154){

                              scena_mc.x -= 10;

                    }

}

function navR_Out(e:MouseEvent){

          navR_mc.removeEventListener(Event.ENTER_FRAME, runR);

}

////////////////////////////////////

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 ,
Jan 22, 2014 Jan 22, 2014
LATEST

sounds good.

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