通过P2P Flex发送ArrayCollection [英] Sending ArrayCollections via P2P Flex
问题描述
我对带flex的P2P有疑问. 使用P2P在两个应用程序之间传递数据时.我收到以下错误:
I have a question regarding P2P with flex. When passing data between two applications using P2P. I get the following error:
warning: unable to bind to property 'piece' on class 'Object' (class is not an IEventDispatcher)
我已经花了几天时间使用Google尝试寻找解决方案,但是无法消除该错误.我尝试使用ObjectUtils,直接分配,并在括号内使用ObjectUtils创建新的ArrayCollection,但仍然无法解决问题.
I've spent a few days using Google to try and find a solution, but a can't get rid of that error. I've tried using ObjectUtils, direct assignment, and creating a new ArrayCollection WITH the ObjectUtils inside the parenthesis and still can't solve the problem.
代码用途:
->两个用户通过P2P连接
-> 1st 用户可以操纵图片(作为对象存储在数组集合中).
-> 1st 用户将更新的ArrayCollection(具有更改的图片)发送给 2nd 用户
-> 第二个用户的ArrayCollection已更新,现在可以看到受操纵的图片
Purpose of code:
-> Two users connect via P2P
-> 1st user can manipulate pictures (stored as objects in the array collection).
-> 1st user sends updated ArrayCollection (with changed pictures) to 2nd user
-> 2nd user's ArrayCollection gets updated and now sees manipulated pics
就我对Flex的了解(这是很新的东西),我正确地绑定了需要绑定的内容.使用弹出窗口和跟踪,我可以看到ArrayCollection中的数据已正确复制,但只是不想显示.
As far as my knowledge of Flex goes (fairly new to it), I properly Binded what needed to be binded. Using pop-ups and trace, I was able to see that the data from the ArrayCollection gets copied in properly, but it just doesn't want to display.
这是我的代码的一些摘要:
Here are some snippets of my code:
[Bindable]
public var taken:ArrayCollection = new ArrayCollection ([
new picLayout(1,'sky.png'),
new picLayout(2,'bird.png')
])
public function receiveSomeData(pass:ArrayCollection):void
{
// Want to replace current version of variable "taken" with
// the one passed in using P2P
this.taken= new ArrayCollection(pass.source);
}
public function sendSomeData(free:ArrayCollection):void
{
sendStream.send("receiveSomeData",free);
}
<s:Button click="sendSomeData(taken)" label="Update" />
感谢您的帮助和时间!
推荐答案
我想出了问题所在以及解决方法-部分感谢这些页面:
无法绑定警告:类不是IEventDispatcher
弹性警告:无法绑定到类对象"上的属性"foo"(类不是IEventDispatcher)
I figured out what the problem was and how to fix it - with partial thanks to these pages:
Unable to Bind warning: class is not an IEventDispatcher
Flex Warning: Unable to bind to property 'foo' on class 'Object' (class is not an IEventDispatcher)
我知道该信息已成功发送到另一个对等方,但是问题是ArrayCollection的 INSIDE对象没有被绑定.
I knew that the information was being successfully sent to the other peer, but the problem was that the objects INSIDE the ArrayCollection weren't made bindable.
我对这个问题的解决方法如下:
My solution to the problem was as follows:
-
创建一个循环,该循环发送ArrayCollection中的每个对象以及一个 index ,该索引告诉您ArrayCollection中的值是什么正在流式传输.
Create a loop that sends each object in the ArrayCollection along with an index that tells you what value in the ArrayCollection you are streaming.
现在,由于您正在流式处理"数据,因此请使用 setItemAt()函数将 first 字段设置为"",覆盖当前的ArrayCollection.新的ObjectProxy(passedObject)"和 second 字段作为 passedIndex (注意): ObjectProxy()函数会强制传递对象可绑定.
Now, since you are "streaming" the data, overwrite the current ArrayCollection, using the setItemAt() function with first field as "new ObjectProxy(passedObject)" and the second field as the passedIndex (Note): the ObjectProxy() function forces the passed object to be bindable.
这是我的代码的更新片段:
Here is an updated snippet of my code:
[Bindable]
public var takenPics:ArrayCollection = new ArrayCollection ([
new picLayout(1,'sky.png'),
new picLayout(2,'bird.png')
])
private function sendSomeData(data:Object, index:int):void
{
sendStream.send("receiveSomeData",data,index);
}
private function receiveSomeData(passedPic:Object,ix:int):void
{
// ObjectProxy needed to force a bindable object
takenPics.setItemAt(new ObjectProxy(passedPic),ix);
}
public function sendPictures():void
{
// ix < 2 because size of ArrayCollection is 2
for (var ix:int = 0; ix<2; ix++)
sendSomeData(takenPics[ix],ix);
}
这篇关于通过P2P Flex发送ArrayCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!