Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-29-2012, 01:25 PM   #1
krakatoa
Registered User
 
Join Date: Mar 2012
Posts: 18
Default AS2 to AS3 help

Hello guys,

I trying to convert the code below(AS2) to AS3. I guessing the onRollOver funtion (fade in and fade out) in AS3 is:

ActionScript Code:
button.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true); button.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);   function manageMouseOver(event:MouseEvent):void{   //your over code here }   function manageMouseOut(event:MouseEvent):void{   //your out code here }

If yes any idea if I need to change something in the funtions fadeIn and fadeOut?

AS2:

ActionScript Code:
/*Buttons Effect code */ function fadeIn (bgClip) {     bgClip.onEnterFrame = function ()     {         if (this._alpha < 100)         {             this._alpha += 20;         }     }; } function fadeOut (bgClip) {     bgClip.onEnterFrame = function ()     {         if (this._alpha > 0)         {             this._alpha -= 20;         }     }; } home_btn.onRollOver = function () {     fadeIn (red); }; home_btn.onRollOut = function () {     fadeOut (red); }; about_btn.onRollOver = function () {     fadeIn (red2); }; about_btn.onRollOut = function () {     fadeOut (red2); }; products_btn.onRollOver = function () {     fadeIn (red3); }; products_btn.onRollOut = function () {     fadeOut (red3); }; services_btn.onRollOver = function () {     fadeIn (red4); }; services_btn.onRollOut = function () {     fadeOut (red4); }; videos_btn.onRollOver = function () {     fadeIn (red5); }; videos_btn.onRollOut = function () {     fadeOut (red5); }; contact_btn.onRollOver = function () {     fadeIn (red6); }; contact_btn.onRollOut = function () {     fadeOut (red6); };



Thanks in advance.
krakatoa is offline   Reply With Quote
Old 03-29-2012, 01:44 PM   #2
dmb85
Senior Member
 
Join Date: Jan 2012
Posts: 608
Default

  • Remove underscores from property names (_alpha becomes alpha)
  • Properties that used to go from 0 to 100 now go from 0 to 1
  • onEnterFrame needs to be an event listener like the MouseEvents: addEventListener( Event.ENTER_FRAME, functionName )
dmb85 is offline   Reply With Quote
Old 03-29-2012, 02:37 PM   #3
krakatoa
Registered User
 
Join Date: Mar 2012
Posts: 18
Default

I tried that look:

ActionScript Code:
/*Buttons Effect code */ addEventListener(Event.ENTER_FRAME, fadeIn); function fadeIn(event:Event) { if (this.alpha < 1)      {       this.alpha += .20;      } } home_btn.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);   function manageMouseOver(event:MouseEvent):void{   fadeIn (red); }


But i get the error:

Scene 1, Layer 'Actions', Frame 1, Line 26 1067: Implicit coercion of a value of type flash.display:MovieClip to an unrelated type flash.events:Event.
krakatoa is offline   Reply With Quote
Old 03-29-2012, 02:43 PM   #4
dmb85
Senior Member
 
Join Date: Jan 2012
Posts: 608
Default

Your fadeIn function needs modification:

ActionScript Code:
function fadeIn(mc:MovieClip) { if (mc.alpha < 1)      {       mc.alpha += .20;      } }
dmb85 is offline   Reply With Quote
Old 03-29-2012, 03:33 PM   #5
krakatoa
Registered User
 
Join Date: Mar 2012
Posts: 18
Default

So'll be something like:

ActionScript Code:
/*Buttons Effect code */ addEventListener(Event.ENTER_FRAME, fadeIn); function fadeIn(mc:MovieClip) { if (mc.alpha < 1)     {                mc.alpha += .20;     } } home_btn.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);   function manageMouseOver(event:MouseEvent):void{   fadeIn (red); }


cause this time I have this output:

ActionScript Code:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@3a542511 to flash.display.MovieClip.

I tried this:

import flash.display.MovieClip; in the second line, but nothing
krakatoa is offline   Reply With Quote
Old 03-29-2012, 04:03 PM   #6
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,886
Send a message via Skype™ to henke37
Default

Please go and learn about type safety. You are getting incorrect advice and are unable to tell the difference between bad and good advice.

Event listeners have exactly one argument, the event object. This is not the object that the event happened to, it is the object representing the event itself.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 03-29-2012, 04:05 PM   #7
dmb85
Senior Member
 
Join Date: Jan 2012
Posts: 608
Default

Ok sorry I only skimmed your code the first time and didn't fully comprehend what you were trying to do. Undo what I said in my last post.

Your problem is that you've written the fadeIn function to be something called by an event listener, but then you try to call fadeIn here:

ActionScript Code:
function manageMouseOver(event:MouseEvent):void{   fadeIn (red); }

You cant do this since you've defined fadeIn to receive an Event object, not a movieclip object. One way to fix it is to change it so that manageMouseOVer only adds/removes the ENTER_FRAME event listener.

With that said...

What you are trying to do would be better accomplished with a tweening engine like GreenSock TweenLite.
dmb85 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:28 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.