简体   繁体   中英

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:

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

and I have to determine which peer I'm sending to by their ID such as "peerID1234"

I know that you can check the peerID of the stream by doing:

sendStream.peerStreams[0]["farID"]

how can I make my send stream function know to use the array index where the peerID is?

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. 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.

There's some other approaches mentioned here but they are just different styles of doing the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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