I am trying to write a simple action to get a button to load an eternal swf onto the stage, or preferably into a target movie clip. My current understanding of what is needed to accomplish this is as follow:
- create a new Loader
- Create an even listener for each button to catch the Mouse.CLICK and run custom function.
- Create a new URLRequest and Loader load the URLrequest. (I am trying to apply this to each button so they will load unique swf’s)
- Have the stage addChild of my Loader.
This is what I have for that so far:
stop();
home_btn.addEventListener(MouseEvent.CLICK, home_btnclick)
function home_btnclick(e:MouseEvent):void
{
var loader_mc : Loader = new Loader();
var urlRequest : URLRequest = new URLRequest("home.swf");
loader_mc.load(urlRequest);
addChild(loader_mc);
}
portfolio_btn.addEventListener(MouseEvent.CLICK, portfolio_btnclick)
function portfolio_btnclick(e:MouseEvent):void
{
var loader_mc : Loader = new Loader();
var urlRequest : URLRequest = new URLRequest("portfolio.swf");
loader_mc.load(urlRequest);
addChild(loader_mc);
}
contact_btn.addEventListener(MouseEvent.CLICK, contact_btnclick)
function contact_btnclick(e:MouseEvent):void
{
var loader_mc : Loader = new Loader();
var urlRequest : URLRequest = new URLRequest("contact.swf");
loader_mc.load(urlRequest);
addChild(loader_mc);
}
When I preview my project an error is returned :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at EclipticVisualsindex_fla::MainTimeline/frame61()
My guess is that the external swf has not been loaded before it has been called? Any help on this will be greatly appreciated! Thanks!!