I'm not saying you have to create a new instance but was just getting as
close to your example as I could, which looks like a new instance to me;
"var myBox:DrawBox("boxname");
myBox._y = 100;
myBox._alpha = 50;"
" this is just an example..
u know i wanted to apply some custom effect to a movieClip and using
mc.applyFX(bla bla) instead of applyFX(mc, bla bla);
Just like mc_tween's mc.alphaTo() for example..."
If you want shortcuts like mc_tween then you are probably attaching them to
the MovieClip prototype. This will give every MovieClip from there on out
the same functions ( version1 ).
If you want and instance by instance basis with shortcuts, then you can try
using a class like EventDispatcher.initialize ( object ), or replace a
simple MovieClip with a class that extends the MovieClip class which
includes those shortcuts you want ( version2 ).
You'll notice in version2 each shortcut calls static methods in another
class. Maybe that keeps file size and memory usage down... who knows?
/////////////////////////////////////////////
//
// VERSION 1: Prototype Approach
//
/////////////////////////////////////////////
var mc = this.createEmptyMovieClip ( 'box', this.getNextHighestDepth() );
MovieClip.prototype.OFouction = function(){ trace( 'this function is
special' ) };
mc.OFouction (); // this function is special
/////////////////////////////////////////////
//
// VERSION 2: Shortcuts with static methods
//
/////////////////////////////////////////////
// In .fla
var myBox = this.createEmptyMovieClip ('myBox', this.getNextHighestDepth()
);
myBox.__proto__ = DrawBox.prototype;
myBox.drawMe ();
myBox._y = 100;
myBox._alpha = 0;
myBox.alphaTo ( 100 );
// in DrawBox.as
import CrazyEffects;
class DrawBox extends MovieClip
{
public function DrawBox ( ) {
}
public function drawMe ( ):Void { CrazyEffects.drawBox ( this ); }
public function alphaTo ( alpha:Number ):Void { CrazyEffects.alphaTo
( this, alpha ) };
}
// in CrazyEffects.as
class CrazyEffects
{
public function CrazyEffects ( )
{
}
public static function drawBox ( mc ):Void
{
with ( mc )
{
beginFill(0xFF0000,100);
moveTo(0,0);
lineTo(100,0);
lineTo(100,100);
lineTo(0,100);
lineTo(0,0);
endFill();
}
}
public static function alphaTo ( mc, alpha ):Void
{
mc.onEnterFrame = function()
{
var dif = alpha - this._alpha;
if ( Math.abs( dif) < 2 )
{
this._alpha = alpha;
delete this.onEnterFrame;
}
else
{
this._alpha += dif / 6;
}
}
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of O. Fouad
Sent: Friday, June 08, 2007 7:09 PM
To: [email protected]
Subject: Re: [Flashcoders] Having MovieClip behaviours in a class..
thanks :D but why should i use static methods.... I am trying to create some
color effect shortcut....i wont need to create new instances. If i have a
movieClip on my stage i wouldlike to have it
myMC.someEffect(par);
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com