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
Solved

Tween Event error AS3

Posted on 2011-09-27
10
427 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
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.

790 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