PDA

View Full Version : [AS3] Inspectable parameter returns NULL


as3_novice
06-08-2009, 01:29 AM
I have a simple class that wraps a movieClip around a Video Object and I used the class to make a simple component.

package
{
import flash.media.Video;
import flash.net.*;
import flash.display.*;
public class VideoDisplay extends MovieClip
{
private var _videoName:String;
private var nc:NetConnection
private var ns:NetStream

[Inspectable(defaultValue = "")]
public function get videoName():String {
return _videoName;
}
public function set videoName(value:String):void {
_videoName = value;

}


public function VideoDisplay():void
{
startPlay();
}

public function startPlay()
{

var myVideo:Video = new Video();
addChild(myVideo);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
myVideo.attachNetStream(ns);
ns.play(_videoName);
trace(_videoName);

}
}//class
}// package

If I hard code the video path to "ns.play()" in the class file it works fine, but when I enter the value via the Component Inspector, the value returns NULL. What am I missing. Any help would be greatly appreciated.

as3_novice
06-08-2009, 05:58 AM
Ok, after doing some research I found that components parameters aren't set until after the INIT event is fired. Here is the code that worked. Not sure why this is not documented and why so many examples exist without adding that eventlistener. If anyone has an alternative means of doing this, please share :)


package
{
import flash.media.Video;
import flash.net.*;
import flash.display.*;
import flash.events.*



public class VideoDisplay extends MovieClip
{
private var _videoName:String;
private var nc:NetConnection
private var ns:NetStream

[Inspectable ()]
public function get videoName():String {
return _videoName;
}
public function set videoName(value:String):void {
_videoName = value;

}


public function VideoDisplay():void
{

loaderInfo.addEventListener(Event.INIT, onInit);

}

public function onInit(e:Event)
{

var myVideo:Video = new Video();
addChild(myVideo);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
myVideo.attachNetStream(ns);
ns.play(_videoName);


}
}//class
}// package

Rhuno
10-24-2009, 07:31 PM
Hey, awesome! I just ran into this problem; your init tip totally fixed it. Thanks! :)