这有什么AS3 $ C $下加载外部SWF的空对象错误? [英] What is the null-object error with this AS3 code for loading external swf?
问题描述
我得到一个空对象错误,当我加入鼠标事件侦听器登录按钮。 (看看构造函数中的评论)
我使用Flash CS6,和对象,如logInbutton和screen_log_in是从FLA文件实例名称。这这里的。至于文件。
错误我得到的是:
类型错误:错误#1009:无法访问空对象引用的属性或方法。
在行动:: indexPage()
我的AS3 code:
包操作
{
进口的flash.display.MovieClip;
进口对象类型:flash.events.Event;
进口flash.events.ProgressEvent;
进口flash.events.IEventDispatcher;
进口flash.net.URLRequest;
进口flash.display.Loader;
进口fl.motion.MotionEvent;
进口flash.events.MouseEvent;
公共类indexPage扩展影片剪辑
{
公共职能indexPage():无效
{
loadSWF(http://mathlympics.cu.cc/loginsystem.swf);
//这是这是造成错误的行
//当我评论了错误消失
logInButton.addEventListener(MouseEvent.CLICK,goToLogIn);
}
VAR _swfLoader:装载机;
VAR _swfContent:影片剪辑;
公共职能loadSWF(路径:字符串):无效
{
VAR _REQ:的URLRequest =新的URLRequest();
_req.url =路径;
_swfLoader =新的Loader();
setupListeners(_swfLoader.contentLoaderInfo);
_swfLoader.load(_REQ);
}
功能setupListeners(调度员:IEventDispatcher,请):无效
{
dispatcher.addEventListener(引发Event.COMPLETE,addSWF);
}
功能addSWF(事件:事件):无效
{
event.target.removeEventListener(引发Event.COMPLETE,addSWF);
event.target.removeEventListener(使用ProgressEvent.PROGRESS,preloadSWF);
_swfContent = event.target.content;
screen_log_in.addChild(_swfContent);
}
功能unloadSwf():无效
{
_swfLoader.unloadAndStop();
screen_log_in.removeChild(_swfContent);
_swfContent = NULL;
}
功能goToLogIn(E:MouseEvent)方法:无效
{
unloadSwf();
screen_log_in.loadSWF(http://mathlympics.cu.cc/loginsystem.swf);
}
功能goToRegister(E:MouseEvent)方法:无效
{
unloadSwf();
screen_log_in.loadSWF(http://mathlympics.cu.cc/register.swf);
}
}
}
我只是要回答我的问题对未来的游客。问题的原因我已经注意到能够找出,但我想通了就是如何解决它。我只是复制粘贴我的文档类code的帧和它的作品精美绝伦那里。
I am getting a null object error when I add the mouse event listener for the log in button. (Look at the comments in the constructor)
I am using Flash CS6, and objects such as logInbutton and screen_log_in are instance names from the .fla file. This here is the .as file.
Error I get is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at actions::indexPage()
My AS3 code:
package actions
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IEventDispatcher;
import flash.net.URLRequest;
import flash.display.Loader;
import fl.motion.MotionEvent;
import flash.events.MouseEvent;
public class indexPage extends MovieClip
{
public function indexPage():void
{
loadSWF("http://mathlympics.cu.cc/loginsystem.swf");
//THIS IS THE LINE WHICH IS CAUSING THE ERROR
//WHEN I COMMENT IT OUT THE ERROR IS GONE
logInButton.addEventListener(MouseEvent.CLICK, goToLogIn);
}
var _swfLoader:Loader;
var _swfContent:MovieClip;
public function loadSWF(path:String):void
{
var _req:URLRequest = new URLRequest();
_req.url = path;
_swfLoader = new Loader();
setupListeners(_swfLoader.contentLoaderInfo);
_swfLoader.load(_req);
}
function setupListeners(dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener(Event.COMPLETE, addSWF);
}
function addSWF(event:Event):void
{
event.target.removeEventListener(Event.COMPLETE, addSWF);
event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
_swfContent = event.target.content;
screen_log_in.addChild(_swfContent);
}
function unloadSwf():void
{
_swfLoader.unloadAndStop();
screen_log_in.removeChild(_swfContent);
_swfContent = null;
}
function goToLogIn(e:MouseEvent):void
{
unloadSwf();
screen_log_in.loadSWF("http://mathlympics.cu.cc/loginsystem.swf");
}
function goToRegister(e:MouseEvent):void
{
unloadSwf();
screen_log_in.loadSWF("http://mathlympics.cu.cc/register.swf");
}
}
}
I am just going to answer my question for the future visitors. The cause of problem I have note been able to figure out but what I have figured out is how to get around it. I simply copy pasted my code from document class to the frames and it works absolutely fine there.
这篇关于这有什么AS3 $ C $下加载外部SWF的空对象错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!