Flex - 在收到标准事件后调度自定义事件
我正在处理用户在以下代码中选择的多个文件的 FileReferenceList.fileList[] 。
for (i=0;i < event.currentTarget.fileList.length; i ++){
fileByteData = new ByteArray();
fileByteData = (event.currentTarget.fileList[i].data as ByteArray);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, checkImageDimensions);
loader.loadBytes(fileByteData);
}
我需要将 i 传递到 checkImageDimensions 来跟踪哪个图像是哪个,我可以轻松地创建一个自定义事件,但我需要这个在正确的时间开火。 理想情况下我可以做这样的事情..
var myEvent:CustomEvent = new CustomEvent(i);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.dispatchEvent(CustomEvent))
但说实话,我不确定如何继续...
任何人都可以帮助我吗? 谢谢!
I am processing a FileReferenceList.fileList[] of multiple files a user selects in the following code..
for (i=0;i < event.currentTarget.fileList.length; i ++){
fileByteData = new ByteArray();
fileByteData = (event.currentTarget.fileList[i].data as ByteArray);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, checkImageDimensions);
loader.loadBytes(fileByteData);
}
I need to pass i into checkImageDimensions to keep track of which image is which, I can easily enough create a custom event, but I need this to fire at the right time. Ideally I could do something like this..
var myEvent:CustomEvent = new CustomEvent(i);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.dispatchEvent(CustomEvent))
But to be honest, I am unsure of how to proceed...
Can anyone help me out? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个侦听器函数 - 函数调用是不够的。 将类名传递给
dispatchEvent
也不起作用。 以下是具体操作方法。请注意,如果事件中所需的只是字符串类型,则不一定需要自定义事件类。 在这种情况下,您可以简单地使用 Event 类:
Edit:如果您真的很懒,但仍然想通过事件传递值,则可以使用
DinamicEvent
类:当然,声明自己的错误类更干净且不易出错。
You need to make a listener function - a function call does not suffice. Passing a class name to
dispatchEvent
does not work either. Here's how to do it.Note that you don't necessarily need a custom event class, if all you need in the event is a type string. You can simply use the Event class in this case:
Edit: If you're really lazy, but still want to pass values with the event, you can use the
DinamicEvent
class:Of course, it is cleaner and less error prone to declare your own error class.