A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Question about Classes

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177

    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

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    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.

  3. #3
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    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);

  4. #4
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177
    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

  5. #5
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center