dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Building a Function, passing lines of code

  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    51

    Building a Function, passing lines of code

    So this is a basic question, I think, but I'm having a bunch of trouble.

    Basically, I want to save time by building functions for my commonly used tasks, in this case fading transitions. I want to build a function that can pass the specifics for the transition, and then implement them in code. However, I can't figure out what class to make the arguments - when they're strings it errors and I don't know what else to call them. Here's the basic of the code:

    private function transition(obj:MovieClip,string:string,direc:Strin g,durat:Number,ease:String,evt:Function):void {
    var tm:TransitionManager = new TransitionManager(obj);
    tm.startTransition({type:string, direction:direc, duration:durat, easing:ease});
    tm.addEventListener("allTransitionsInDone",evt);
    }

    transition(tribeguys_mc,Fade,"Transition.IN",4,"Re gular.easeOut",testing123)

    I'm looking for a way to do this in multiple cases - when a flash method has multiple arguements, I want to be able to pass them in a function.

  2. #2
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    You don't need to pass a function into another function... in fact, I don't think I've ever seen it done. Is that working like that? You should just be able to call the function on its own and it will work.

    Also, I'm not sure if this code is exact, but you need to capitalize "String" in the parameters of your function definition.

    Secondly, I'm not sure if you intended to spell this wrong or not, but "allTransitionsIsDone" (you put "In" instead of "Is")... I won't even get into grammar .

    That transition manager class seems pretty complicated. I'd think about learning to use Tweener. Google it. It's great and it's got an "onComplete" parameter where you can include something that you want it to do when the animation is completed.

    Oh, also Tweener doesn't need to be instantiated. You just include it at the beginning and then use "Tweener.addTween(parameters.....)" for every tween you want to do. It works really well.
    Last edited by Taidaishar; 06-11-2009 at 11:03 AM.

  3. #3
    Member
    Join Date
    Mar 2004
    Posts
    51
    I did notice that In/Is distinction - but that's the way it's referenced (twice) in the comment field of adobe's official help, so I just copy/pasted.

    I'll look into tweener. I was just looking for an easy way to add functionality to an existing function without having to add new lines of code each time.

  4. #4
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    Yeah. That makes sense. I think Tweener would actually be easier for you to use however. It's a lot easier to understand IMO. You just treat it like any other class file. Also, the documentation is really good. If you go to the website and read about it.

    That doesn't fix your current problem, however. What error are you getting?

  5. #5
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    I think you should use TweenLite instead of Tweener its even simpler to use and you can do really neat things with it.
    ~calmchess~

  6. #6
    Member
    Join Date
    Mar 2004
    Posts
    51
    Well, I mean it does, in a way

    I've learned not to try and pass arguements from one function to another. And as long as I can get some kind of "transition completed" event/function out of tweener, it might be exactly what I need.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Your original code actually looks mostly okay except for a few issues. One is the capitalization of String. Another more serious issue is that TransitionManager does not dispatch the event you're listening for. I don't know where you got that.

    The transparams object passed to startTransition should have a type field which is a Class, and should be one of the subclasses of Transition (Blinds, Fade, Fly, Iris, Photo, PixelDissolve, Rotate, Squeeze, Wipe, Zoom). Direction should be one of the direction constants defined in Transition (Transition.IN, Transition.OUT, these are uints). Duration appears to be a Number, expressed in seconds. Easing is a Function which takes the parameters (t:Number, b:Number, c:Number, d:Number) and returns Number. See Bounce.easeOut.

    Code:
    private function transition(obj:MovieClip, transType:Class, direc:uint, durat:Number, ease:Function,evt:Function):void {
      var tm:TransitionManager = new TransitionManager(obj);
      tm.startTransition({type:transType, direction:direc, duration:durat, easing:ease});
      //tm.addEventListener("allTransitionsInDone",evt);  //doesn't work since TransistionManager does not dispatch it.
    }
    
    transition(tribeguys_mc, Fade, Transition.IN, 4, Regular.easeOut, testing123);
    Of course, since your extra callback won't be called, you could just do this with TransitionManager.start

    Code:
    TransitionManager.start(tribeguys_mc, {type:Fade, direction:Transition.IN, duration:4, easing:Regular.easeOut});
    So yeah, use a different tweening package that has the callback/event you need.

  8. #8
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    Here's a sample line using Tweener:
    PHP Code:

    Tweener
    .addTween(targetMovieClip, {x:targetXy:targetYtime:numberOfSecondstransition:"linear"onComplete:myFunction})

    //the transition parameter is for easing
    //the time parameter is in seconds

    function myFunction():void
    {
         
    //this function is called when the animation is completed

    Also, you can use other parameters like scaleX, scaleY, alpha, onStart(performs an action when the animation starts), onUpdate(performs an action when animation updates). You can also create your OWN properties and have tweener affect those. It's a really robust package.

    In fact, here are the links to get you started with Tweener:
    Code Download:http://code.google.com/p/tweener/
    Online Documentation: http://hosted.zeh.com.br/tweener/docs/en-us/
    Last edited by Taidaishar; 06-11-2009 at 11:34 AM.

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