flash ActionScript
- tehila10
- Born


- Joined: Oct 30, 2012
- Posts: 1
- Status: Offline
Hello, I a flash script to which I do not understand great since it is written with AS3 I guess, and I know rather AS2. Someone could it help me?
Thank you
Thank you!!
Thank you
ACTIONSCRIPT Code: [ Select ]
import flash.events.MouseEvent;
var handleRollOut = function(event:MouseEvent):void {}
removeEventListener (MouseEvent.ROLL_OUT, handleRollOut);
button.addEventListener (MouseEvent.CLICK, handleClick);
play();
};
var handleClick = function(event:MouseEvent):void {}
button.removeEventListener (MouseEvent.CLICK, handleClick);
addEventListener (MouseEvent.ROLL_OUT, handleRollOut);
play();
};
button.addEventListener (MouseEvent.CLICK, handleClick);
stop();
Then somewhere else, jai
stop();
var handleClickButton1 = function(event:MouseEvent):void {}
trace ("handleClickButton1");
};
var handleClickButton2 = function(event:MouseEvent):void {}
trace ("handleClickButton2");
};
var handleClickButton3 = function(event:MouseEvent):void {}
trace ("handleClickButton3");
};
If (! button_1.hasEventListener (MouseEvent.CLICK)) button_1.addEventListener (MouseEvent.CLICK, handleClickButton1);
If (! button_2.hasEventListener (MouseEvent.CLICK)) button_2.addEventListener (MouseEvent.CLICK, handleClickButton2);
If (! button_3.hasEventListener (MouseEvent.CLICK)) button_3.addEventListener (MouseEvent.CLICK, handleClickButton3);
var handleRollOut = function(event:MouseEvent):void {}
removeEventListener (MouseEvent.ROLL_OUT, handleRollOut);
button.addEventListener (MouseEvent.CLICK, handleClick);
play();
};
var handleClick = function(event:MouseEvent):void {}
button.removeEventListener (MouseEvent.CLICK, handleClick);
addEventListener (MouseEvent.ROLL_OUT, handleRollOut);
play();
};
button.addEventListener (MouseEvent.CLICK, handleClick);
stop();
Then somewhere else, jai
stop();
var handleClickButton1 = function(event:MouseEvent):void {}
trace ("handleClickButton1");
};
var handleClickButton2 = function(event:MouseEvent):void {}
trace ("handleClickButton2");
};
var handleClickButton3 = function(event:MouseEvent):void {}
trace ("handleClickButton3");
};
If (! button_1.hasEventListener (MouseEvent.CLICK)) button_1.addEventListener (MouseEvent.CLICK, handleClickButton1);
If (! button_2.hasEventListener (MouseEvent.CLICK)) button_2.addEventListener (MouseEvent.CLICK, handleClickButton2);
If (! button_3.hasEventListener (MouseEvent.CLICK)) button_3.addEventListener (MouseEvent.CLICK, handleClickButton3);
- import flash.events.MouseEvent;
- var handleRollOut = function(event:MouseEvent):void {}
- removeEventListener (MouseEvent.ROLL_OUT, handleRollOut);
- button.addEventListener (MouseEvent.CLICK, handleClick);
- play();
- };
- var handleClick = function(event:MouseEvent):void {}
- button.removeEventListener (MouseEvent.CLICK, handleClick);
- addEventListener (MouseEvent.ROLL_OUT, handleRollOut);
- play();
- };
- button.addEventListener (MouseEvent.CLICK, handleClick);
- stop();
- Then somewhere else, jai
- stop();
- var handleClickButton1 = function(event:MouseEvent):void {}
- trace ("handleClickButton1");
- };
- var handleClickButton2 = function(event:MouseEvent):void {}
- trace ("handleClickButton2");
- };
- var handleClickButton3 = function(event:MouseEvent):void {}
- trace ("handleClickButton3");
- };
- If (! button_1.hasEventListener (MouseEvent.CLICK)) button_1.addEventListener (MouseEvent.CLICK, handleClickButton1);
- If (! button_2.hasEventListener (MouseEvent.CLICK)) button_2.addEventListener (MouseEvent.CLICK, handleClickButton2);
- If (! button_3.hasEventListener (MouseEvent.CLICK)) button_3.addEventListener (MouseEvent.CLICK, handleClickButton3);
Thank you!!
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
October 30th, 2012, 4:21 am
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
OK ... So if you haven't figured it out by now your your code is broken.
So it looks like you want button rollover/rollout and click functions on different buttons. I for one see a lot of thing that are not needed to be done. like removing and re adding the event listeners. Also that the functions needed to run the button interactions are being closed ... well immediately making your buttons not work at all and should be throwing errors.
To make this snippet work do the following
If you notice I've also added the rollOver and considering that the rollOver and rollOut states in my example do the exact same thing there is no need to make a function for each button rather they can share the function. Within the event variable you can use event.currentTarget to get access to the correct movie clip. See the attached file for a working example.
So it looks like you want button rollover/rollout and click functions on different buttons. I for one see a lot of thing that are not needed to be done. like removing and re adding the event listeners. Also that the functions needed to run the button interactions are being closed ... well immediately making your buttons not work at all and should be throwing errors.
ACTIONSCRIPT Code: [ Select ]
var handleClickButton1 = function(event:MouseEvent):void {}
- var handleClickButton1 = function(event:MouseEvent):void {}
To make this snippet work do the following
ACTIONSCRIPT Code: [ Select ]
import flash.events.MouseEvent;
// Make your mouse functions
var handleClick = function(event:MouseEvent):void {
trace ("handleClickButton");
};
var handleRollOut = function(event:MouseEvent):void {
trace ("handleRollOutButton");
// Change the cursor
Mouse.cursor = 'auto';
// Goto the normal state
event.currentTarget.gotoAndStop(1);
};
var handleRollOver = function(event:MouseEvent):void {
trace ("handleRollOverButton");
// Change the cursor
Mouse.cursor = 'button';
// Goto the over state
event.currentTarget.gotoAndStop(2);
};
var handleClickButton1 = function(event:MouseEvent):void {
trace ("handleClickButton1");
};
var handleClickButton2 = function(event:MouseEvent):void {
trace ("handleClickButton2");
};
var handleClickButton3 = function(event:MouseEvent):void {
trace ("handleClickButton3");
};
// Make the event listeners for the buttons
button.addEventListener(MouseEvent.CLICK, handleClick);
button.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
button_1.addEventListener(MouseEvent.CLICK, handleClickButton1);
button_1.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button_1.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
button_2.addEventListener(MouseEvent.CLICK, handleClickButton2);
button_2.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button_2.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
button_3.addEventListener(MouseEvent.CLICK, handleClickButton3);
button_3.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button_3.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
stop();
// Make your mouse functions
var handleClick = function(event:MouseEvent):void {
trace ("handleClickButton");
};
var handleRollOut = function(event:MouseEvent):void {
trace ("handleRollOutButton");
// Change the cursor
Mouse.cursor = 'auto';
// Goto the normal state
event.currentTarget.gotoAndStop(1);
};
var handleRollOver = function(event:MouseEvent):void {
trace ("handleRollOverButton");
// Change the cursor
Mouse.cursor = 'button';
// Goto the over state
event.currentTarget.gotoAndStop(2);
};
var handleClickButton1 = function(event:MouseEvent):void {
trace ("handleClickButton1");
};
var handleClickButton2 = function(event:MouseEvent):void {
trace ("handleClickButton2");
};
var handleClickButton3 = function(event:MouseEvent):void {
trace ("handleClickButton3");
};
// Make the event listeners for the buttons
button.addEventListener(MouseEvent.CLICK, handleClick);
button.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
button_1.addEventListener(MouseEvent.CLICK, handleClickButton1);
button_1.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button_1.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
button_2.addEventListener(MouseEvent.CLICK, handleClickButton2);
button_2.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button_2.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
button_3.addEventListener(MouseEvent.CLICK, handleClickButton3);
button_3.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
button_3.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
stop();
- import flash.events.MouseEvent;
- // Make your mouse functions
- var handleClick = function(event:MouseEvent):void {
- trace ("handleClickButton");
- };
- var handleRollOut = function(event:MouseEvent):void {
- trace ("handleRollOutButton");
- // Change the cursor
- Mouse.cursor = 'auto';
- // Goto the normal state
- event.currentTarget.gotoAndStop(1);
- };
- var handleRollOver = function(event:MouseEvent):void {
- trace ("handleRollOverButton");
- // Change the cursor
- Mouse.cursor = 'button';
- // Goto the over state
- event.currentTarget.gotoAndStop(2);
- };
- var handleClickButton1 = function(event:MouseEvent):void {
- trace ("handleClickButton1");
- };
- var handleClickButton2 = function(event:MouseEvent):void {
- trace ("handleClickButton2");
- };
- var handleClickButton3 = function(event:MouseEvent):void {
- trace ("handleClickButton3");
- };
- // Make the event listeners for the buttons
- button.addEventListener(MouseEvent.CLICK, handleClick);
- button.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
- button.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
- button_1.addEventListener(MouseEvent.CLICK, handleClickButton1);
- button_1.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
- button_1.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
- button_2.addEventListener(MouseEvent.CLICK, handleClickButton2);
- button_2.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
- button_2.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
- button_3.addEventListener(MouseEvent.CLICK, handleClickButton3);
- button_3.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
- button_3.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
- stop();
If you notice I've also added the rollOver and considering that the rollOver and rollOut states in my example do the exact same thing there is no need to make a function for each button rather they can share the function. Within the event variable you can use event.currentTarget to get access to the correct movie clip. See the attached file for a working example.
Attachments:
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 2 posts
- Users browsing this forum: No registered users and 60 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
