对象为空的小错,找了一个下午也没找到

Greg_han 2012-07-16 04:24:14
//控制类: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;
}
}
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
雷恩特 2012-07-30
  • 打赏
  • 举报
回复
viewComponent.labName as Label
这里不能这样转吧
panxuan 2012-07-23
  • 打赏
  • 举报
回复
你要确保viewComponent.labName和viewComponent.imgPicture在使用之前创建完成。
lxglhxjll 2012-07-20
  • 打赏
  • 举报
回复
是不是因为viewComponent这个控件加载前就调用了这段代码

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧