# Why Dose video stop when I click another Button

**URL:** <https://forum.kirupa.com/t/why-dose-video-stop-when-i-click-another-button/318772>\
**Category:** flash\
**Created:** [January 30, 2011, 2:01am UTC](https://forum.kirupa.com/t/why-dose-video-stop-when-i-click-another-button/318772 "2011-01-30T02:01:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daragh\_c](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@daragh\_c](https://forum.kirupa.com/u/daragh_c)\
**Post date:** [January 30, 2011, 2:01am UTC](https://forum.kirupa.com/t/why-dose-video-stop-when-i-click-another-button/318772/1 "2011-01-30T02:01:02Z")

</div>

Hi Guys, I have the following code which loads a file from the FLASH MEDIA SERVER. (See below)

When I click on the playVid the video plays perfectly. The FMSConnection is an external AS3 file.  
The problem is that when I press the “run\_mc” the video suddenly stops.

The “run\_mc” loads an XML file. Im just wondering why my video stops when I load the XML ?. Many thanks, Daragh

Any help would be greatly appraciated.

the main time line;  
import com.teamSelection.teamSelectionLoader;  
import com.teamSelection.MyFlashFile;  
import com.teamSelection.createPlayerInfo;  
import com.teamSelection.FMSConnection;  
import flash.events.MouseEvent;  
import flash.events.Event;

// ----------------------------------------------------------------------------------  
// set up functions to display teamLineUp calls teamSelectionLoader class  
// ----------------------------------------------------------------------------------  
run\_mc.addEventListener(MouseEvent.CLICK,displayTeam);  
play\_mc.addEventListener(MouseEvent.CLICK,playVid);

function displayTeam(e:Event):void  
{  
var todaysTeam:teamSelectionLoader = new teamSelectionLoader();  
addChild(todaysTeam);  
todaysTeam.x = 400;  
todaysTeam.y = 200;  
}

function playVid(e:Event):void  
{  
var fmsCon:FMSConnection = new FMSConnection;  
addChild(fmsCon); \<------- this adds the class FMSConnection.  
}

\<\<CODE TO PLAY MOVIE FROM FMS\>\>  
package com.teamSelection{

```
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import fl.controls.Button;
import fl.controls.NumericStepper;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.AsyncErrorEvent;

import flash.events.NetStatusEvent;

public class FMSConnection extends MovieClip {

    public static const CONNECTED:String='connected';

    private var nc:NetConnection;
    public var vidID="video";
    public var consumerVideo:Video=new Video ;

    public function FMSConnection() {
        connect('rtmp://localhost/dvr/', 'DARAGH_C');
    }

    public function connect(url:String, username:String):void {

        // Create new net connection

        nc = new NetConnection();

        // Set this instance/class to receive callback functions.

        nc.client=this;

        // Call the connect method on the FMS and pass in the username.

        nc.connect(url, username);

        nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

        nc.addEventListener(IOErrorEvent.IO_ERROR, onIoError);

        nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);

    }

    private function onNetStatus(event:NetStatusEvent):void {

        if (event.info.code=="NetConnection.Connect.Success") {

            trace("Connected To server");

            // Dispatch event letting the application know it connected.

            dispatchEvent(new Event(FMSConnection.CONNECTED, true));

            trace("this is the BOMB !!!");
            var _ns=new NetStream(nc);
            _ns.client = new Object();
            addChild(consumerVideo);
            consumerVideo.attachNetStream( _ns );
            _ns.play( "video", 0, -1 );
            _ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

        } else {

            throw new Error("Failed to connect to server!");

        }

    }

    private function onIoError(event:IOErrorEvent):void {

        throw new Error("IO Error on connection.");

    }

    private function onSecurityError(event:SecurityErrorEvent):void {

        throw new Error("Security Error on connection.");

    }

    function asyncErrorHandler(event:AsyncErrorEvent):void {
        trace(event.text);
    }

}

```

}
