触发 MouseEvent 的dispatchEvent 不起作用
我将相同的图像(播放按钮)添加到影片剪辑中,稍后按下时切换状态并播放视频。
我想要完成的是自动切换默认图像,因为该视频是自动播放的。
//Setup thumb Container
thumbs = new Sprite();
thumbs.addEventListener (MouseEvent.CLICK, playVideo);
thumbs.x = thumbs_x;
thumbs.y = thumbs_y;
thumbs.buttonMode = true;
main_container.addChild (thumbs);
//Call Function that gets all the thumbs using loader and adds it to the thumb movieClip
callThumbs ();
setDefaultButton ();
function callThumbs ():void {
for (var i:Number = 0; i < my_total; i++) {
var thumb_url = my_videos[i].@THUMB;
var thumb_loader = new Loader();
thumb_loader.name = i;
trace(thumb_loader.name);
thumb_loader.load (new URLRequest(root_path + thumb_url));
thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
thumb_loader.y = (thumb_height+210)*i;
}
function thumbLoaded (e:Event):void {
var my_thumb:Loader = Loader(e.target.loader);
thumbs.addChild (my_thumb);
}
function setDefaultButton ():void {
thumbs.getChildAt(0).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
//or
thumbs.getChildByName('0').dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
因此,这与单击第一张图像的作用相同,但它是自动发生的。
这是我的错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at LowesPlayerCS4_fla::MainTimeline/setDefaultButton()
at LowesPlayerCS4_fla::MainTimeline/processXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I am adding the same image (play button) to a movie clip those images later when pressed toggle states and play a video.
What I am trying to accomplish is automatically toggle the default image since that video is playing automatically.
//Setup thumb Container
thumbs = new Sprite();
thumbs.addEventListener (MouseEvent.CLICK, playVideo);
thumbs.x = thumbs_x;
thumbs.y = thumbs_y;
thumbs.buttonMode = true;
main_container.addChild (thumbs);
//Call Function that gets all the thumbs using loader and adds it to the thumb movieClip
callThumbs ();
setDefaultButton ();
function callThumbs ():void {
for (var i:Number = 0; i < my_total; i++) {
var thumb_url = my_videos[i].@THUMB;
var thumb_loader = new Loader();
thumb_loader.name = i;
trace(thumb_loader.name);
thumb_loader.load (new URLRequest(root_path + thumb_url));
thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
thumb_loader.y = (thumb_height+210)*i;
}
function thumbLoaded (e:Event):void {
var my_thumb:Loader = Loader(e.target.loader);
thumbs.addChild (my_thumb);
}
function setDefaultButton ():void {
thumbs.getChildAt(0).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
//or
thumbs.getChildByName('0').dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
So this does the same thing as click the first image but it happens automatically.
THIS IS MY ERROR:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at LowesPlayerCS4_fla::MainTimeline/setDefaultButton()
at LowesPlayerCS4_fla::MainTimeline/processXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将thumb_Loader添加到callThumbs中的显示列表中,而不是thumbLoaded中。
Try adding the thumb_Loader to the Display List in callThumbs rather than thumbLoaded.