Solved

Tween Event error AS3

Posted on 2011-09-27
10
421 Views
Last Modified: 2012-08-13
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
Comment
Question by:chevronrod
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 18

Expert Comment

by:Antonio Estrada
Comment Utility
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
 

Author Comment

by:chevronrod
Comment Utility
EE-help.fla

Here is a stripped down version of the .fla.
0
 
LVL 29

Expert Comment

by:dgofman
Comment Utility
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
 
LVL 29

Expert Comment

by:dgofman
Comment Utility


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
 
LVL 18

Expert Comment

by:Antonio Estrada
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 39

Expert Comment

by:blue-genie
Comment Utility

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
 

Author Comment

by:chevronrod
Comment Utility
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
 
LVL 14

Expert Comment

by:tomaugerdotcom
Comment Utility
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
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:chevronrod
Comment Utility
Thanks to all who contributed to this solution. I'm rolling down the tracks now and headed for my next confusion. :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now