Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-07-2008, 03:26 PM   #1
giloosh
Registered User
 
Join Date: Feb 2008
Posts: 1
Default MovieClip.prototype.fadeIn in AS3?

Please help me adjust this code to work in Actionscript 3.0
PHP Code:
MovieClip.prototype.fadeIn = function(){
    
mcImg.onEnterFrame = function(){
        
this._alpha +=6;
        if(
this._alpha 99){
            
this._alpha 100;
            
delete this.onEnterFrame;
        }
    };
}; 
giloosh is offline   Reply With Quote
Old 02-07-2008, 10:10 PM   #2
Slowburn
[Invent:Design:Create]
 
Join Date: Sep 2002
Location: Toronto, ON
Posts: 1,966
Default

ActionScript Code:
package {      public class FaderClip extends MovieClip     {                 public function FaderClip():void         {             super();         }                 public function fadeIn():void         {             // make sure we are hidden first             this.alpha = 0;             // start fadeing In             addEventListener( Event.ENTER_FRAME, onFadeIn, false, 0, true );         }                 public function onFadeOut():void         {             this.alpha = 1;             addEventListener( Event.ENTER_FRAME, onFadeOut, false, 0, true );         }                 public function onFadeIn( objEvent:Event ):void         {             // increment the opacity by 5%             this.alpha += .05;             // if we are at full opacity             if( this.alpha >= 1 )             {                 // remove the listener ( so we don't call this method anymore )                 removeEventListener( Event.ENTER_FRAME, onFadeIn, false );                 // tell others that we are done                 dispatchEvent( new Event( Event.CHANGE ) );             }         }                 public function onFadeOut( objEvent:Event ):void         {             this.alpha -= .05;             if( this.alpha <= 0 )             {                 removeEventListener( Event.ENTER_FRAME, onFadeOut, false );                 dispatchEvent( new Event( Event.CHANGE ) );             }         }     } } // create your new faderclip var clip = new FaderClip(); addChild( clip ); // give it some design clip.graphics.beginFill( 0x660000, 1 ); clip.graphics.drawRect( 0, 0, 100, 100 ); clip.graphics.endFill(); // make it hidden clip.alpha = 0; // listen for changes clip.addEventListener( Event.CHANGE, onChanged ); // begin fading in clip.fadeIn(); function onChanged( objEvent:Event ):void {     // if the clip is at full opacity, fade out     if( objEvent.target.alpha >= 1 ) clip.fadeOut();     // else fade back in     else clip.fadeIn(); }
__________________
o Please do a search before you post
o Please use the [ as][ /as] tag for your code (so we can read it clearly)

Last edited by Slowburn; 02-07-2008 at 10:15 PM..
Slowburn is offline   Reply With Quote
Old 11-04-2009, 06:25 AM   #3
astrix
Registered User
 
Join Date: Jan 2005
Posts: 6
Default

A large difference in the amount of code to implement...

And, for programmers, not is very bad need write much more code???

I not like very much AS3 and class...

Good speed in as3, and much more options, but very bad the language... Not is easy and intuitive... And without easy and intuitive language, the time for develop are much more, and is important the time of development...

Last edited by astrix; 11-04-2009 at 06:28 AM..
astrix is offline   Reply With Quote
Old 11-04-2009, 03:02 PM   #4
maskedMan
Obfuscated Coder
 
maskedMan's Avatar
 
Join Date: Apr 2008
Posts: 699
Default

Quote:
Originally Posted by astrix View Post
A large difference in the amount of code to implement...

And, for programmers, not is very bad need write much more code???

I not like very much AS3 and class...

Good speed in as3, and much more options, but very bad the language... Not is easy and intuitive... And without easy and intuitive language, the time for develop are much more, and is important the time of development...
Slowburn's code is drastically longer than yours because he wrote a full-featured class instead of the stripped down basics, commented his code, and put his braces on start of the following line instead of at the end of the current line. You could do it like this too...

ActionScript Code:
package{      public class FaderClip extends MovieClip    {               public function fadeOut():void{             this.alpha = 1;             addEventListener( Event.ENTER_FRAME, onFadeOut, false, 0, true);         }      public function onFadeOut( objEvent:Event ):void{             this.alpha -= .05;             if( this.alpha <= 0 ){                 removeEventListener( Event.ENTER_FRAME, onFadeOut, false );                 dispatchEvent( new Event( Event.CHANGE ) );             }      }       } }

I count 10 statements here as opposed to your 6. Mostly this is also down to style.

AS3 is far more consistent and logical, with far better error reporting making it easier to debug. It's not 'intuitive' to you because you are not familiar with it. When you have experience with both however, you can clearly see how much more solid and consistent AS3 is.




EDIT: Argh! I've been sucked in by a dead thread.
__________________
man.mask = mask_mc;

Sigh. The AS3 version just doesn't look at nice as
'man.setMask(mask_mc);'

Last edited by maskedMan; 11-04-2009 at 03:14 PM..
maskedMan 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nice introduction to AS3 SHDR ActionScript 3.0 7 08-07-2008 12:17 PM
AS2 -> AS3 Migration: unloadMovie() -> ? henry wyckoff ActionScript 3.0 3 12-19-2007 03:20 PM
Converting to AS3. How would I do this in AS3 bubba ActionScript 3.0 7 10-08-2007 05:26 PM
help with as3 and mxml integration photoeq ActionScript 3.0 0 08-19-2007 08:53 PM
AS3 loads AS2 swf. AS2 swf not displayed darbar ActionScript 3.0 0 07-20-2007 10:12 PM


All times are GMT. The time now is 12:21 AM.


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