0
votes

I am new to working with Flash Builder and Flash Professional. I have a movie clip called myplayer that I created in Flash Professional, and I am trying to code some ActionScript for it in Flash Builder that will change its position on the stage, but I keep getting the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at level_1()

Here's the code:

package
{
    import flash.display.MovieClip;

    public class level_1 extends MovieClip
    {
        public function level_1()
        {
            myplayer.x=650;
            myplayer.y=350;
        }
    }
}

I know I am missing something, but I'm not sure what. Any advice?

1
Does a MovieClip exist on the stage with a instance name myplayer? - Marty
Yes. It exists in the second scene. Would it make a difference if the object is in the second rather than the first scene? - user3116503
Here, level_1 symbol probably needs linkage - there are two symbols in play: level_1 which references myplayer. - Jason Sturges
Jason, how would I create that linkage? - user3116503

1 Answers

1
votes

There are two symbols here: level_1 and myplayer. Naming convention for classes usually start with a capital letter; so, I'm going to refer to these types as Level1 and MyPlayer.

So, here's the scene:

  • Level1 is your game level
  • MyPlayer instance is a child of Level1

scene

The player of this level needs an instance name defined as myplayer.

myplayer is an instance of the MyPlayer class (ActionScript linkage).

player

Now from Flash Builder, our Level1 class may manipulate the child myplayer instance:

package {
    import flash.display.MovieClip;

    public class Level1 extends MovieClip {

        public var myplayer:MyPlayer;

        public function Level1() {
            super();

            myplayer.x = 650;
            myplayer.y = 350;
        }
    }
}

Flash CS5 example source code with Level1 ActionScript class at: http://labs.jasonsturges.com/stack-overflow/examples/referencing-flash-professional-object-in-flash-builder/