Search code examples
actionscript-3flashflash-builder

Referencing Flash Professional Object in Flash Builder Actionscript


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?


Solution

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