A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] AS2 How to hide a btn until the (preloaded) FLV has loaded?

  1. #1
    Member
    Join Date
    Apr 2006
    Posts
    72

    resolved [RESOLVED] AS2 How to hide a btn until the (preloaded) FLV has loaded?

    Hey Everyone,

    Trying to find a solution to this question, I've found lots of answers on making a button visable after a swf has loaded but not a flv. I am preloading an flv, well 20secs of it, then it starts playing. But I have a 'play' button on the stage and it sits there tempting people to hit it whilst the preloading bar works its magic preloading the flv. I want the button to be visable only after the flv has loaded or at least until it starts to play.
    I am a newbie to coding so please be kind and spell it out to me nice and clearly. :-)

    Thanks.

    Here's my code;

    stop();

    /////Btn controls/////
    btnPausePlay.onRelease = function() {
    ns.pause();
    }

    /////preload and play flv///////

    var duration:Number = 0;
    var ratio:Number = 0;
    var idTracking:Number = 0;
    var idLoading:Number = 0;

    var nc:NetConnection = new NetConnection();
    nc.connect(null);
    var ns:NetStream = new NetStream(nc);
    my_video.attachVideo(ns);
    ns.play("presenter.flv");
    //////change this (20) to th amount of seconds you want to laod before playing///
    ns.setBufferTime(15);


    ns.onMetaData = function(evt:Object):Void {
    duration = evt.duration;
    ratio = track._width / duration;
    idTracking = setInterval(updateKnob, 50);
    idLoading = setInterval(updateLoader, 50);
    };

    ns.onStatus = function(evt:Object):Void {
    if (this.time > 0 && this.time >= (duration - 0.5)) {
    gotoAndPlay(2)
    clearInterval(idTracking);
    delete this.onStatus;
    }
    };

    function updateKnob():Void {
    knob._x = track._x + ns.time * ratio;
    }

    knob.onPress = function():Void {
    clearInterval(idTracking);
    ns.pause(true);
    this.onMouseMove = function():Void {
    if (track._xmouse > 0 && track._xmouse < loader._width) {
    this._x = track._x + track._xmouse;
    }
    }
    }
    knob.onRelease = function():Void {
    delete this.onMouseMove;
    ns.seek((this._x - track._x) / ratio);
    ns.pause(false);
    idTracking = setInterval(updateKnob, 50);
    }
    knob.onReleaseOutside = knob.onRelease;

    function updateLoader():Void {
    loader._xscale = ns.bytesLoaded / ns.bytesTotal * 100;
    if (loader._xscale >= 98) {
    loader._xscale = 100;
    clearInterval(idLoading);
    }
    }

    track.onRelease = function():Void {
    if (this._xmouse > 0 && this._xmouse < loader._width) {
    clearInterval(idTracking);
    idTracking = setInterval(updateKnob, 50);
    ns.seek(this._xmouse / ratio);
    }
    }

    //////////////

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    replace your onStatus event handler with this:

    Code:
    //first hide your button
    btnPausePlay._visible = false;
    
    ns.onStatus = function(evt:Object):Void
    {
    	//Playback has stopped - movie has ended
    	if (evt.code == "NetStream.Play.Stop") 
            {
    		gotoAndPlay(2);
    		clearInterval(idTracking);
    	}
    	
    	//The buffer is full and the stream will begin playing.
    	if (evt.code == "NetStream.Buffer.Full") 
           {
    		//show your play button here
                   btnPausePlay._visible = true;
    	}
    	
    };

    for more onStatus properites have a look at http://livedocs.adobe.com/flash/9.0/...=00002020.html
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Member
    Join Date
    Apr 2006
    Posts
    72
    Fantastic, works a treat. I knew it had something to do with making the button false or something...cheers! :-)

Tags for this Thread

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