Skip to main content
Known Participant
June 20, 2011
Answered

nested function

  • June 20, 2011
  • 2 replies
  • 1290 views

(1)

i want to add a listener that it will direct to a nested function if it triggered,

but later i found that i cant name the target event directly as "dragStart", so what should i type?

(2)

also, are there some ways that able to do the same tweening effect as the code below but without nesting them?

i made the tweenings play as one by one.

thz for any help

function changeImg() {

    mask1.removeEventListener(Event.ENTER_FRAME, mask1Drag);

    stage.addEventListener(MouseEvent.CLICK, dragStart);

    var maskTween1:Tween = new Tween(mask1,"width",Strong.easeInOut,1,750,1,true);

    maskTween1.addEventListener(TweenEvent.MOTION_FINISH, playMaskTween2);
    function playMaskTween2(e) {

        var maskTween2:Tween = new Tween(mask1,"width",Strong.easeInOut,750,1,1,true);

        maskTween2.addEventListener(TweenEvent.MOTION_FINISH, playMaskTween3);
        function playMaskTween3(e) {

            var maskTween3:Tween = new Tween(mask1,"width",Strong.easeInOut,1,750 - mouseX,1,true);

            maskTween3.addEventListener(TweenEvent.MOTION_FINISH, dragStart);
           function dragStart(e) {

                maskTween1.stop();
                maskTween2.stop();
                maskTween3.stop();
                mask1.addEventListener(Event.ENTER_FRAME, mask1Drag);
            }
        }
    }
}

This topic has been closed for replies.
Correct answer kglad

use:

function dragStart(e) {
    if(maskTween1){
    maskTween1.stop();
    }
    if(maskTween2){
    maskTween2.stop();
    }
    if(maskTween3){
    maskTween3.stop();
    }
    mask1.addEventListener(Event.ENTER_FRAME, mask1Drag);
}

2 replies

Participating Frequently
June 23, 2011

I am wondering if you can help me again. I have some simple animations happening with the instructions you gave me before. I have a box that comes in followed by a circle. Then the box spins. I want to make the box get larger and come towards the user, I guess kind of zoom in. I have tried adding TrasitionManager zoom to no avail. Can you show me how this is done. Here is my code. Thank you.

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

var boxFlyIn;

boxFlyIn = new Tween(box_mc,"x",Strong.easeOut,-50,200,0.5,true);
boxFlyIn.addEventListener(TweenEvent.MOTION_FINISH, doCrcFlyIn);

var crcFlyIn;

function doCrcFlyIn(evt:TweenEvent):void
{
    boxFlyIn.removeEventListener(TweenEvent.MOTION_FINISH, doCrcFlyIn);
    crcFlyIn = new Tween(crc_mc,"x",Strong.easeOut,900,300,0.5,true);
    crcFlyIn.addEventListener(TweenEvent.MOTION_FINISH, doBoxSpin);
}

var boxSpin;

function doBoxSpin(evt:TweenEvent):void
{
    crcFlyIn.removeEventListener(TweenEvent.MOTION_FINISH, doBoxSpin);
    boxSpin = new Tween(box_mc,"rotation",Strong.easeOut,0,360,1,true);

}

kglad
Community Expert
Community Expert
June 20, 2011

never nest named functions.

  var   maskTween1:Tween
var maskTween2:Tween
var maskTween3:Tween

function changeImg() {

    mask1.removeEventListener(Event.ENTER_FRAME, mask1Drag);

    stage.addEventListener(MouseEvent.CLICK, dragStart);

     maskTween1 = new Tween(mask1,"width",Strong.easeInOut,1,750,1,true);

    maskTween1.addEventListener(TweenEvent.MOTION_FINISH, playMaskTween2);
 
}

  function playMaskTween2(e) {

        maskTween2 = new Tween(mask1,"width",Strong.easeInOut,750,1,1,true);

        maskTween2.addEventListener(TweenEvent.MOTION_FINISH, playMaskTween3);    
    }
   function playMaskTween3(e) {

           maskTween3 = new Tween(mask1,"width",Strong.easeInOut,1,750 - mouseX,1,true);

            maskTween3.addEventListener(TweenEvent.MOTION_FINISH, dragStart);
          
         }
function dragStart(e) {

                maskTween1.stop();
                 maskTween2.stop();
                 maskTween3.stop();
                 mask1.addEventListener(Event.ENTER_FRAME, mask1Drag);
             }
lem9mAuthor
Known Participant
June 20, 2011

i ran the code you gave me above, then the complier gave me such thing:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at photoediting_fla::MainTimeline/dragStart()

and the tweening animations were lost...

if i remove the part of stops, it worked and the animations ran...

                maskTween1.stop();
                 maskTween2.stop();
                 maskTween3.stop();

did you know whats the reason of that?

thanks : )