[CS3] Help With my code!
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 40

Thread: [CS3] Help With my code!

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    39

    [CS3] Help With my code!

    hi someone helped me out with this code and when i run it i get this error

    1120: Access of undefined property circle_mc.
    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );

    im completley new to actionscript and was wondering if someone could tell me what the error means?

    Thanks

    Code:
    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
     
     
    var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    // this tweens the yellow_mc inside of circle_mc.
     
    yellowTween.addEventListener(TweenEvent.MOTION_FINISH, startBlue);
    // this listens for the yellowTween to finish its event and when its done it triggers startBlue function.
     
    function startBlue(event:TweenEvent):void
    {
    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true ); 
    // in this function it starts the blue_mc to tween. 
     
    blueTween.addEventListener(TweenEvent.MOTION_FINISH, startRed);
    //also, it listens for the blueTween to finish its motion tween. now, i had to put this inside of this function rather than outside because i declared variable ofblueTween insie of this startBlue function. so in ordor to recognize the blueTween, it has to be within the same location.
     
    }
    function startRed(event:TweenEvent):void
    {
    var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
    // so after blue is finished, it triggered red Tween and this is the red function.
     
    }

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    it means that circle_mc does not exist as far as the code you are running is concerned. is there a clip on the stage with that instance name?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    39
    ahh i see now, got it working.

    how do i make the actionscript code below loop?

    thankyou

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    By loop, you mean make the tweens loop?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Member
    Join Date
    Aug 2008
    Posts
    39
    no as in make the whole thing start again, go back to the begining

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Well here is what I would probably do. Tweens are weird in that they are in fact reusable, but I have not found a way to create them without passing the initial parameters, which in turn stars the tween. So basically what I normally end up doing with them is creating them and then immediately stopping them, or create them with a starting and ending value that is the same (I do this when I will be customizing the values later). So if I understand you correctly, you want that sequence of tween to loop. I did not actually test this, but you can give it a try and see how it works for you:

    var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    yellowTween.stop();
    yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, startBlue);
    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    blueTween.stop();
    blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startRed);
    var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
    redTween.stop()
    blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startYellow);
    yellowTween.start();

    function startBlue(event:TweenEvent):void
    {
    blueTween.start();
    }
    function startRed(event:TweenEvent):void
    {
    redTween.start()
    }
    function startYellow(event:TweenEvent):void
    {
    yellowTween.start();
    }

    by doing it this way you are reusing the tween objects and only assigning the event listeners once instead of recreating them and assigning them each time the TweenEvent.MOTION_FINISH is triggered. Since each TweenEvent.MOTION_FINISH triggers the next tween to start, you basically just set the loop up and let it run.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    Member
    Join Date
    Aug 2008
    Posts
    39
    right heres the code so far

    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;


    var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    yellowTween.stop();
    yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, startBlue);

    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    blueTween.stop();
    blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startRed);

    var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
    redTween.stop()
    redTween.addEventListener(TweenEvent.MOTION_FINISH , startYellow);

    yellowTween.start();

    function startBlue(event:TweenEvent):void
    {
    blueTween.start();
    }
    function startRed(event:TweenEvent):void
    {
    redTween.start()
    }
    function startYellow(event:TweenEvent):void
    {
    yellowTween.start();
    }

    the first time it goes it loops over each other giving a sorta cross fade effect the second time is different

    id like each to fade in straight after each other, and how do i slow them down?

    my fla is attached if it helps to use my example
    and the swf to view it

    Thankyou very much for your help so far
    Attached Files Attached Files

  8. #8
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    So the second set of rotations is what you want correct? You slow them down by making the tween take longer which is the number value before the last parameter true.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  9. #9
    Member
    Join Date
    Aug 2008
    Posts
    39
    yes the second is more right, but id like them to fade in and out if thats a simpel add on?

  10. #10
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Again this has to do with the tweens starting. Since your circles are on top of each other, the first time through you see the colors mixing, but after the first pass, they are all hidden. Add the following:

    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    yellowTween.stop();
    circle_mc.yellow_mc.alpha=0;
    yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, startBlue);

    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
    blueTween.stop();
    circle_mc.blue_mc.alpha =0;
    blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startRed);

    var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
    redTween.stop()
    circle_mc.red_mc.alpha =0;
    redTween.addEventListener(TweenEvent.MOTION_FINISH , startYellow);

    yellowTween.start();

    function startBlue(event:TweenEvent):void
    {
    blueTween.start();
    }
    function startRed(event:TweenEvent):void
    {
    redTween.start()
    }
    function startYellow(event:TweenEvent):void
    {
    yellowTween.start();
    }
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  11. #11
    Member
    Join Date
    Aug 2008
    Posts
    39
    super
    how do i get them to fade in then wait for a given ammount of time then fade out?

    Thankyou so much for your help
    im learning hehe

  12. #12
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Try this:

    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    yellowTween.stop();
    yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, fadeOut);
    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    blueTween.stop();
    var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true);
    redTween.stop();
    circle_mc.yellow_mc.nextTween = blueTween;
    circle_mc.blue_mc.nextTween = redTween;
    circle_mc.red_mc.nextTween = yellowTween;

    yellowTween.start();

    function fadeOut(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, fadeOut);
    event.target.addEventListener(TweenEvent.MOTION_FI NISH, startNext);
    event.target.begin = 1;
    event.target.finish = 0;
    event.target.start();
    }
    function startNext(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, startNext);
    event.target.obj.nextTween.addEventListener(TweenE vent.MOTION_FINISH, fadeOut);
    event.target.obj.nextTween.begin = 0;
    event.target.obj.nextTween.finish = 1;
    event.target.obj.nextTween.start();
    }
    a bit simpler than writing start and end function for each tween.
    Last edited by kortex; 08-11-2008 at 01:32 PM.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  13. #13
    Member
    Join Date
    Aug 2008
    Posts
    39
    this is exactly what i wanted
    do you think you could comment it for me to explain what each part does?

    Thankyou for your help

  14. #14
    Member
    Join Date
    Aug 2008
    Posts
    39
    hi ive been trying to duplicate your code for some text with static backgrounds

    so there is a bakground colour and the text fades on top of it

    i thought i changed all the names right but i must of missed of left something out

    heres the code, it prioduces no errors, just doesnt work

    Code:
    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    var text1Tween:Tween = new Tween (text_mc.text1_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    text1Tween.stop();
    text1Tween.addEventListener(TweenEvent.MOTION_FINISH,fadeOutText);
    var text2Tween:Tween = new Tween (text_mc.text2_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    text2Tween.stop();
    var text3Tween:Tween = new Tween (text_mc.text3_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true);
    text3Tween.stop();
    
    text_mc.text1_mc.nextTween = text2Tween;
    text_mc.text2_mc.nextTween = text3Tween;
    text_mc.text3_mc.nextTween = text1Tween;
    
    text1Tween.start();
    
    function fadeOutText(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION_FINISH, fadeOutText);
    event.target.addEventListener(TweenEvent.MOTION_FINISH, startNextText);
    event.target.begin = 1;
    event.target.finish = 0;
    event.target.start();
    }
    function startNextText(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION_FINISH, startNextText);
    event.target.obj.nextTween.addEventListener(TweenEvent.MOTION_FINISH, fadeOutText);
    event.target.obj.nextTween.begin = 0;
    event.target.obj.nextTween.finish = 1;
    event.target.obj.nextTween.start();
    }
    and the fla so you can see what ive done easier

    thanks for any help
    Attached Files Attached Files

  15. #15
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Will start with the commented code:
    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    /*
    Create tween objects and immediately stop them so that they can be re-used.
    */
    var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    yellowTween.stop();
    var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    blueTween.stop();
    var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true);
    redTween.stop();
    /*Add an event listener to the first tween to trigger the fade in the opposite
    direction. Subsequent listeners will be assigned and removed in the event
    handler functions.
    */
    yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, fadeOut);
    /*
    Since movie clips allow for the creation of dynamic properties (aka variables), simply create a
    reference to the next tween that should be triggered directly on the clip. With
    this system you could easily add additional clips by creating a new tween and adding
    another reference on the new clip to be tweened.
    */
    circle_mc.yellow_mc.nextTween = blueTween;
    circle_mc.blue_mc.nextTween = redTween;
    circle_mc.red_mc.nextTween = yellowTween;
    /*
    Start the first tween to kick off the sequence. This should be the tween that you
    added the event listener to in the previous code.
    */
    yellowTween.start();

    /*
    Create a generic handler for the end of the fade in event. Since the TweenEvent object
    holds a reference to the tween that caused the even, we can reference that tween via
    the event.target property.
    */
    function fadeOut(event:TweenEvent) {
    /*remove the event listener that triggers this function from the tween since we have
    gotten past the point of needed it and we don't want it to complete with the next part
    of the sequence.
    */
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, fadeOut);
    /*Add a new event listener that will trigger the next part of the sequence*/
    event.target.addEventListener(TweenEvent.MOTION_FI NISH, startNext);
    /*Set the begin and finish properties of the tween object to the opposites
    of those we used to create the fade in effect. I had originally tried to do
    this with the built in yoyo function, but it produced unexpected results.
    */
    event.target.begin = 1;
    event.target.finish = 0;
    /*Restart the tween with the new properties, when this tween is finished,
    it will trigger the new event handler we assigned in this function and
    continue the sequence.
    */
    event.target.start();
    }
    /*Now that the tween has faded in and out, start the next tween. Again since TweenEvent
    holds a reference to the tween that triggered the event, we can reference that tween.
    Additionally, since the tween object holds a reference to the clip being tweened,
    we can reference the properties of that clip. In this case we are interested in the
    nextTween property we assigned in the previous code as this is what we will use
    to start the next tween.
    */
    function startNext(event:TweenEvent) {
    /*Removed the event listener that triggered this function.*/
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, startNext);
    /*
    event.target is the tween that triggered the function. obj is the property on
    the tween object that holds a reference to the clip being tweened. hence, we can
    reference the next tween to be triggered by accessing the nextTween property we created.
    */
    /*
    add a listener to trigger the fade out function completing the logical loop.
    */
    event.target.obj.nextTween.addEventListener(TweenE vent.MOTION_FINISH, fadeOut);
    /*Reset the values of the tween so that the effect is to fade in.*/
    event.target.obj.nextTween.begin = 0;
    event.target.obj.nextTween.finish = 1;
    /*start the tween and the cycle repeat itself.*/
    event.target.obj.nextTween.start();
    }
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  16. #16
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Quote Originally Posted by awilderbeast
    hi ive been trying to duplicate your code for some text with static backgrounds

    so there is a bakground colour and the text fades on top of it

    i thought i changed all the names right but i must of missed of left something out

    heres the code, it prioduces no errors, just doesnt work

    Code:
    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    var text1Tween:Tween = new Tween (text_mc.text1_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    text1Tween.stop();
    text1Tween.addEventListener(TweenEvent.MOTION_FINISH,fadeOutText);
    var text2Tween:Tween = new Tween (text_mc.text2_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    text2Tween.stop();
    var text3Tween:Tween = new Tween (text_mc.text3_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true);
    text3Tween.stop();
    
    text_mc.text1_mc.nextTween = text2Tween;
    text_mc.text2_mc.nextTween = text3Tween;
    text_mc.text3_mc.nextTween = text1Tween;
    
    text1Tween.start();
    
    function fadeOutText(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION_FINISH, fadeOutText);
    event.target.addEventListener(TweenEvent.MOTION_FINISH, startNextText);
    event.target.begin = 1;
    event.target.finish = 0;
    event.target.start();
    }
    function startNextText(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION_FINISH, startNextText);
    event.target.obj.nextTween.addEventListener(TweenEvent.MOTION_FINISH, fadeOutText);
    event.target.obj.nextTween.begin = 0;
    event.target.obj.nextTween.finish = 1;
    event.target.obj.nextTween.start();
    }
    and the fla so you can see what ive done easier

    thanks for any help
    Tweening text is always a pain in the ***. Most of the time you have to embed your fonts. I would try that first.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  17. #17
    Member
    Join Date
    Aug 2008
    Posts
    39
    that worked

    now i have a problem with my backgrounds

    what i was doing was

    background 1 in the text1mc does not fade
    then text1 fades in and out
    then i want background 2 to appaer
    then text2 fades and so on if you get me

    if you see my fla you will be able to tell what i mean

    thanks for your help ,really appreciate it
    Attached Files Attached Files

  18. #18
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Was able to simplify this even further. It will depend a bit on the order of the clips in the FLA, but this is even more flexible. Take a look at what I did in the fla with text_mc

    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    var text1Tween:Tween = new Tween (text_mc.text_1, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    text1Tween.stop();
    text1Tween.addEventListener(TweenEvent.MOTION_FINI SH,fadeOutText);
    if (text_mc.numChildren > 1) {
    for (var c:int = text_mc.numChildren-1; c>=0; c--) {
    var clip:Object = text_mc.getChildAt(c);
    clip.alpha = 0;
    if (c > 0){
    clip.nextClip = text_mc.getChildAt(c-1);
    }else{
    clip.nextClip = text_mc.getChildAt(text_mc.numChildren-1);
    }
    }
    }
    text1Tween.start();

    function fadeOutText(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, fadeOutText);
    event.target.addEventListener(TweenEvent.MOTION_FI NISH, startNextText);
    event.target.begin = 1;
    event.target.finish = 0;
    event.target.start();
    }
    function startNextText(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, startNextText);
    event.target.addEventListener(TweenEvent.MOTION_FI NISH, fadeOutText);
    event.target.obj = event.target.obj.nextClip;
    event.target.begin = 0;
    event.target.finish = 1;
    event.target.start();
    }
    Attached Files Attached Files
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  19. #19
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Will also work for your other clips. As long as they are all going to use the same timings, then this should be fine:
    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
    var yellowTween:Tween = new Tween (pics_mc.yellow_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
    yellowTween.stop();
    yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH,fadeOut);

    if (pics_mc.numChildren > 1) {
    for (var c:int = pics_mc.numChildren-1; c>=0; c--) {
    var clip:Object = pics_mc.getChildAt(c);
    clip.alpha = 0;
    if (c > 0) {
    clip.nextClip = pics_mc.getChildAt(c-1);
    } else {
    clip.nextClip = pics_mc.getChildAt(pics_mc.numChildren-1);
    }
    trace (pics_mc.getChildAt(c).name)
    trace (clip.nextClip.name)
    }
    }


    yellowTween.start();

    function fadeOut(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, fadeOut);
    event.target.addEventListener(TweenEvent.MOTION_FI NISH, startNext);
    event.target.begin = 1;
    event.target.finish = 0;
    event.target.start();
    }
    function startNext(event:TweenEvent) {
    event.target.removeEventListener(TweenEvent.MOTION _FINISH, startNext);
    event.target.addEventListener(TweenEvent.MOTION_FI NISH, fadeOut);
    event.target.obj = event.target.obj.nextClip;
    event.target.begin = 0;
    event.target.finish = 1;
    event.target.start();
    }
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  20. #20
    Member
    Join Date
    Aug 2008
    Posts
    39
    how do i set the timings?

    i dotn get some of the code, could you explain it to me please?

    also with the text movie clips i with the backgrounds (the big squares) i didnt want the squares to fade in, just to change colour then the text fades ontop of it

    thankyou so much for your help though, youve been so helpful so far
    Thanks!

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

Poll by Flashkit.com