tags:

views:

285

answers:

3

Hi all! I'm new here, just found these forums on Google.

First of all, I want to appologise if there is some topics like this, but I searched whole forums and didn't find any that finishes my problem.

Now the important one. As I stated in topic title, I need an AS3 code that's doing the thing. This is what I want to accomplish. I have a MC(image) in the center of my screen, and have two buttons, one on right and one on left side of that MC. I want to scroll (image is like a menu) that MC left or right on mouse events, down or over. So, I just want to change MCs X value while holding mouse button on buttons or just hovering over them. I have managed to do that, but it's only moving by one value I have entered after a mouse event. Here's a piece of code I did.

buttonL1_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonL1Pressed);


function buttonL1Pressed(event:MouseEvent):void{

var temp:int = 0;
var temp1:int = 0;
temp = paleta1_mc.x;
temp1 = temp - 5;
paleta1_mc.x = temp1;
trace(temp1);


}

I hope you understood me, and have a clue how to help me with this.

Thank you very much in advance!

Cheers, Ivan

A: 

Try this:

var isScrolling = false;

buttonL1_btn.addEventListener(MouseEvent.MOUSE_OVER, function(e){isScrolling =true});
buttonL1_btn.addEventListener(MouseEvent.MOUSE_OUT, function(e){isScrolling =false});
this.addEventListener(Event.ENTER_FRAME,checkAction)

function checkAction(event:Event):void{

  if (isScrolling)
  {
     paleta1_mc.x -=5;
  }

}
Luis
That just did it! Thank you very much on your assistance, Luis!
Ivan
Cool!! Glad I could help.Can you mark the question as answered? Thanks
Luis
I did :) Thanx again!
Ivan
A: 

It looks like you're attaching the event listener to the MOUSE_OVER event instead of MOUSE_DOWN? Since your handler function is called buttonL1Pressed, I assume you want the event to fire when the user clicks the button instead of when the mouse cursor is over it.

Sorry, I'm not entirely clear what you're asking, but that jumped out at me as I was reading your code.

If you can provide a little more detail, I'd be happy to help if I can.

inkedmn
Is it MOUSE_OVER or MOUSE_DOWN is relevant, because I can make an event handler on a button, but can't make that MovieClip moves when I hold the mouse button or hover over it. It just moves 5pxs to the left, but I want to move it until is MOUSE_UP or MOUSE_OUT. You understand now? Sorry if I wasn't clear enough.
Ivan
A: 

Right so i've tried that and it works fine but how do i get it to scoll both ways?

Ashleigh