onSeekPoint weirdness

2019-08-03 13:38发布

问题:

I have a NetStream which is put into data generation mode properly... everything works fine and I get onSeekPoint() events when I do something like the following:

EXAMPLE 1

public function setupStream() {
     netStream.client = {};
     netStream.client.onSeekPoint = this.onSeekPoint;
     netStream.client.onMetaData = this.onMetaData;
}

public function onSeekPoint(... args) {...}
public function onMetaData(... args) {...}

However, instead of keeping it all in that parent class, I need to create a new class for the client which also has that onSeekPoint. It doesn't work. Strangely, the onMetaData callback does... it's something like this:

EXAMPLE 2

package {
   public class CustomClient {
       public function CustomClient() {
       }
       public function onSeekPoint(... args) {...}
       public function onMetaData(... args) {...}
   }
}

public function setupStream() {
   var myClient:CustomClient = new CustomClient();
   netStream.client = CustomClient;
}

I thought that maybe there's some small issue I missed- but what's really freaking me out, is that this fully works properly...

EXAMPLE 3

package {
   public class CustomClient {
       public function CustomClient() {
       }
       public function onSeekPoint(... args) {...}
       public function onMetaData(... args) {...}
   }
}

public function setupStream() {
   var myClient:CustomClient = new CustomClient();
   netStream.client = {};
   netStream.client.onSeekPoint = myClient.onSeekPoint;
   netStream.client.onMetaData = myClient.onMetaData
}

I guess "if it ain't broke don't fix it" might apply here, but I'm a little worried letting some code I don't understand go, and afraid it might come back to bite me when I least expect it ;)

My questions are:

  1. Why doesn't the second example work for seekPoints?
  2. Ok then- why does the second example work for metaData?
  3. Why does the third example fix everything?

EDIT: In case it's unclear, the different classes are correctly in separate files, etc. They're just combined in the examples here to make it easier to digest

回答1:

In your second example you have this:

var myClient:CustomClient = new CustomClient();
netStream.client = CustomClient;

But shouldn't it be something like this:

var myClient:CustomClient = new CustomClient();
netStream.client = myClient;