dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [RESOLVED] Timer date help!

  1. #1
    Senior Member
    Join Date
    Oct 2005
    Posts
    198

    resolved [RESOLVED] Timer date help!

    Hi,

    I'm having problems with the NetStream object in terms of ending a video---I am being told that the _stream.time object is null.

    Code:
    	private var vidConnectionCommercial:NetConnection;
    		private var videoCommercial:Video;
    		private var stCommercial:SoundTransform;
    		private var customClientCommercial:Object = new Object();
    		private var _duration:uint;
    		var _stream:NetStream;	
    
    public function vidDisplayCommercial() {
    			trace("video call");
    			var videoCommercial=new Video(760,477);
    			_duration=0;
    			var vidConnectionCommercial=new NetConnection();
    			vidConnectionCommercial.connect(null);
    			var _stream:NetStream=new NetStream(vidConnectionCommercial);
    			_stream.play("eas.f4v");
    			var customClientCommercial:Object=new Object();
    			customClientCommercial.onMetaData=metaDataHandler;
    			_stream.client=customClientCommercial;
    			_stream.bufferTime=5;
    			_stream.addEventListener(NetStatusEvent.NET_STATUS, onStatusCommercial,false,0, true);
    			videoCommercial.attachNetStream(_stream);
    			commercials.addChild(videoCommercial);
    			commercials.soundTransform=new SoundTransform(1);
    			var stCommercial:SoundTransform=new SoundTransform();
    			stCommercial.volume=1;
    			_stream.soundTransform=stCommercial;
    			addEventListener(Event.ENTER_FRAME, onEnterFrames,false,0,true);
    			_stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandlerCommercial,false,0, true);
    
    			function asyncErrorHandlerCommercial(evt:AsyncErrorEvent):void {
    				//ignore error
    			}
    		}
    		public function onStatusCommercial(e:Object):void {
    			trace(e.info.code);
    			if (e.info.code == "NetStream.Play.Start" &&
    			   e.info.code == "NetStream.Buffer.Full") {
    				trace("loaded");
    			} else if (e.info.code == "NetStream.Buffer.Empty") {
    				trace("empty");
    				}
    			if (e.info.code=="NetStream.Play.Stop") {
    				trace("stopped");
    				}
    	}
    		private function metaDataHandler(data:Object):void {
    			_duration=data.duration;
    			trace(_duration, "duration metaHandler");
    	}
    		private function onEnterFrames(event:Event):void {
    			if (_duration>0) {
    				trace(_duration, "onFrames duration");
    				if (_stream.time>=_duration) {
    					trace("COMPLETE");
    					videoCommercial.clear();
    					commercials.removeChild(videoCommercial);
    
    				}
    			}
    		}
    Could someone tell me how to determine the current NetStream time?

    Thanks,
    ---Yvette
    Last edited by yvillicana; 10-15-2009 at 04:56 PM.

  2. #2
    Member
    Join Date
    Oct 2009
    Location
    Ontario
    Posts
    98
    You aren't instantiating the _stream object.

    In your vidDisplayCommercial function, you need to create a new instance of the NetStream class and assign it to _stream.

    Code:
    _stream = new NetStream(); // I am not sure what is required for this constructor
    You cannot use a function like "play" because no such function exists in an object that has not been instantiated. =)

  3. #3
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    Hi Nidht,

    I believe I have that in the code:
    var _stream:NetStream=new NetStream(vidConnectionCommercial);

    Im not having a problem with playing the video. The problem I have is that Im trying to determine when the video ends by getting the current _stream.time and comparing it to the stream duration...Everything works except the _stream.time....

    Help?
    Thanks,
    ---Yvette

  4. #4
    Member
    Join Date
    Oct 2009
    Location
    Ontario
    Posts
    98
    Sorry, missed that one.

    However, the error message still leads me to believe that when you're accessing the _stream object from within that onEnterFrames event listener, it's either not an instance of NetStream, or the "time" property does not exist in the class.

  5. #5
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    Thanks Nidht,

    Yeah, I have no idea--I referenced help on line and it seems as though its a property
    http://livedocs.adobe.com/flash/9.0/...NetStream.html
    and dont know why it wouldnt be instantiated. Thats for the Flash player 9 however was it changed for the Flash player 10?
    Does anyone know how to get the current NetStream time?

    Thanks,
    ---Yvette

  6. #6
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    Hi,

    It seems to be that its not instantiated when the onEnterFrames function is called. How could I fix that?

    Thanks,
    ---Yvette

  7. #7
    Member
    Join Date
    Oct 2009
    Location
    Ontario
    Posts
    98
    Ah! You aren't using the class variable for _stream because you have "var" in front of its declaration.

    Code:
    var _stream:NetStream = new NetStream(vidConnectionCommercial);
    This means it is re-declared as a variable whose scope exists only within that function.

    I was able to spot this once I had massaged your code a little bit and spaced some things out. It's hard to follow when it's all crammed together. Neat code means faster bug-tracking. =)

    If you like, I can paste the same code here after I was done moving it around. Otherwise, I hope this works!

  8. #8
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    Thanks so much Nidht!!! That did it.

    ---Yvette
    Last edited by yvillicana; 10-15-2009 at 08:11 PM.

  9. #9
    Member
    Join Date
    Oct 2009
    Location
    Ontario
    Posts
    98
    No problem! =)

    Please resolve this thread by using the Thread Tools menu above and to the right of your initial post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center