1 [FL]Flash Tutorial Displaying Pictures According to the Cursor Positio Wed Sep 22, 2010 10:58 am
Admin
Admin
1. Create a new flash file (Actionscript 3.0) and save it as src.fla.
2. Create a movie clip and put each one of your picture in a new frame. Set its registration point to the top left and give it an instance name of “pic_mc”.
3. Create an “actions” layer and with its first frame selected open the actions panel.
First add a stop() to the “pic_mc” movie clip to prevent if from looping through its frames and add ROLL_OVER and ROLL_OUT event listeners.view source
print?
4. In the overHandler() function, we add a MOUSE_MOVE event listener that will call the changeFrame() function when the event will be triggered. In the changeFrame() function, we set the current frame of “pic_mc” according to the mouse position on the movie clip.view source
print?
5. In the outHandler() function, we simply remove the MOUSE_MOVE listener.view source
print?
6. Here’s the final code, test your movie to see it in action.view source
print?
]
2. Create a movie clip and put each one of your picture in a new frame. Set its registration point to the top left and give it an instance name of “pic_mc”.
3. Create an “actions” layer and with its first frame selected open the actions panel.
First add a stop() to the “pic_mc” movie clip to prevent if from looping through its frames and add ROLL_OVER and ROLL_OUT event listeners.view source
print?
1 | pic_mc.stop(); |
2 | pic_mc.addEventListener(MouseEvent.ROLL_OVER, overHandler); |
3 | pic_mc.addEventListener(MouseEvent.ROLL_OUT, outHandler); |
4. In the overHandler() function, we add a MOUSE_MOVE event listener that will call the changeFrame() function when the event will be triggered. In the changeFrame() function, we set the current frame of “pic_mc” according to the mouse position on the movie clip.view source
print?
1 | function overHandler(e:Event):void { |
2 | pic_mc.addEventListener(MouseEvent.MOUSE_MOVE,changeFrame); |
3 | } |
4 |
5 | function changeFrame(e:Event):void { |
6 | var frame : uint = Math.ceil(pic_mc.totalFrames * pic_mc.mouseX / pic_mc.width); |
7 | pic_mc.gotoAndStop(frame); |
8 | } |
5. In the outHandler() function, we simply remove the MOUSE_MOVE listener.view source
print?
1 | function outHandler(e:Event):void { |
2 | pic_mc.removeEventListener(MouseEvent.MOUSE_MOVE, changeFrame); |
3 | } |
6. Here’s the final code, test your movie to see it in action.view source
print?
01 | pic_mc.stop(); |
02 | pic_mc.addEventListener(MouseEvent.ROLL_OVER, overHandler); |
03 | pic_mc.addEventListener(MouseEvent.ROLL_OUT, outHandler); |
04 |
05 | function overHandler(e:Event):void { |
06 | pic_mc.addEventListener(MouseEvent.MOUSE_MOVE,changeFrame); |
07 | } |
08 |
09 | function changeFrame(e:Event):void { |
10 | var frame : uint = Math.ceil(pic_mc.totalFrames * pic_mc.mouseX / pic_mc.width); |
11 | pic_mc.gotoAndStop(frame); |
12 | } |
13 |
14 | function outHandler(e:Event):void { |
15 | pic_mc.removeEventListener(MouseEvent.MOUSE_MOVE, changeFrame); |
16 | } |