flash ActionScript

  • tehila10
  • Born
  • Born
  • tehila10
  • Posts: 1

Post 3+ Months Ago

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

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);
  1. import flash.events.MouseEvent;
  2.  
  3. var handleRollOut = function(event:MouseEvent):void {}
  4. removeEventListener (MouseEvent.ROLL_OUT, handleRollOut);
  5. button.addEventListener (MouseEvent.CLICK, handleClick);
  6. play();
  7. };
  8.  
  9. var handleClick = function(event:MouseEvent):void {}
  10. button.removeEventListener (MouseEvent.CLICK, handleClick);
  11. addEventListener (MouseEvent.ROLL_OUT, handleRollOut);
  12. play();
  13. };
  14.  
  15. button.addEventListener (MouseEvent.CLICK, handleClick);
  16.  
  17.  
  18. stop();
  19.  
  20. Then somewhere else, jai
  21.  
  22.  
  23. stop();
  24.  
  25. var handleClickButton1 = function(event:MouseEvent):void {}
  26. trace ("handleClickButton1");
  27. };
  28. var handleClickButton2 = function(event:MouseEvent):void {}
  29. trace ("handleClickButton2");
  30. };
  31. var handleClickButton3 = function(event:MouseEvent):void {}
  32. trace ("handleClickButton3");
  33. };
  34.  
  35. If (! button_1.hasEventListener (MouseEvent.CLICK)) button_1.addEventListener (MouseEvent.CLICK, handleClickButton1);
  36. If (! button_2.hasEventListener (MouseEvent.CLICK)) button_2.addEventListener (MouseEvent.CLICK, handleClickButton2);
  37. If (! button_3.hasEventListener (MouseEvent.CLICK)) button_3.addEventListener (MouseEvent.CLICK, handleClickButton3);



Thank you!!
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

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.

ACTIONSCRIPT Code: [ Select ]
var handleClickButton1 = function(event:MouseEvent):void {}
 
  1. var handleClickButton1 = function(event:MouseEvent):void {}
  2.  


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();
 
  1. import flash.events.MouseEvent;
  2.  
  3. // Make your mouse functions
  4. var handleClick = function(event:MouseEvent):void {
  5.     trace ("handleClickButton");
  6. };
  7.  
  8. var handleRollOut = function(event:MouseEvent):void {
  9.     trace ("handleRollOutButton");
  10.    
  11.     // Change the cursor
  12.     Mouse.cursor = 'auto';
  13.      
  14.     // Goto the normal state
  15.     event.currentTarget.gotoAndStop(1);
  16.      
  17. };
  18.  
  19. var handleRollOver = function(event:MouseEvent):void {
  20.     trace ("handleRollOverButton");
  21.    
  22.     // Change the cursor
  23.     Mouse.cursor = 'button';
  24.    
  25.     // Goto the over state
  26.     event.currentTarget.gotoAndStop(2);
  27.  
  28. };
  29.  
  30. var handleClickButton1 = function(event:MouseEvent):void {
  31.     trace ("handleClickButton1");
  32. };
  33.  
  34. var handleClickButton2 = function(event:MouseEvent):void {
  35.     trace ("handleClickButton2");
  36. };
  37.  
  38. var handleClickButton3 = function(event:MouseEvent):void {
  39.     trace ("handleClickButton3");
  40. };
  41.  
  42. // Make the event listeners for the buttons
  43. button.addEventListener(MouseEvent.CLICK, handleClick);
  44. button.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
  45. button.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
  46. button_1.addEventListener(MouseEvent.CLICK, handleClickButton1);
  47. button_1.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
  48. button_1.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
  49. button_2.addEventListener(MouseEvent.CLICK, handleClickButton2);
  50. button_2.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
  51. button_2.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
  52. button_3.addEventListener(MouseEvent.CLICK, handleClickButton3);
  53. button_3.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
  54. button_3.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
  55.  
  56. stop();
  57.  


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:
test3.zip

(13.59 KiB) Downloaded 122 times

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 8 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.