Jump to content
Search Community

Cannot tween a null object

ContraMuffin test
Moderator Tag

Recommended Posts

Hello,
I'm kind of new to Greensock (and Flash in general), so sorry if it's a stupid mistake. I'm trying to create a textbox (like in games). I fumbled around with the code until it runs properly. However, once I move onto the third frame, the Output panel gives me an error.

 

Error: Cannot tween a null object. Duration: 0.3, data: undefined
at com.greensock::TweenLite()
at com.greensock::TweenMax()
at com.greensock::TweenMax$/to()
at textbox_fla::MainTimeline/myKeyDown()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenMax/render()
at com.greensock.core::SimpleTimeline/render()
at com.greensock.core::Animation$/_updateRoot()

 

This is strange, since the function "myKeyDown" is in frame 1. I do not understand why Greensock would throw me an error, since the function is not a functionality of Greensock (it's just a regular AS3 code) . Anyways, here is the code on frame 1.

import com.greensock.*;
import flash.events.KeyboardEvent;

stop();
TweenMax.from(instruc,1,{alpha:0});
TweenMax.from(char1,0.3,{x:"-400"});
TweenMax.from(box, 0.5, {x:"-100", alpha:0});
textbox.visible = false;
TweenMax.delayedCall(0.5, myFunctionL);
function myFunctionL():void{
	textbox.visible = true;
	TweenMax.from(textbox, 0.3, {x:"-10", alpha:0});
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void{
if(e.keyCode == 32){
	TweenMax.to(textbox,0.3,{x:"10",alpha:0});
	TweenMax.to(char1,0.3,{x:"-400"});
	TweenMax.delayedCall(0.3,frame);
	function frame():void{
	nextFrame();
}
}
}

Link to comment
Share on other sites

We can't really troubleshoot by just looking at your code. Null object errors are usually related to user-error.

Either you have typed an instance name wrong like textbox instead of textBox or you are trying to tween something that isn't on the stage.

Sounds like you may have an item that has an instance name on frame 1 but for some reason loses it on frame 3. Sometimes this can happen if you are duplicating symbols when you make new keyframes... again hard to know from looking at the code only.

 

2 ways of getting to the heart of the issue.

 

  1. Remove tweens one by one and export after each removal to see where the error goes away.
  2. prior to each tween try to trace() out the target of the tween and see which one is null

 

For option 2, something like this

trace("instruc is " + instruc);
TweenMax.from(instruc,1,{alpha:0});
trace("char1 is " + char1);
TweenMax.from(char1,0.3,{x:"-400"});
trace("box is " + box)
TweenMax.from(box, 0.5, {x:"-100", alpha:0});
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...