对象为空的小错,找了一个下午也没找到
//控制类:StartupCommand
public class StartupCommand extends SimpleCommand implements ICommand
{
public function StartupCommand()
{
super();
}
public override function execute(notification:INotification):void
{
//var appMainPage:MyFirstMVC=new MyFirstMVC();
var appMainPage:MyFirstMVC=notification.getBody() as MyFirstMVC;
facade.registerProxy(new DataProxy(DataProxy.PICTURE_LOAD));
facade.registerMediator(new PictureShowMediator(
PictureShowMediator.NAME,
{
imgPicture:appMainPage.imgPicture,
labName:appMainPage.labName
}
));
//facade.registerMediator();
sendNotification(AppFacade.GetUrl,appMainPage);
}
}
//中介者类
public class PictureShowMediator extends Mediator implements IMediator
{
public static const NAME:String="PictureShowMediator";
private var currentIndex:int=-1;
private var arr:Array=null;
public function PictureShowMediator(mediatorName:String=null, viewComponent:Object=null)
{
super(mediatorName, viewComponent);
var a:int =10;
}
override public function listNotificationInterests():Array
{
return [DataProxy.PICTURE_LOAD];
}
override public function handleNotification(notification:INotification):void
{
switch(notification.getName())
{
case DataProxy.PICTURE_LOAD:
arr = notification.getBody() as Array;
//var imgPicture:Image= viewComponent.imgPicture as Image;
trace( arr.length); //有正确数据
trace( (viewComponent.labName as Label).text.toString()); //TypeError: Error #1009: 无法访问空对象引用的属性或方法。 trace( (viewComponent.imgPicture as Image).source);//TypeError: Error #1009: 无法访问空对象引用的属性或方法。 break;
default:break;
}
}
[解决办法]
是不是因为viewComponent这个控件加载前就调用了这段代码
[解决办法]
你要确保viewComponent.labName和viewComponent.imgPicture在使用之前创建完成。
[解决办法]
viewComponent.labName as Label
这里不能这样转吧