-
Please help me
I want to load external swf but it’s give me error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main()[E:\MacMenuSource\Main.as:23]
the code is
package{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.display.Loader;
public class Main extends Sprite{
private var _loader:Loader = new Loader();
public function Main():void{
mc_star.addEventListener(MouseEvent.CLICK,buttonCl ick);
mc_gear.addEventListener ( MouseEvent.CLICK , buttonClick );
mc_apple.addEventListener(MouseEvent.CLICK,buttonC lick);
mc_photo.addEventListener(MouseEvent.CLICK,buttonC lick);
mc_buy.addEventListener(MouseEvent.CLICK,buttonCli ck);
mc_contact.addEventListener(MouseEvent.CLICK,butto nClick);
//_loader=new Loader();
addChild(_loader);
}
private function buttonClick(e:MouseEvent):void{
var url:URLRequest=new URLRequest();
switch(e.target.name){
case “mc_star”: url.url=”bg2.swf”; break;
//case “mc_gear”: url.url = “bg2.swf”; break;
//case “mc_apple”: url.url=”bg4.swf”; break;
//case “mc_photo”: url.url=”bg5.swf”; break;
//case “mc_buy”: url.url=”bg6.swf”; break;
//case “mc_contact”: url.url=”bg7.swf”; break;
}
_loader.load(url);
}
}
}
the line 23 is
mc_star.addEventListener(MouseEvent.CLICK,buttonCl ick);
if you want to see the fla download it from this link
http://mir.cr/0BJTHHF4
thank you
-
Error1009 means your trying to access something that isn't instantiated yet. Make sure your movie clips all have instance names.
-
Senior Member
Maybe you have conflicting class references. Try renaming the Main class or the class of the "bg2.swf". Below is an example of loading external SWF's.
Code:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(“MouseActions.swf”);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
Code taken from http://www.iheartactionscript.com/lo...al-swf-in-as3/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|