-
Question about Classes
Hello,
I'm working on a project that involves a large number of bitmaps that all will have an alpha tween to fade them in. I am using AS3 for the tweens rather than the timeline, however every tween needs to be hand written because the code requires a discreet instance name to invoke the tween class.
My question: Is it possible to create a class like a tween manager that is simple and just invokes an Alpha tween to whatever MC it is applied to? Here is the code I'm currently using:
Actionscript Code:
var Alpha:Tween = new Tween(figures_mc, "alpha", Regular.easeIn, 0, 1, 5, true);
Thanks,
Llyfre
-
Actionscript Code:
import fl.transitions.Tween; import fl.transitions.easing.*; function alphaTween(mc,b,f,d) { var Alpha:Tween = new Tween(mc, "alpha", Regular.easeIn, b, f, d, true); } alphaTween(figures_mc0,0,1,5); alphaTween(figures_mc1,0,1,2);
arkitx
Last edited by arkitx; 05-04-2012 at 03:42 PM.
-
Total Universe Mod
A whole class for managing tweens may be a little overkill for what you want. You'd probably be fine with a simple helper function that just sugar coats your tween. You could have that function return a new tween instance to you ready to go so that you could still manipulate it (start, stop, destroy) the way you do now.
First write the function that accepts parameters for the parts that differ among bitmaps. In your case it looks like only the mc is different.
Actionscript Code:
function makeAlphaTween(mc) : Tween { var tween:Tween = new Tween(mc, "alpha", Regular.easeIn, 0, 1, 5, true); return tween; }
now, whenever you need to create the tween, say for an mc called bmp1 for example:
Actionscript Code:
bmp1_tween:Tween = makeAlphaTween(bmp1);
-
I gave jAQUAN's script a whirl and got back the following error messages:
1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
1188: Illegal assignment to class Tween.
Next, I put arkitx's script to work and it is perfect --thanks so much!
-Llyfre
Last edited by llyfre; 05-05-2012 at 01:15 AM.
Reason: mispelling
-
No jAQUAN's Code is perfect. The usage of his code is more that mine. Try this.
Actionscript Code:
import fl.transitions.Tween; import fl.transitions.easing.*;
function makeAlphaTween(mc):Tween { var tween:Tween = new Tween(mc, "alpha", Regular.easeIn, 0, 1, 5, true); return tween; }
var bmp1_tween:Tween = makeAlphaTween(bmp1);
btn.addEventListener(MouseEvent.CLICK,clicked); function clicked(evt:MouseEvent):void { if (bmp1_tween.isPlaying) { bmp1_tween.stop(); } else { bmp1_tween.start(); } }
This is on behalf of him. Please don't mind jAQUAN.
You have to know What the Error tells you and sometimes we thought that you know at least the basic syntax.
arkitx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|