I've searched everywhere and can't find an answer to this question and I'll do my best to explain it.
I have 2 movieclips in my library, 'Bluknife' and 'cat' (It's an rpg game.). Both those movieclips are linked to as3 classes of the same names.
I know I can can add both of these items to the stage by having the following code in the document class:
var knife:BluKnife = new BluKnife();
stage.addChild(knife);
knife.x = stage.stageWidth / 2;
knife.y = stage.stageHeight / 2;
var ct:cat = new cat();
stage.addChild(ct);
ct.x = stage.stageWidth / 2;
ct.y = stage.stageHeight / 2;
However I don't want all this stuff to be in the document class, so I made another class that I want to use to call all of this stuff to the stage and named it callitems
:
package
{
import flash.display.MovieClip;
import flash.display.MovieClip;
import flash.display.Stage;
public class callitems extends MovieClip
{
public function callitems()
{
var knife:BluKnife = new BluKnife();
stage.addChild(knife);
knife.x = stage.stageWidth / 2;
knife.y = stage.stageHeight / 2;
var ct:cat = new cat();
stage.addChild(ct);
ct.x = stage.stageWidth / 2;
ct.y = stage.stageHeight / 2;
}
}
}
I'm just wondering how I would go about calling the callitems
class from my document class? I've tried a few things, like creating an instance of callitems
and adding it to the stage from the document class (which i wasn't surprised didn't work). Here's the function:
public function Engine()
{
var calling:callitems = new callitems();
stage.addChild(calling);
}
I got the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at callitems() at Engine()
The name of my document class is Engine