?
Solved

Tween Event error AS3

Posted on 2011-09-27
10
Medium Priority
?
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
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…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

765 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