FORUMS: list search recent posts

Trouble with CreativeCow Tutorial

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Clint Milner
Trouble with CreativeCow Tutorial
on Dec 22, 2009 at 4:05:18 pm

Hi All,

I'm about 90% done with the newest snow globe tutorial here:
http://library.creativecow.net/articles/studios_domani/shake_snow_globe.php

I've worked through the video and written tutorial, but I'm getting one error.

When you pick up the globe and shake it the snow is supposed to update, but in my output I'm getting this:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SnowGlobeContainer/update()

The snow plays once and I can grab the globe and it bounces and everything works except the snow.

Has anyone experienced this and/or know where I might be going wrong?

Files here:
http://www.alpha-duplication.com/Snowglobe.zip (231 KB)


Thanks Everybody!

Clint


Adobe CS4 Master Suite
Vista Ultimate 64 SP1
Intel Core i7 920 @ 3.60GHz
12 GB DDR3 RAM
NVidia Quadro FX 3700
Matrox RT.X2 LE Capture Card
4 TB RAID 5


Return to posts index

Marcus Geduld
Re: Trouble with CreativeCow Tutorial
on Dec 22, 2009 at 5:46:22 pm

That sometimes happens when you either forget to give something on the stage an instance name or there's a typo in the name so that it doesn't agree with the name you've written in the code. That's the first thing I'd check. Looks like it's something referred to in the update() function. Remember, AS is case-sensitive, so snow and Snow are not considered the same name.

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index

Clint Milner
Re: Trouble with CreativeCow Tutorial
on Dec 23, 2009 at 3:01:27 pm

Thanks for the advice, but still not having much luck.

Can someone please have a look for me? OOP is new for me.


http://www.alpha-duplication.com/Snowglobe.zip

and the live version is at
http://www.alpha-duplication.com/Snowglobe/




Many thanks,
Clint

Adobe CS4 Master Suite
Vista Ultimate 64 SP1
Intel Core i7 920 @ 3.60GHz
12 GB DDR3 RAM
NVidia Quadro FX 3700
Matrox RT.X2 LE Capture Card
4 TB RAID 5


Return to posts index


Marcus Geduld
Re: Trouble with CreativeCow Tutorial
on Dec 23, 2009 at 10:45:45 pm

Okay, I found a few errors in your code:

At the top of SnowGlobeContainer.as, I see these lines:

public var startPos:Point = new Point;
public var mouseDownOffset:Point = new Point;
public var bounds:Rectangle = new Rectangle;

You need to change them so that the new operator calls constructor functions:

public var startPos:Point = new Point();
public var mouseDownOffset:Point = new Point();
public var bounds:Rectangle = new Rectangle();

I'd also make the class extend MovieClip instead of Sprite:

public class SnowGlobeContainer extends MovieClip

Unlike Sprites, MovieClips have internal timelines, so lines such as the following make much more sense for Movieclips:

this.addEventListener(Event.ENTER_FRAME, update);

Finally, you're getting as error that says "Cannot access a property or method of a null object reference.
at SnowGlobeContainer/updates()"

That's telling you something is wrong in the class called SnowGlobeContainer -- specifically in a function called update. So that gives you a place to look.

Even better, the error is telling you that there's a null object reference. Null means "nothing," so your code is trying to access an object where no object exists.

Objects are things with methods and properties. For instance, Math is an object. It has methods, such as Math.round() and properties, such as Math.PI. So you need to look in your code for things that are followed by dots, the way Math is always followed by a dot: Math.whatever.

I started looking at the objects you reference in update(). The first one is this. We can assume that this is okay, because it always is set to be the class itself. So this is SnowGlobeContainer, and we know that isn't null. The next two are parent and mouseDownOffset.

this.x = parent.mouseX - mouseDownOffset.x;
this.y = parent.mouseY - mouseDownOffset.y

I inserted a trace right before those two lines of code:

trace( parent, mouseDownOffset );

Here's what I saw in the Output Window:

[object HolidayCardTutorial] (x=-35, y=21)

Cool. So those objects aren't null. I continued to do traces for all your other objects: bounds, old, d, vel, pos and snowForeground. That last one, snowForeground, hit pay dirt: it traced out as null.

Note: when you do the traces, it's worth adding labels, such as...

trace("vel", vel);
trace( "snowForeground", snowForeground);

This makes it much easier to understand the output. For the latter, I got...

snowForeground null

So that's the locus of your problem. snowForeground is null. Why is snowForeground null? I'm not sure. I didn't read the tutorial, so I'm not sure what's supposed to be going on. But I do know that the code assumes that the variable snowForeground is holding an object. Yours isn't. Yours is holding nothing. Maybe you're missing a line of code that start "snowForeground = ..."

I sometimes get this error when I forget to call an object's constructor function. I'm supposed to write this:

var myObject : SomeType = new SomeType();

but I write this instead:

var myObject : SomeType;

Since you made the same mistake elsewhere, maybe you wrote...

var snowForeground : SomeType = new SomeType;

... forgetting the () at the end. It should be...

var snowForeground : SomeType = new SomeType();

Incidentally, I hope you didn't know about testing with trace(). It's fine if you didn't. Hopefully, knowing about this technique will help you from now on.

But I once worked with a guy who would call me into an office every day because he couldn't figure out how to kill off bugs.

I showed him how to trace out values to see what they were, but he still had the bugs. So I would take his code, do the traces, and easily solve the problems.

I couldn't figure out why he couldn't figure it out since traces made the problems so obvious. Turns out, he knew how to do the traces but couldn't be bothered. It was easier to have me do them.

His way of debugging was just to stare at the code for a long time, and then if he couldn't see the problem, he would give up (and pass the code on to me, knowing that I'd slog through it and trace everything out).

Real programmers never stare at code to solve problems. They run tests.

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index

Stacey Brocklebank
Re: Trouble with CreativeCow Tutorial
on Nov 8, 2013 at 7:48:24 pm

I'm in the process of doing this tutorial but when i lift up the globe it just stays attatched to the mouse rather than drop the globe? Don't know what to try!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]