• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

Tween Event error AS3

Code snippet:

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

var GEOTweenH:Tween;

function doGreenOld(e:Event):void{
      stage.removeEventListener(Event.ENTER_FRAME, doGreenOld);
      var GEOTweenH:Tween = new Tween(GEO, "height", Strong.easeOut, 18.1, 173.4, 3, true);      
}

GEOTweenH.addEventListener(TweenEvent.MOTION_FINISH, dissolveOld);



The last line throws this error (you've seen it before):

TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at CCSD_fla::MainTimeline/CCSD_fla::frame55()

I've move the Tween listener around ahead of the function and it doesn't make any difference.

Any ideas?
0
chevronrod
Asked:
chevronrod
  • 3
  • 3
  • 2
  • +2
1 Solution
 
Antonio EstradaCommented:
Can we see the full code? it might be something in the dissolveOld function. Perhaps the GEO identifier isn't present...

A lot of things could be going sour. It would even be better if you could provide the FLA.

-V
0
 
chevronrodAuthor Commented:
EE-help.fla

Here is a stripped down version of the .fla.
0
 
dgofmanCommented:
You are looking for problem in the wrong place. You forgot create a Tween object for GEOTweenH variable

Here is my prove

trace(GEOTweenH)

//GEOTweenH.addEventListener(TweenEvent.MOTION_FINISH, dissolveOld);

I am sure you will find out how to fix this problem now :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dgofmanCommented:


function doGreenOld(e:Event):void{
      stage.removeEventListener(Event.ENTER_FRAME, doGreenOld);
      var GEOTweenX:Tween = new Tween(GEO, "x", Strong.easeOut, 141.6, 275, 3, true);
      var GEOTweenY:Tween = new Tween(GEO, "y", Strong.easeOut, 71.7, 200,  3, true);
      var GEOTweenW:Tween = new Tween(GEO, "width", Strong.easeOut, 32.1, 236.4, 3, true);
      var GEOTweenH:Tween = new Tween(GEO, "height", Strong.easeOut, 18.1, 173.4, 3, true);
      GEOTweenH.addEventListener(TweenEvent.MOTION_FINISH, dissolveOld);
}
0
 
Antonio EstradaCommented:
Oops didn't check my email until now. I guess there's the answer now, however I'll keep monitoring this in case you need any assistance.

-V
0
 
blue-genieCommented:

i just want to add my 2c worth.

you did declare var GEOTweenH:Tween; but it's not instantiated so when you do the addEventListener - it doesn't know what you're referring to, hence the null errror.

but IMO you have a scope issue

 inside of doGreenOld function, you're creating a local variable by declaring var GEOTweenH again  - this is inside the scope of the function
so my adding the addEventListener inside doGreenOld it knows what you're referencing, but your removeEventListener inside dissolveOld  won't be referencing the correct instance.

0
 
chevronrodAuthor Commented:
dgofman, I'm going to award you the points on this one.

Vulturous, thanks for helping getting this thing rolling by requesting the .fla.

blue-genie, you are right. I tried to morph some of the things I saw on the internet as I searched for solutions, by putting in the declaration before the function. But, alas, that was to no avail.

dgofman, your solution works in an excellent manner. One question, if you don't mind. I don't see a way to REMOVE the listenener, then, when I run the dissolveOld function since it has now left the calling function behind.
0
 
tomaugerdotcomCommented:
It's an EE party! Let me get in on the fun.

@B-G's right as usual, you're attempting to redeclare your GEOTweenH object by re-using the "var" keyword. I used to do this all the time, still sometimes forget that I've already done it. This line:

var GEOTweenH:Tween = new Tween(GEO, "height", Strong.easeOut, 18.1, 173.4, 3, true);

Open in new window


should read:

GEOTweenH = new Tween(GEO, "height", Strong.easeOut, 18.1, 173.4, 3, true);

Open in new window


Note that we took out both the "var" keyword and the type declaration.

But the actual error is that your tween can't find the "GEO" object ( at least, if we go by the code that you posted in your OP ). This is an extremely common situation, where your ActionScript is executing BEFORE the items on the stage that you want to tween are actually available to ActionScript.

This is mitigated by wrapping any code that depends on objects being on the stage within a Event.ADDED_TO_STAGE event handler. We typically do this right off the bat:

public class MyDocumentClass extends MovieClip {
  public function MyDocumentClass {
     this.addEventListener(Event.ADDED_TO_STAGE, init);
  }

  private function init(e:Event):void {
    //.. now your stage objects are available
  }
}

Open in new window

0
 
dgofmanCommented:
You are removing but I will suggest to use event target to be sure you are removing for the current object

function doGreenOld(e:Event):void{
      stage.removeEventListener(Event.ENTER_FRAME, doGreenOld);
      var GEOTweenX:Tween = new Tween(GEO, "x", Strong.easeOut, 141.6, 275, 3, true);
      var GEOTweenY:Tween = new Tween(GEO, "y", Strong.easeOut, 71.7, 200,  3, true);
      var GEOTweenW:Tween = new Tween(GEO, "width", Strong.easeOut, 32.1, 236.4, 3, true);
      var GEOTweenH:Tween = new Tween(GEO, "height", Strong.easeOut, 18.1, 173.4, 3, true);      
      GEOTweenH.addEventListener(TweenEvent.MOTION_FINISH, dissolveOld);
}

function dissolveOld(e:TweenEvent):void{
      e.currentTarget.removeEventListener(TweenEvent.MOTION_FINISH, dissolveOld);

      TMGreenOld.startTransition({type:PixelDissolve,direction:Transition.OUT,
            duration:1,easing:Regular.easeIn,xSections:100,ySections:100});
}
0
 
chevronrodAuthor Commented:
Thanks to all who contributed to this solution. I'm rolling down the tracks now and headed for my next confusion. :)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now