No, and I'm not writing the code for you as you'll learn, and remember it,
more through persistence. Unfortunately, you're further away from a
solution than you was before your first post.
Your onEnterFrame is a method defined within the fadeObj method and, as
such, it will not have access to the variables you've defined outside of it
- it has no reference to "mc", etc. whereas "this" would refer to the movie
clip that has the "onEnterFrame" event.
Your constructor sets two variables ("alphaRate" and "target") using
parameters that don't yet exist, yet your fadeObj defines those parameters
("$target" and "$alphaRate") but never uses them; "alphaRate" will always be
"0" and "target" "undefined".
Try popping a couple of traces in your methods and check the output window -
you'll have a few "undefined" results.
Your best bet would be to have a flick through a few examples in the Help
section; namely "Classes" which can be found under "Learning ActionScript
2.0 in Flash", and I would also read up on how to handle scope within your
classes. It can be troublesome at first but it's all worth it in the end as
it'll make your coding much more efficient - once you've cracked it, it's a
doddle. Although it's a shame Flash doesn't help as much as it could when
comparing it to other environments.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of CK
Sent: 06 August 2006 01:03
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Class Silent
Hi,
Would you say this is helping to resolve the problem:
[code]
class FadeAlpha extends MovieClip {
private var alpha:Number = this._alpha;
private var visible:Boolean = this._visible;
public var alphaRate:Number;
public var target:MovieClip;
//constructor.
public function FadeAlpha() {
alphaRate=$alphaRate;
target=$target;
}
function fadeObj($target:MovieClip, $alphaRate:Number) {
target.onEnterFrame = function() {
target.alpha -= alphaRate;
if (mc.alpha<=0) {
target._visible = false;
delete target.onEnterFrame;
}
};
}
}
/*
[/code]
On Aug 5, 2006, at 7:12 PM, Paul Venton wrote:
> Well for starters, your fadeObj method defines a parameter which
> has the
> same name as your public variable.
>
> Also, it appears that your onEnterFrame contains a reference to
> "mc" that
> doesn't exist in its scope; perhaps using a Delegate helper would
> solve
> that, or simply change it to "this" since the method belongs to
> your "mc"
> anyway.
>
> Although this could just be a typo, where you're instantiating your
> class,
> you're missing a "(" after the class name.
>
> Hope that helps get you back on track - good luck!
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of CK
> Sent: 05 August 2006 23:58
> To: Flashcoders mailing list
> Subject: [Flashcoders] Class Silent
>
> Hi,
>
> The following class I've coded fails to fade the MC on stage. Could
> someone explain why the code fails?
> //Class
> class FadeAlpha extends MovieClip {
> private var alpha:Number = this._alpha;
> private var visible:Boolean = this._visible;
> public var alphaRate:Number;
> public var mc:MovieClip;
> //constructor left enpty, can use later.
> public function FadeAlpha() {
> fadeObj();
> }
> function fadeObj(mc:MovieClip, alphaRate:Number) {
> mc.onEnterFrame = function() {
> mc.alpha -= alphaRate;
> if (mc.alpha<=0) {
> mc._visible = false;
> delete mc.onEnterFrame;
> }
> };
> }
> }
>
> From AS Timeline:
> import FadeAlpha;
> var fadeAlpha:FadeAlpha = new FadeAlpha);
> img01_mc.fadeAlpha(this, 5);
> On Stage:
> img1_mc
>
>
>
> _______________________________________________
> [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
>
> _______________________________________________
> [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
_______________________________________________
[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
_______________________________________________
[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