Solved

Tween Event error AS3

Posted on 2011-09-27
10
424 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
ID: 36710981
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
ID: 36711989
EE-help.fla

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

Expert Comment

by:dgofman
ID: 36712416
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
ID: 36712424


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
ID: 36714307
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Expert Comment

by:blue-genie
ID: 36715687

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
ID: 36716799
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
ID: 36716820
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
ID: 36718703
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
ID: 36719606
Thanks to all who contributed to this solution. I'm rolling down the tracks now and headed for my next confusion. :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

920 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

15 Experts available now in Live!

Get 1:1 Help Now