简体   繁体   English

如何根据索引对象内的值获取特定的数组索引? 柔性

[英]how do i get the specific array index based on value inside the index's object? flex

So, for sending to individual streams we have to reference the connected netStream we want to send to in some way like this: 因此,要发送到各个流,我们必须以如下方式引用要发送到的已连接netStream:

sendStream.peerStreams[0].send("MyFunction",param1,param2);

and I have to determine which peer I'm sending to by their ID such as "peerID1234" 并且我必须通过他们的ID(例如“ peerID1234”)来确定要发送给哪个对等对象

I know that you can check the peerID of the stream by doing: 我知道您可以通过执行以下操作来检查流的peerID:

sendStream.peerStreams[0]["farID"]

how can I make my send stream function know to use the array index where the peerID is? 如何使我的发送流函数知道使用peerID所在的数组索引?

so basically it could be like: 所以基本上可以像这样:

sendStream.peerStreams[where peerStreams[]["farID"] == peerID].send("MyFunction",param1,param2);

Sounds like you'll have to loop through the peerStreams array to find the object that has the right farID property value. 听起来您必须遍历peerStreams数组以查找具有正确farID属性值的对象。 Basically you are searching through the array for an item with a specific property value. 基本上,您正在数组中搜索具有特定属性值的项目。 There is no built-in functionality for this. 没有内置功能。 But you can do it with a simple loop. 但是您可以通过一个简单的循环来实现。 Something like this: 像这样:

var correctStream:Object = null;
for each (var stream:Object in sendStream.peerStreams) {
   if (stream["farId"] == peerId) {
     correctStream = stream;
     break;
   }
}
correctStream.send("MyFunction",param1,param2);

Note that I don't know what the data type is for the peerStreams object so I just typed it as Object in my example. 请注意,我不知道peerStreams对象的数据类型是什么,因此在示例中我只是将其键入为Object

There's some other approaches mentioned here but they are just different styles of doing the same thing. 这里提到了其他一些方法但是它们只是做同一件事的风格不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM