The problem was when building the class I took for granted that NetStream referenced against the client object and invoked the callback function from the object when a callback took place. But the fact is that when you assign a client object to netstream it saves a reference to the callback function, not the client object itself. So it was clear why my class didnt work.
So I patched it up with the proxy implementation getProperty (it looks a bit hackish but it does the trick).
flash_proxy override function getProperty(name:*) : * { var qName:QName = name as QName; return function ( ...args ) : void { flash_proxy::callProperty( qName, args[0] ); } }
I also noticed that in my usage example I used an object instead of the NetStreamClientEvent. So this is how you "really" use it.
// create a instance client = new NetStreamClient(); // assign the client netStream.client = client; // then just add listeners to the client client.addEventListener( NetStreamClientEvent.CUE_POINT, client_cuePointHandler ); // an example of the handler function function client_cuePointHandler ( event:NetStreamClientEvent ) : void { // the info object holds the original data var info:Object; info = event.arguments[0]; trace( [info.name, info.time, info.cuetype] ); }
View the class below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Licensed under the MIT License | |
* | |
* Copyright (c) 2009-2010 Martin Sandström | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy of | |
* this software and associated documentation files (the "Software"), to deal in | |
* the Software without restriction, including without limitation the rights to | |
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
* the Software, and to permit persons to whom the Software is furnished to do so, | |
* subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in all | |
* copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
* | |
* http://www.marteinn.se | |
* http://www.opensource.org/licenses/mit-license.php | |
* | |
*/ | |
package se.marteinn.net.client | |
{ | |
import flash.events.Event; | |
import flash.events.EventDispatcher; | |
import flash.events.IEventDispatcher; | |
import flash.utils.Proxy; | |
import flash.utils.flash_proxy; | |
import nl.base42.log.Logger; | |
dynamic public class NetStreamClient extends Proxy implements IEventDispatcher | |
{ | |
protected var dispatcher:EventDispatcher; | |
public function NetStreamClient ( ) : void | |
{ | |
dispatcher = new EventDispatcher(this); | |
} | |
// this is a catch-all method witch dispatches events | |
flash_proxy override function callProperty( name:*, ...args ):* | |
{ | |
var qName:QName = name as QName; | |
switch( qName.localName ) | |
{ | |
case NetStreamClientEvent.XMP_DATA: | |
case NetStreamClientEvent.META_DATA: | |
case NetStreamClientEvent.CUE_POINT: | |
case NetStreamClientEvent.IMAGE_DATA: | |
case NetStreamClientEvent.TEXT_DATA: | |
case NetStreamClientEvent.DRM_CONTENT_DATA: | |
case NetStreamClientEvent.PLAY_STATUS: | |
dispatchEvent( new NetStreamClientEvent( qName.localName, args, qName.localName ) ); | |
break; | |
default: | |
dispatchEvent( | |
new NetStreamClientEvent( NetStreamClientEvent.UNKNOWN_CALL, args, qName.localName ) ); | |
break; | |
} | |
} | |
flash_proxy override function getProperty(name:*) : * | |
{ | |
var qName:QName = name as QName; | |
return function ( ...args ) : void | |
{ | |
flash_proxy::callProperty( qName, args[0] ); | |
} | |
} | |
// inherited methods for EventDispatcher | |
public function addEventListener( type:String, listener:Function, useCapture:Boolean = false, priority:int = 0 | |
, useWeakListener:Boolean = true ) : void | |
{ | |
dispatcher.addEventListener( type, listener, useCapture, priority, useWeakListener ); | |
} | |
public function dispatchEvent( event:Event ) : Boolean | |
{ | |
return dispatcher.dispatchEvent( event ); | |
} | |
public function hasEventListener( type:String ) : Boolean | |
{ | |
return dispatcher.hasEventListener( type ); | |
} | |
public function removeEventListener( type:String, listener:Function, useCapture:Boolean = false ) : void | |
{ | |
dispatcher.removeEventListener( type, listener, useCapture ); | |
} | |
public function willTrigger( type:String ) : Boolean | |
{ | |
return dispatcher.willTrigger( type ); | |
} | |
} | |
} |