Beginner Question: controlling AS3 with Flex button


hi

i learning flex , as3 , hoping here tell me doing wrong. have basic flex application plays flv. purposes of application not want use videodisplay flex component, using as3 class play flv. here flex application:

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationcomplete="init()">
<mx:script>
<![cdata[
import flash.display.sprite;

public var _video:sprite = new simpleflv();

public function init():void
{
rawchildren.addchildat(_video,2);

}
public function playpause():void
{
ns.pause();
}
]]>
</mx:script>
<mx:button label="pause" click="playpause()" right="10" bottom="10"/>

</mx:application>

and here simpleflv class:

package
{
import flash.display.sprite;
import flash.net.netconnection;
import flash.media.video;
import flash.net.netstream;
import flash.events.netstatusevent;
import flash.display.stage;

public class simpleflv extends sprite
{
public function simpleflv(){
var nc:netconnection= new netconnection();
nc.connect(null);
var ns:netstream = new netstream(nc);
var vid:video = new video(320,240);
this.addchild(vid);
vid.attachnetstream(ns);
vid.smoothing=true;
ns.play("foo.flv");
ns.addeventlistener(netstatusevent.net_status,netstat);
function netstat(stats:netstatusevent):void
{
var netclient:object = new object();
netclient.onmetadata = function(meta:object):void
{
trace(meta.duration);
};

ns.client = netclient;
}
}
}
}

the video plays when run application without including pause button, following error when try run application coded above:

1120: access of undefined property ns

i know missing totally obvious here. how code flex button tell flv pause when press it?

thanks in advance

your ns variable's scope simpleflv class cannot access directly main application. put playpause function in simpleflv class package , can call function button this: click="_video.playpause()"

vygo


More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial