StartDrag constrain to Rectangle

hi there
please can somoe help with this little problem, I have a demo file that I am trying to created a constraint to a rectangle. I have the startDrag working and I am trying to constrain a square to the movie size of 600x400.
I have been searching online help files but I can not for the life of me get it to work, would someone beable to put me out of my misery. I have attached the demo file I am working with but I will also post my script here for thoughs who prefer that.....going crazy, can any help, does it have to be this difficult...aarrrghh!!
this is what I thought I could simply add
animation", false, 0, 0, 300, 300);
but know joy....anyone help   : (
my code:
////Button Listeners/////////////
// BtnNav listeners
btnNav.addEventListener(MouseEvent.ROLL_OVER, btnNavOver);
btnNav.addEventListener(MouseEvent.ROLL_OUT, btnNavOut);
btnNav.addEventListener(MouseEvent.CLICK, btnNavDown);
// change: made the graphic "red shape" a movieClip and made redShape and closeBtn a movieClip
// added this listener to that button...
animation.redShape.closeBtn.addEventListener(MouseEvent.MOUSE_UP,closeUp);
////for the click and drag
animation.addEventListener(MouseEvent.MOUSE_DOWN,dragStart);
animation.addEventListener(MouseEvent.MOUSE_UP,dragStop);
///////button 1 function ///////////
// BtnNav Over function
function btnNavOver(event:MouseEvent):void {
btnNav.gotoAndPlay("over"); // go into btn1 movieclip and play the over frame label
// BtnNav Out function
function btnNavOut(event:MouseEvent):void {
btnNav.gotoAndPlay("out"); // go into btn1 movieclip and play the out frame label
//animation.stopDrag();
// BtnNav Down function
function btnNavDown(event:MouseEvent):void {
// change: tell the movieClip animation to play...
animation.play();
//this.gotoAndPlay("animation");
// play any frame label in any movieclip
// change: added this function for the close button to have it play the animation clip...
function closeUp(event:MouseEvent):void {
animation.play();
/////for the click and drag////
function dragStart(event:MouseEvent):void {
    event.currentTarget.startDrag();
//("animation", false, 0, 0, 300, 300);
function dragStop(event:MouseEvent):void {
    stopDrag();

I'm afraid it does not get simpler than this (AFAIK).
Here's the (stripped down version) you could use:
import flash.geom.Rectangle;
////Button Listeners/////////////
////for the click and drag
animation.addEventListener(MouseEvent.MOUSE_DOWN,dragStart);
animation.addEventListener(MouseEvent.MOUSE_UP,dragStop);
/////for the click and drag////
function dragStart(event:MouseEvent):void {
    event.currentTarget.startDrag( false, new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight ) );
function dragStop(event:MouseEvent):void {
    stopDrag();
The rectangle created defines the bounds in which the movieClip "animation" is dragged.
The registrationpoint of the movieClip "animation" will remain within these bounds. If you want the whole clip to remain within these bounds easiest is to have the registrationpoint in the middle of the clip and defin the rect like:
    var d:DisplayObject = DisplayObject( event.currentTarget );
    var r:Rectangle = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
    r.inflate( -d.width / 2, -d.height / 2 );
    event.currentTarget.startDrag( false, r );
Just some handy methods of the Rectangle object to inflate (or shrink) a rectangle.

Similar Messages

  • How do I set _bounds so that my Rectangle drags correctly?

    Hi,
    So I'm having this issue. I have a movieclip that's longer than the width of the stage. I've put a mask over the stage so that whatever's outside the stage won't be seen. I want the user to be able to drag the movie clip left and right to get to the buttons. However, right now if I have the movieclip where it's left edge is at the left edge of the stage, it will drag off and you can see all this empty stage. If I move the movieclip in the center and try it, you can only see the part of the movieclip that the mask allows, therefore making the dragging useless because it doesn't reveal the rest of the movieclip.
    Should I take off the mask and is there some way to set the _bounds so that way I can place the movieclip in, and if can be dragged left and right without it revealing empty stage?
    Here's what I have:
    import flash.geom.Rectangle;
    var rx:Number = 0;
    var ry:Number = 0;
    var rwidth:Number = 550;
    var rheight:Number = 400;
    var _bounds:Rectangle = new Rectangle(rx, ry, rwidth, rheight);
    campusMC.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
    stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
    function mouseDown(event:MouseEvent):void {
        startDrag(false, _bounds);
        /*rectangle*/
    function mouseReleased(event:MouseEvent):void {
        stopDrag();

    Hey hi,
    While using the start drag we can give some limitations limitations.
    object.startDrag(false, object.width / 2, object.height / 2, stage.stageWidth - object.width / 2, stage.stageHeight - object.height / 2);
    try this.

  • StartDrag element with rotationY or rotationX bug

    Hello  there,
    I´ve  looked a  lot in the web but it seems that no one got this problem...  or at least  not published it.
    I´m making a startDrag with bounds  on a element  with rotationY value. Ok, it drags, but when got in the  bounds it just  give a huge bug, distorting the element scale. I tryed  some other things  but nothing worked - like put the drag canvas without  rotationY inside  another canvas with the rotationY. I tryied on Flex  Builder 3 and Flash  Builder and both gives the same bug. Does anyone  has an idea or got this  error?
    PS:  in Flex Builder 3 we need to configure  it to accept rotationY or  rotationX parameters.
    This bug is  cleared related to rotationY for  me because this parameter modifys the  2d into a 3d space, so the  rectangle could not be right. I wish someone  can help me! Thanks!
    http://www.keek.me/testes/drag2.swf
    <?xml  version="1.0" encoding="utf-8"?>
    <mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml"
              layout="absolute"
            verticalAlign="top"
              backgroundColor="white"
              backgroundGradientColors="[#0694F7, #501A82]"   backgroundGradientAlphas="[1.0, 1.0]"
              horizontalScrollPolicy="off" verticalScrollPolicy="off" >
          <mx:Script>
            <![CDATA[
                public function   allowDrag():void{
                    window_1.cacheAsBitmap = true;
                  public function startDragg():void{
                      window_1.startDrag(false,new Rectangle(0,10,300,0));
                  public function stopDragg():void{
                      window_1.stopDrag();
                private function   stage_mouseUp(evt:Event):void {
                    stopDragg();
              ]]>
        </mx:Script>
        <mx:Canvas   id="window_1" mouseUp="stopDragg();" rotationY="20"   mouseDown="startDragg();" width="564" height="240"   backgroundColor="#FFFFFF"/>
    </mx:Application>

    Repost!
    Hi,
    please, can someone from Oracle give me a statement?

  • Which libary I need to import for Rectangle method

    Anybody else knows which file we need to import for Rectangle method
    Example:
    mc.startDrag(false, new Rectangle(40,50,50,60));

    Hi,
           create a new ActionScript file...
         and click the left top corner + sign.That menu having a all classes.......
    regards
    Kamal

  • Marquee Selection Tool - Constrain

    Is there a way to constrain the rectangle and circle selection tools to squares and circles?

    I didn't see an option myself. (Right now, you can only expand/contract the current selection and any attempt at resizing using the transform option also transforms the pixels within the selection.)
    Might be something for the wishlist.

  • What happened to the 'Shape Mode' shortcut keys on the Pen Tool?

    For the longest time I've used both the Shape and Pen Tools for drawing vectors in Photoshop, but with CS6 I noticed a lot of weird behaviours. The one that is really getting to me is the lack of 'Shape Mode' shortcut keys when using the Pen Tool. When on the 'Shape Tool', fo example Cirle or Rectange, you can press the Shift to change the Shape Mode to 'Add', Alt to change it to 'Subtract' or both together to get 'Intersect'. This functionality used to exist on the Pen Tool too, but in CS6 I can't seem to get it working.
    A collegue suggested to move over to Illustrator for all my Vector needs, and I know that this a good advice. However the lack of quick/integrated changing between 'Shape Modes' in either product (now) makes drawing things alot slower (for me).
    Am I missing something, or is this feature now ommited in Photoshop CS6. If it is does anyone know if its possible to script something to allow this kind of behviour in Photoshop or Illustrator?
    cheers,
    Jon

    The modifier keys "Alt|Opt", "Ctrl|Cmd" and "Shift" work differently depending on the tool being used but the individual keys seem to provide somewhat related functions.
    For example the "Shift" key tends to be a constraining key Rectangle tools are constrained to square ellipse tools to Circles. However if there is an Active selection when you hold down the skey when you drag out a new selection it does not reset the current selection instead the new selection is not constrained and is added to the current selection. Shift constrains Transform tool to current aspect ratio,  Shift constrains Line tools to vertical, horizontal or 45 degree angles. Pen tool like line tool shift constrains the angle.
    The "Alt|Opt" key changes the way tools operate. Transforms are from the center not from the side or corner being dragged.  Selection tools like the rectangle and ellipse will cause the intal drag out be from the center however it there is a Active selection dragging out a new selection will be subtracted from the current selection. This key changes the Pen tool from draw mode to anchor point adjusting.
    The "Shift" and "Alt|Opt" modifier keys can be used together to have an operation be both constrain and from the center.
    The "Ctrl|Cmd" key seems to change the way a tool works on a control anchor point.  The Pen Tool changes from Pen Draw mode to Direct Selection tool to facilitate moving the point.  Transform can be distorted a single corner point can be moved and distort the rectangle bounding box.
    These keys may have other functions I don't know about.  Photoshop has many features so many I don't know if any one person know and uses all of them. For the rest of us they seem to be Photoshop hidden secrets.

  • How to stop video from playing?

    Hi,
    i have a problem that i've already see that is pretty usual, the videoplayer that i have works fine but when i click in a button to go to another page the videoplayer doesn't stop,the audio continues playing even when i'm not on the videoplayer page.
    I've already found some solutions in the web but none of them worked,probably because i didn't put them in the right place
    The code is a little long:
    // ############# CONSTANTS
    // time to buffer for the video in sec.
    const BUFFER_TIME:Number                = 8;
    // start volume when initializing player
    const DEFAULT_VOLUME:Number                = 0.6;
    // update delay in milliseconds.
    const DISPLAY_TIMER_UPDATE_DELAY:int    = 10;
    // smoothing for video. may slow down old computers
    const SMOOTHING:Boolean                    = true;
    // ############# VARIABLES
    // flag for knowing if user hovers over description label
    var bolDescriptionHover:Boolean = false;
    // flag for knowing in which direction the description label is currently moving
    var bolDescriptionHoverForward:Boolean = true;
    // flag for knowing if flv has been loaded
    var bolLoaded:Boolean                    = false;
    // flag for volume scrubbing
    var bolVolumeScrub:Boolean                = false;
    // flag for progress scrubbing
    var bolProgressScrub:Boolean            = false;
    // holds the number of the active video
    var intActiveVid:int;
    // holds the last used volume, but never 0
    var intLastVolume:Number                = DEFAULT_VOLUME;
    // net connection object for net stream
    var ncConnection:NetConnection;
    // net stream object
    var nsStream:NetStream;
    // object holds all meta data
    var objInfo:Object;
    // shared object holding the player settings (currently only the volume)
    var shoVideoPlayerSettings:SharedObject = SharedObject.getLocal("playerSettings");
    // url to flv file
    var strSource:String                    = root.loaderInfo.parameters.playlist == null ? "playlist.xml" : root.loaderInfo.parameters.playlist;
    // timer for updating player (progress, volume...)
    var tmrDisplay:Timer;
    // loads the xml file
    var urlLoader:URLLoader;
    // holds the request for the loader
    var urlRequest:URLRequest;
    // playlist xml
    var xmlPlaylist:XML;
    // ############# STAGE SETTINGS
    stage.scaleMode    = StageScaleMode.NO_SCALE;
    stage.align        = StageAlign.TOP_LEFT;
    // ############# FUNCTIONS
    // sets up the player
    function initVideoPlayer():void {
        // hide video controls on initialisation
        mcVideoControls.visible = false;
        // hide buttons
        mcVideoControls.btnUnmute.visible            = false;
        mcVideoControls.btnPause.visible            = false;
        mcVideoControls.btnFullscreenOff.visible    = false;
        // set the progress/preload fill width to 1
        mcVideoControls.mcProgressFill.mcFillRed.width    = 1;
        mcVideoControls.mcProgressFill.mcFillGrey.width    = 1;
        // set time and duration label
        mcVideoControls.lblTimeDuration.htmlText        = "<font color='#ffffff'>00:00</font> / 00:00";
        // add global event listener when mouse is released
        stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
        // add fullscreen listener
        stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreen);
        // add event listeners to all buttons
        mcVideoControls.btnPause.addEventListener(MouseEvent.CLICK, pauseClicked);
        mcVideoControls.btnPlay.addEventListener(MouseEvent.CLICK, playClicked);
        mcVideoControls.btnStop.addEventListener(MouseEvent.CLICK, stopClicked);
        mcVideoControls.btnNext.addEventListener(MouseEvent.CLICK, playNext);
        mcVideoControls.btnPrevious.addEventListener(MouseEvent.CLICK, playPrevious);
        mcVideoControls.btnMute.addEventListener(MouseEvent.CLICK, muteClicked);
        mcVideoControls.btnUnmute.addEventListener(MouseEvent.CLICK, unmuteClicked);
        mcVideoControls.btnFullscreenOn.addEventListener(MouseEvent.CLICK, fullscreenOnClicked);
        mcVideoControls.btnFullscreenOff.addEventListener(MouseEvent.CLICK, fullscreenOffClicked);
        mcVideoControls.btnVolumeBar.addEventListener(MouseEvent.MOUSE_DOWN, volumeScrubberClicked);
        mcVideoControls.mcVolumeScrubber.btnVolumeScrubber.addEventListener(MouseEvent.MOUSE_DOWN , volumeScrubberClicked);
        mcVideoControls.btnProgressBar.addEventListener(MouseEvent.MOUSE_DOWN, progressScrubberClicked);
        mcVideoControls.mcProgressScrubber.btnProgressScrubber.addEventListener(MouseEvent.MOUSE_ DOWN, progressScrubberClicked);
        mcVideoControls.mcVideoDescription.btnDescription.addEventListener(MouseEvent.MOUSE_OVER, startDescriptionScroll);
        mcVideoControls.mcVideoDescription.btnDescription.addEventListener(MouseEvent.MOUSE_OUT, stopDescriptionScroll);
        // create timer for updating all visual parts of player and add
        // event listener
        tmrDisplay = new Timer(DISPLAY_TIMER_UPDATE_DELAY);
        tmrDisplay.addEventListener(TimerEvent.TIMER, updateDisplay);
        // create a new net connection, add event listener and connect
        // to null because we don't have a media server
        ncConnection = new NetConnection();
        ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        ncConnection.connect(null);
        // create a new netstream with the net connection, add event
        // listener, set client to this for handling meta data and
        // set the buffer time to the value from the constant
        nsStream = new NetStream(ncConnection);
        nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        nsStream.client = this;
        nsStream.bufferTime = BUFFER_TIME;
        // attach net stream to video object on the stage
        vidDisplay.attachNetStream(nsStream);
        // set the smoothing value from the constant
        vidDisplay.smoothing = SMOOTHING;
        // set default volume and get volume from shared object if available
        var tmpVolume:Number = DEFAULT_VOLUME;
        if(shoVideoPlayerSettings.data.playerVolume != undefined) {
            tmpVolume = shoVideoPlayerSettings.data.playerVolume;
            intLastVolume = tmpVolume;
        // update volume bar and set volume
        mcVideoControls.mcVolumeScrubber.x = (53 * tmpVolume) + 318;
        mcVideoControls.mcVolumeFill.mcFillRed.width = mcVideoControls.mcVolumeScrubber.x - 371 + 53;
        setVolume(tmpVolume);
        // create new request for loading the playlist xml, add an event listener
        // and load it
        urlRequest = new URLRequest(strSource);
        urlLoader = new URLLoader();
        urlLoader.addEventListener(Event.COMPLETE, playlistLoaded);
        urlLoader.load(urlRequest);
    function playClicked(e:MouseEvent):void {
        // check's, if the flv has already begun
        // to download. if so, resume playback, else
        // load the file
        if(!bolLoaded) {
            nsStream.play(strSource);
            bolLoaded = true;
        else{
            nsStream.resume();
        vidDisplay.visible = true;
        // switch play/pause visibility
        mcVideoControls.btnPause.visible    = true;
        mcVideoControls.btnPlay.visible        = false;
    function pauseClicked(e:MouseEvent):void {
        // pause video
        nsStream.pause();
        // switch play/pause visibility
        mcVideoControls.btnPause.visible    = false;
        mcVideoControls.btnPlay.visible        = true;
    function stopClicked(e:MouseEvent):void {
        // calls stop function
        stopVideoPlayer();
    function muteClicked(e:MouseEvent):void {
        // set volume to 0
        setVolume(0);
        // update scrubber and fill position/width
        mcVideoControls.mcVolumeScrubber.x                = 318;
        mcVideoControls.mcVolumeFill.mcFillRed.width    = 1;
    function unmuteClicked(e:MouseEvent):void {
        // set volume to last used value or DEFAULT_VOLUME if last volume is zero
        var tmpVolume:Number = intLastVolume == 0 ? DEFAULT_VOLUME : intLastVolume
        setVolume(tmpVolume);
        // update scrubber and fill position/width
        mcVideoControls.mcVolumeScrubber.x = (53 * tmpVolume) + 318;
        mcVideoControls.mcVolumeFill.mcFillRed.width = mcVideoControls.mcVolumeScrubber.x - 371 + 53;
    function volumeScrubberClicked(e:MouseEvent):void {
        // set volume scrub flag to true
        bolVolumeScrub = true;
        // start drag
        mcVideoControls.mcVolumeScrubber.startDrag(true, new Rectangle(318, 19, 53, 0)); // NOW TRUE
    function progressScrubberClicked(e:MouseEvent):void {
        // set progress scrub flag to true
        bolProgressScrub = true;
        // start drag
        mcVideoControls.mcProgressScrubber.startDrag(true, new Rectangle(0, 2, 432, 0)); // NOW TRUE
    function mouseReleased(e:MouseEvent):void {
        // set progress/volume scrub to false
        bolVolumeScrub        = false;
        bolProgressScrub    = false;
        // stop all dragging actions
        mcVideoControls.mcProgressScrubber.stopDrag();
        mcVideoControls.mcVolumeScrubber.stopDrag();
        // update progress/volume fill
        mcVideoControls.mcProgressFill.mcFillRed.width    = mcVideoControls.mcProgressScrubber.x + 5;
        mcVideoControls.mcVolumeFill.mcFillRed.width    = mcVideoControls.mcVolumeScrubber.x - 371 + 53;
        // save the volume if it's greater than zero
        if((mcVideoControls.mcVolumeScrubber.x - 318) / 53 > 0)
            intLastVolume = (mcVideoControls.mcVolumeScrubber.x - 318) / 53;
    function updateDisplay(e:TimerEvent):void {
        // checks, if user is scrubbing. if so, seek in the video
        // if not, just update the position of the scrubber according
        // to the current time
        if(bolProgressScrub)
            nsStream.seek(Math.round(mcVideoControls.mcProgressScrubber.x * objInfo.duration / 432))
        else
            mcVideoControls.mcProgressScrubber.x = nsStream.time * 432 / objInfo.duration;
        // set time and duration label
        mcVideoControls.lblTimeDuration.htmlText        = "<font color='#ffffff'>" + formatTime(nsStream.time) + "</font> / " + formatTime(objInfo.duration);
        // update the width from the progress bar. the grey one displays
        // the loading progress
        mcVideoControls.mcProgressFill.mcFillRed.width    = mcVideoControls.mcProgressScrubber.x + 5;
        mcVideoControls.mcProgressFill.mcFillGrey.width    = nsStream.bytesLoaded * 438 / nsStream.bytesTotal;
        // update volume and the red fill width when user is scrubbing
        if(bolVolumeScrub) {
            setVolume((mcVideoControls.mcVolumeScrubber.x - 318) / 53);
            mcVideoControls.mcVolumeFill.mcFillRed.width = mcVideoControls.mcVolumeScrubber.x - 371 + 53;
        // chech if user is currently hovering over description label
        if(bolDescriptionHover) {
            // check in which direction we're currently moving
            if(bolDescriptionHoverForward) {
                // move to the left and check if we've shown everthing
                mcVideoControls.mcVideoDescription.lblDescription.x -= 0.1;
                if(mcVideoControls.mcVideoDescription.lblDescription.textWidth - 133 <= Math.abs(mcVideoControls.mcVideoDescription.lblDescription.x))
                    bolDescriptionHoverForward = false;
            } else {
                // move to the right and check if we're back to normal
                mcVideoControls.mcVideoDescription.lblDescription.x += 0.1;
                if(mcVideoControls.mcVideoDescription.lblDescription.x >= 0)
                    bolDescriptionHoverForward = true;
        } else {
            // reset label position and direction variable
            mcVideoControls.mcVideoDescription.lblDescription.x = 0;
            bolDescriptionHoverForward = true;
    function onMetaData(info:Object):void {
        // stores meta data in a object
        objInfo = info;
        // now we can start the timer because
        // we have all the neccesary data
        if(!tmrDisplay.running)
            tmrDisplay.start();
    function netStatusHandler(event:NetStatusEvent):void {
        // handles net status events
        switch (event.info.code) {
            // trace a messeage when the stream is not found
            case "NetStream.Play.StreamNotFound":
                trace("Stream not found: " + strSource);
            break;
            // when the video reaches its end, we check if there are
            // more video left or stop the player
            case "NetStream.Play.Stop":
                if(intActiveVid + 1 < xmlPlaylist..vid.length())
                    playNext();
                else
                    stopVideoPlayer();
            break;
    function stopVideoPlayer():void {
        // pause netstream, set time position to zero
        nsStream.pause();
        nsStream.seek(0);
        // in order to clear the display, we need to
        // set the visibility to false since the clear
        // function has a bug
        vidDisplay.visible                    = false;
        // switch play/pause button visibility
        mcVideoControls.btnPause.visible    = false;
        mcVideoControls.btnPlay.visible        = true;
    function setVolume(intVolume:Number = 0):void {
        // create soundtransform object with the volume from
        // the parameter
        var sndTransform        = new SoundTransform(intVolume);
        // assign object to netstream sound transform object
        nsStream.soundTransform    = sndTransform;
        // hides/shows mute and unmute button according to the
        // volume
        if(intVolume > 0) {
            mcVideoControls.btnMute.visible        = true;
            mcVideoControls.btnUnmute.visible    = false;
        } else {
            mcVideoControls.btnMute.visible        = false;
            mcVideoControls.btnUnmute.visible    = true;
        // store the volume in the flash cookie
        shoVideoPlayerSettings.data.playerVolume = intVolume;
        shoVideoPlayerSettings.flush();
    function formatTime(t:int):String {
        // returns the minutes and seconds with leading zeros
        // for example: 70 returns 01:10
        var s:int = Math.round(t);
        var m:int = 0;
        if (s > 0) {
            while (s > 59) {
                m++; s -= 60;
            return String((m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
        } else {
            return "00:00";
    function fullscreenOnClicked(e:MouseEvent):void {
        // go to fullscreen mode
        stage.displayState = StageDisplayState.FULL_SCREEN;
    function fullscreenOffClicked(e:MouseEvent):void {
        // go to back to normal mode
        stage.displayState = StageDisplayState.NORMAL;
    function onFullscreen(e:FullScreenEvent):void {
        // check if we're entering or leaving fullscreen mode
        if (e.fullScreen) {
            // switch fullscreen buttons
            mcVideoControls.btnFullscreenOn.visible = false;
            mcVideoControls.btnFullscreenOff.visible = true;
            // bottom center align controls
            mcVideoControls.x = (Capabilities.screenResolutionX - 440) / 2;
            mcVideoControls.y = (Capabilities.screenResolutionY - 33);
            // size up video display
            vidDisplay.height     = (Capabilities.screenResolutionY - 33);
            vidDisplay.width     = vidDisplay.height * 4 / 3;
            vidDisplay.x        = (Capabilities.screenResolutionX - vidDisplay.width) / 2;
        } else {
            // switch fullscreen buttons
            mcVideoControls.btnFullscreenOn.visible = true;
            mcVideoControls.btnFullscreenOff.visible = false;
            // reset controls position
            mcVideoControls.x = 0;
            mcVideoControls.y = 330;
            // reset video display
            vidDisplay.y = 0;
            vidDisplay.x = 0;
            vidDisplay.width = 440;
            vidDisplay.height = 241;
    function playlistLoaded(e:Event):void {
        // create new xml with loaded data from loader
        xmlPlaylist = new XML(urlLoader.data);
        // set source of the first video but don't play it
        playVid(0, true)
        // show controls
        mcVideoControls.visible = true;
    function playVid(intVid:int = 0, bolPlay = true):void {
        if(bolPlay) {
            // stop timer
            tmrDisplay.stop();
            // play requested video
            nsStream.play(String(xmlPlaylist..vid[intVid].@src));
            // switch button visibility
            mcVideoControls.btnPause.visible    = true;
            mcVideoControls.btnPlay.visible        = false;
        } else {
            strSource = xmlPlaylist..vid[intVid].@src;
        // show video display
        vidDisplay.visible                    = true;
        // reset description label position and assign new description
        mcVideoControls.mcVideoDescription.lblDescription.x = 0;
        mcVideoControls.mcVideoDescription.lblDescription.htmlText = (intVid + 1) + ". <font color='#ffffff'>" + String(xmlPlaylist..vid[intVid].@desc) + "</font>";
        // update active video number
        intActiveVid = intVid;
    function playNext(e:MouseEvent = null):void {
        // check if there are video left to play and play them
        if(intActiveVid + 1 < xmlPlaylist..vid.length())
            playVid(intActiveVid + 1);
    function playPrevious(e:MouseEvent = null):void {
        // check if we're not and the beginning of the playlist and go back
        if(intActiveVid - 1 >= 0)
            playVid(intActiveVid - 1);
    function startDescriptionScroll(e:MouseEvent):void {
        // check if description label is too long and we need to enable scrolling
        if(mcVideoControls.mcVideoDescription.lblDescription.textWidth > 138)
            bolDescriptionHover = true;
    function stopDescriptionScroll(e:MouseEvent):void {
        // disable scrolling
        bolDescriptionHover = false;
    // ############# INIT PLAYER
    initVideoPlayer();

    No,im not using flvplayback component (i think).
    Heres the video player that i'm using:
    http://www.thetechlabs.com/tutorials/xml/expanding-the-as3-videoplayer/

  • Looking for some Flash tutorials

    I'm doing some webstuff in Flash CS5 using actionscript 3, and I could use some help with a couple of things.  Can anyone recommend some tutorials on how to make an effective image gallery?  Like with a picture slider or something?  But ideally nothing overly complicated to do.  I don't wanna just copy and paste code off of a website either, I wanna know how to actually make the code using Flash...maybe even just using the snippets if that's doable. 
    I'd also like to find a tutorial that'll teach me how to make a scroll bar so I can scan up and down text or images for another part of the project.
    I'm looking for either video tutorials or written tutorials.

    You can create mask for the movieclip as exactly as in your tutorial. and use below code (I think this is what you want).
    For using the below code you should create some user defined components.
    For Horizontal Scroll Bar:  create hscrollBG for scrollbar background and hscroller for scroller.
    For Vertical Scroll Bar: create vscrollBG for scrollbar background and vscroller for scroller.
    mask_mc is mask movieclip  and    content_mc is which the content you want to scroll.
    /**** code  ****/
    var hscrollbar:MovieClip;
    var vscrollbar:MovieClip;
    if (content_mc.height > mask_mc.height)
        drawVScrollBar();
       if(content_mc.width > mask_mc.width)
        drawHScrollBar();
    private function drawVScrollBar():void
       try
        removeChild(vscrollbar);
       catch (e:Error)
       vscrollbar = new MovieClip();
       addChild(vscrollbar);
       vscrollbar.x = mask_mc.width + 5;        //set scrollbar position
       var bg:vscrollBG = new vscrollBG();
       bg.height = mask_mc.height;
       vscrollbar.addChildAt(bg,0);
       var scroller:vscroller = new vscroller();
       scroller.x = 1;
       scroller.y = 0;
       vscrollbar.addChildAt(scroller,1);
       scroller.addEventListener(MouseEvent.MOUSE_UP, sc_mouseup);
       scroller.addEventListener(MouseEvent.MOUSE_DOWN, sc_mousedown);
       stage.addEventListener(MouseEvent.MOUSE_UP, sc_mouseup);
      private function sc_mousedown(e:MouseEvent):void
       var scroller:MovieClip = vscrollbar.getChildAt(1) as MovieClip;
       scroller.startDrag(false, new Rectangle(1, 0, 0,mask_mc.height- scroller.height));
       scroller.addEventListener(Event.ENTER_FRAME, updateScrollPosition);
      private function sc_mouseup(e:MouseEvent):void
       stopDrag();
       var scroller:MovieClip = vscrollbar.getChildAt(1) as MovieClip;
       scroller.removeEventListener(Event.ENTER_FRAME, updateScrollPosition);
      private function updateScrollPosition(e:Event):void {
       var bg:MovieClip = vscrollbar.getChildAt(0) as MovieClip;
       var scroller:MovieClip = vscrollbar.getChildAt(1) as MovieClip;
       var perc:Number = scroller.y * 100 / (bg.height-scroller.height);
       var ypos:Number = ( -perc * ((content_mc.height - mask_mc.height) / 100));
       content_mc.y = ypos;
      private function drawHScrollBar():void
       try
        removeChild(hscrollbar);
       catch (e:Error)
       hscrollbar = new MovieClip();
       addChild(hscrollbar);
       hscrollbar.y = mask_mc.height + 5;
       var bg:hscrollBG = new hscrollBG();
       bg.width = mask_mc.width;
       hscrollbar.addChildAt(bg,0);
       var scroller:hscroller = new hscroller();
       scroller.x = 1;
       scroller.y = 0;
       hscrollbar.addChildAt(scroller,1);
       scroller.addEventListener(MouseEvent.MOUSE_UP, hsc_mouseup);
       scroller.addEventListener(MouseEvent.MOUSE_DOWN, hsc_mousedown);
       stage.addEventListener(MouseEvent.MOUSE_UP, hsc_mouseup);
      private function hsc_mousedown(e:MouseEvent):void
       var bg:MovieClip = hscrollbar.getChildAt(0) as MovieClip;
       var scroller:MovieClip = hscrollbar.getChildAt(1) as MovieClip;
       scroller.startDrag(false, new Rectangle(bg.x, bg.y, bg.width - scroller.width,0));
       scroller.addEventListener(Event.ENTER_FRAME, hupdateScrollPosition);
      private function hsc_mouseup(e:MouseEvent):void
       stopDrag();
       var scroller:MovieClip = hscrollbar.getChildAt(1) as MovieClip;
       scroller.removeEventListener(Event.ENTER_FRAME, hupdateScrollPosition);
      private function hupdateScrollPosition(e:Event):void {
       var bg:MovieClip = hscrollbar.getChildAt(0) as MovieClip;
       var scroller:MovieClip = hscrollbar.getChildAt(1) as MovieClip;
       var perc:Number = (scroller.x - bg.x) / (bg.width - scroller.width);  
       var xcounter:Number = ( -perc * (content_mc.width - mask_mc.width));
      content_mc.x = xcounter;
    This code is reusable for many applications where we want scrollbar. In this code we can dynamically assign the scrollbars based on the content width and height.

  • Scroll Bar Controlling multiple movieclips?

    Instead of a scroll bar just controlling one movieclip..How could we get it to control multiple movieclips?
    public class MainScroll extends Sprite
              //private var mc_content:Sprite;
              private var content_mc:MovieClip;
              private var content2_mc:MovieClip;
              private var _scrollBar:FullScreenScrollBar;
              //============================================================================================================================
              public function MainScroll()
              //============================================================================================================================
                   addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
              //============================================================================================================================
              private function init():void
              //============================================================================================================================
                   SWFWheel.initialize(stage);
                   //_copy = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quam leo semper non sollicitudin in eleifend sit amet diam. "; 
                   content_mc = new mc_content();
                   content2_mc = new mc_content2();
                   content_mc.x = 110;
                   content_mc.y = 29;
                   content2_mc.x = 10
                   content2_mc.y = 29
                   addChild(content_mc);
                   addChild(content2_mc);
                   // Scrollbar code 
                   // Arguments: Content to scroll, track color, grabber color, grabber press color, grip color, track thickness, grabber thickness, ease amount, whether grabber is "shiny"
                   _scrollBar = new FullScreenScrollBar(content_mc, 0x000000, 0x408740, 0x73C35B, 0xffffff, 15, 15, 4, true);
                   addChild(_scrollBar);
              //============================================================================================================================
              private function onAddedToStage(e:Event):void
              //============================================================================================================================
                   init();
                   removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

    Ok,
    Here is that code:
         import flash.display.*
         import flash.events.*;
         import flash.geom.Rectangle;
         import gs.OverwriteManager;
         import gs.TweenFilterLite;
         public class FullScreenScrollBar extends Sprite
              private var _content:DisplayObjectContainer;
              private var _trackColor:uint;
              private var _grabberColor:uint;
              private var _grabberPressColor:uint;
              private var _gripColor:uint;
              private var _trackThickness:int;
              private var _grabberThickness:int;
              private var _easeAmount:int;
              private var _hasShine:Boolean;
              private var _track:Sprite;
              private var _grabber:Sprite;
              private var _grabberGrip:Sprite;
              private var _grabberArrow1:Sprite;
              private var _grabberArrow2:Sprite;
              private var _tH:Number; // Track height
              private var _cH:Number; // Content height
              private var _scrollValue:Number;
              private var _defaultPosition:Number;
              private var _stageW:Number;
              private var _stageH:Number;
              private var _pressed:Boolean = false;
              //============================================================================================================================
              public function FullScreenScrollBar(c:DisplayObjectContainer, tc:uint, gc:uint, gpc:uint, grip:uint, tt:int, gt:int, ea:int, hs:Boolean)
              //============================================================================================================================
                   _content = c;
                   _trackColor = tc;
                   _grabberColor = gc;
                   _grabberPressColor = gpc;
                   _gripColor = grip;
                   _trackThickness = tt;
                   _grabberThickness = gt;
                   _easeAmount = ea;
                   _hasShine = hs;
                   init();
                   OverwriteManager.init();
              //============================================================================================================================
              private function init():void
              //============================================================================================================================
                   createTrack();
                   createGrabber();
                   createGrips();
                   addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
                   _defaultPosition = Math.round(_content.y);
                   _grabber.y = 0;
              //============================================================================================================================
              public function kill():void
              //============================================================================================================================
                   stage.removeEventListener(Event.RESIZE, onStageResize);
              //============================================================================================================================
              private function stopScroll(e:Event):void
              //============================================================================================================================
                   onUpListener();
              //============================================================================================================================
              private function scrollContent(e:Event):void
              //============================================================================================================================
                   var ty:Number;
                   var dist:Number;
                   var moveAmount:Number;
                   ty = -((_cH - _tH) * (_grabber.y / _scrollValue));
                   dist = ty - _content.y + _defaultPosition;
                   moveAmount = dist / _easeAmount;
                   _content.y += Math.round(moveAmount);
                   if (Math.abs(_content.y - ty - _defaultPosition) < 1.5)
                        _grabber.removeEventListener(Event.ENTER_FRAME, scrollContent);
                        _content.y = Math.round(ty) + _defaultPosition;
                   positionGrips();
              //============================================================================================================================
              public function adjustSize():void
              //============================================================================================================================
                   this.x = _stageW - _trackThickness;
                   _track.height = _stageH;
                   _track.y = 0;
                   _tH = _track.height;
                   _cH = _content.height + _defaultPosition;
                   // Set height of grabber relative to how much content
                   _grabber.getChildByName("bg").height = Math.ceil((_tH / _cH) * _tH);
                   // Set minimum size for grabber
                   if(_grabber.getChildByName("bg").height < 35) _grabber.getChildByName("bg").height = 35;
                   if(_hasShine) _grabber.getChildByName("shine").height = _grabber.getChildByName("bg").height;
                   // If scroller is taller than stage height, set its y position to the very bottom
                   if ((_grabber.y + _grabber.getChildByName("bg").height) > _tH) _grabber.y = _tH - _grabber.getChildByName("bg").height;
                   // If content height is less than stage height, set the scroller y position to 0, otherwise keep it the same
                   _grabber.y = (_cH < _tH) ? 0 : _grabber.y;
                   // If content height is greater than the stage height, show it, otherwise hide it
                   this.visible = (_cH + 8 > _tH);
                   // Distance left to scroll
                   _scrollValue = _tH - _grabber.getChildByName("bg").height;
                   _content.y = Math.round(-((_cH - _tH) * (_grabber.y / _scrollValue)) + _defaultPosition);
                   positionGrips();
                   if(_content.height < stage.stageHeight) { stage.removeEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelListener); } else { stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelListener); }
              //============================================================================================================================
              private function positionGrips():void
              //============================================================================================================================
                   _grabberGrip.y = Math.ceil(_grabber.getChildByName("bg").y + (_grabber.getChildByName("bg").height / 2) - (_grabberGrip.height / 2));
                   _grabberArrow1.y = _grabber.getChildByName("bg").y + 8;
                   _grabberArrow2.y = _grabber.getChildByName("bg").height - 8;
              //============================================================================================================================
              // CREATORS
              //============================================================================================================================
              //============================================================================================================================
              private function createTrack():void
              //============================================================================================================================
                   _track = new Sprite();
                   var t:Sprite = new Sprite();
                   t.graphics.beginFill(_trackColor);
                   t.graphics.drawRect(0, 0, _trackThickness, _trackThickness);
                   t.graphics.endFill();
                   _track.addChild(t);
                   addChild(_track);
              //============================================================================================================================
              private function createGrabber():void
              //============================================================================================================================
                   _grabber = new Sprite();
                   var t:Sprite = new Sprite();
                   t.graphics.beginFill(_grabberColor);
                   t.graphics.drawRect(0, 0, _grabberThickness, _grabberThickness);
                   t.graphics.endFill();
                   t.name = "bg";
                   _grabber.addChild(t);
                   if(_hasShine)
                        var shine:Sprite = new Sprite();
                        var sg:Graphics = shine.graphics;
                        sg.beginFill(0xffffff, 0.15);
                        sg.drawRect(0, 0, Math.ceil(_trackThickness/2), _trackThickness);
                        sg.endFill();
                        shine.x = Math.floor(_trackThickness/2);
                        shine.name = "shine";
                        _grabber.addChild(shine);
                   addChild(_grabber);
              //============================================================================================================================
              private function createGrips():void
              //============================================================================================================================
                   _grabberGrip = createGrabberGrip();
                   _grabber.addChild(_grabberGrip);
                   _grabberArrow1 = createPixelArrow();
                   _grabber.addChild(_grabberArrow1);
                   _grabberArrow2 = createPixelArrow();
                   _grabber.addChild(_grabberArrow2);
                   _grabberArrow1.rotation = -90;
                   _grabberArrow1.x = ((_grabberThickness - 7) / 2) + 1;
                   _grabberArrow2.rotation = 90;
                   _grabberArrow2.x = ((_grabberThickness - 7) / 2) + 6;
              //============================================================================================================================
              private function createGrabberGrip():Sprite
              //============================================================================================================================
                   var w:int = 7;
                   var xp:int = (_grabberThickness - w) / 2;
                   var t:Sprite = new Sprite();
                   t.graphics.beginFill(_gripColor, 1);
                   t.graphics.drawRect(xp, 0, w, 1);
                   t.graphics.drawRect(xp, 0 + 2, w, 1);
                   t.graphics.drawRect(xp, 0 + 4, w, 1);
                   t.graphics.drawRect(xp, 0 + 6, w, 1);
                   t.graphics.drawRect(xp, 0 + 8, w, 1);
                   t.graphics.endFill();
                   return t;
              //============================================================================================================================
              private function createPixelArrow():Sprite
              //============================================================================================================================
                   var t:Sprite = new Sprite();               
                   t.graphics.beginFill(_gripColor, 1);
                   t.graphics.drawRect(0, 0, 1, 1);
                   t.graphics.drawRect(1, 1, 1, 1);
                   t.graphics.drawRect(2, 2, 1, 1);
                   t.graphics.drawRect(1, 3, 1, 1);
                   t.graphics.drawRect(0, 4, 1, 1);
                   t.graphics.endFill();
                   return t;
              //============================================================================================================================
              // LISTENERS
              //============================================================================================================================
              //============================================================================================================================
              private function mouseWheelListener(me:MouseEvent):void
              //============================================================================================================================
                   var d:Number = me.delta;
                   if (d > 0)
                        if ((_grabber.y - (d * 4)) >= 0)
                             _grabber.y -= d * 4;
                        else
                             _grabber.y = 0;
                        if (!_grabber.willTrigger(Event.ENTER_FRAME)) _grabber.addEventListener(Event.ENTER_FRAME, scrollContent);
                   else
                        if (((_grabber.y + _grabber.height) + (Math.abs(d) * 4)) <= stage.stageHeight)
                             _grabber.y += Math.abs(d) * 4;
                        else
                             _grabber.y = stage.stageHeight - _grabber.height;
                        if (!_grabber.willTrigger(Event.ENTER_FRAME)) _grabber.addEventListener(Event.ENTER_FRAME, scrollContent);
              //============================================================================================================================
              private function onDownListener(e:MouseEvent):void
              //============================================================================================================================
                   _pressed = true;
                   _grabber.startDrag(false, new Rectangle(0, 0, 0, _stageH - _grabber.getChildByName("bg").height));
                   stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveListener, false, 0, true);
                   TweenFilterLite.to(_grabber.getChildByName("bg"), 0.5, { tint:_grabberPressColor } );
              //============================================================================================================================
              private function onUpListener(e:MouseEvent = null):void
              //============================================================================================================================
                   if (_pressed)
                        _pressed = false;
                        _grabber.stopDrag();
                        stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveListener);
                        TweenFilterLite.to(_grabber.getChildByName("bg"), 0.5, { tint:null } );
              //============================================================================================================================
              private function onMouseMoveListener(e:MouseEvent):void
              //============================================================================================================================
                   e.updateAfterEvent();
                   if (!_grabber.willTrigger(Event.ENTER_FRAME)) _grabber.addEventListener(Event.ENTER_FRAME, scrollContent, false, 0, true);
              //============================================================================================================================
              private function onTrackClick(e:MouseEvent):void
              //============================================================================================================================
                   var p:int;
                   var s:int = 150;
                   p = Math.ceil(e.stageY);
                   if(p < _grabber.y)
                        if(_grabber.y < _grabber.height)
                             TweenFilterLite.to(_grabber, 0.5, {y:0, onComplete:reset, overwrite:1});
                        else
                             TweenFilterLite.to(_grabber, 0.5, {y:"-150", onComplete:reset});
                        if(_grabber.y < 0) _grabber.y = 0;
                   else
                        if((_grabber.y + _grabber.height) > (_stageH - _grabber.height))
                             TweenFilterLite.to(_grabber, 0.5, {y:_stageH - _grabber.height, onComplete:reset, overwrite:1});
                        else
                             TweenFilterLite.to(_grabber, 0.5, {y:"150", onComplete:reset});
                        if(_grabber.y + _grabber.getChildByName("bg").height > _track.height) _grabber.y = stage.stageHeight - _grabber.getChildByName("bg").height;
                   function reset():void
                        if(_grabber.y < 0) _grabber.y = 0;
                        if(_grabber.y + _grabber.getChildByName("bg").height > _track.height) _grabber.y = stage.stageHeight - _grabber.getChildByName("bg").height;
                   _grabber.addEventListener(Event.ENTER_FRAME, scrollContent, false, 0, true);
              //============================================================================================================================
              private function onAddedToStage(e:Event):void
              //============================================================================================================================
                   stage.addEventListener(Event.MOUSE_LEAVE, stopScroll);
                   stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelListener);
                   stage.addEventListener(Event.RESIZE, onStageResize, false, 0, true);
                   stage.addEventListener(MouseEvent.MOUSE_UP, onUpListener, false, 0, true);
                   _grabber.addEventListener(MouseEvent.MOUSE_DOWN, onDownListener, false, 0, true);
                   _grabber.buttonMode = true;
                   _track.addEventListener(MouseEvent.CLICK, onTrackClick, false, 0, true);
                   removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                   _stageW = stage.stageWidth;
                   _stageH = stage.stageHeight;
                   adjustSize();
              //============================================================================================================================
              private function onStageResize(e:Event):void
              //============================================================================================================================
                   _stageW = stage.stageWidth;
                   _stageH = stage.stageHeight;
                   adjustSize();

  • Sound restarting in wrong place

    I created a play/pause/track slider to control sound. No animation at all. With traces, I can see that the new sound position is being calculated correctly. When the sound restarts, it is much closer to the end of the sound than it should be. Snippets below:
      public function playAudio(event:Event = null):void
       if(media.channel)
        media.channel.stop();
       media.channel = media.audio.play(media.soundResume);
      public function pauseAudio(event:MouseEvent = null):void
       controller.removeProgress(cntl_mc);
       media.soundResume = media.channel.position;
       media.channel.stop();
       if (SoundMixer.areSoundsInaccessible() == false)
        SoundMixer.stopAll();
      public function processDragBar():void
       pauseAudio();
       cntl_mc.progress_mc.bar_mc.startDrag(false, new Rectangle(0,0,cntl_mc.progress_mc.track_mc.width - cntl_mc.progress_mc.bar_mc.width, 0));
      public function processDropBar():void
       var percentage:Number = (cntl_mc.progress_mc.bar_mc.x / (cntl_mc.progress_mc.track_mc.width - cntl_mc.progress_mc.bar_mc.width));
       media.soundResume = (percentage * media.audio.length);
       playAudio();
       cntl_mc.progress_mc.bar_mc.stopDrag(); 
      public function processTrack():void
       cntl_mc.progress_mc.bar_mc.x = media.newTrackX;
       var percentage:Number = (cntl_mc.progress_mc.bar_mc.x / (cntl_mc.progress_mc.track_mc.width - cntl_mc.progress_mc.bar_mc.width));
       if (percentage >= 1)
        media.soundResume = 0;
        pauseAudio();
       else
        media.soundResume = (percentage * media.audio.length);
       playAudio();

    Hi,
    If you are using CS4, please update it as it has fix for sound delay issue.
    http://blogs.adobe.com/rgalvan/2009/05/flash_cs4_update_now_available.html
    Hope this helps.

  • Adding Scrollbar and buttons to Dynamic Text

    Hello,
    I am trying to connect dynamic text to scrollbar and buttons. I did tutorial and Lynda.com and practically pasted the code in with my file names and for some reason it does not work. It says I have a "Access of Undefined Property mask_mc" Did I need to create a variable for this? I didn't in the tutorial.
    Right now I have the dynamic text loading successfuly in 2 different places and I wantd to add the scrollbar. I put the variables on frame 1 code and then I put the actually load code on the frame where it is needed.
    Any suggestions?
    Thanks! Sandra
    HERE IS CODE FOR FRAME 1:
    var textLoader:URLLoader = new URLLoader();
    var textReq:URLRequest;
    var scrollPercent:Number = 0;
    var minScroll:Number;
    var maxScroll:Number;
    var targetScroll:Number = philText_mc.y;
    var easing:Number = 5;
    var scrollAmt:Number = 15;
    var scrollDirection:Number = 0;
    HERE IS CODE FOR FRAME WHERE TEXT LOADS:
    textReq = new URLRequest("text_philosophy.txt");
    function philosophyTextLoaded(event:Event):void {
        philText_mc.philosophy_txt.text = textLoader.data;
        minScroll = philText_mc.y;
        maxScroll = minScroll - philText_mc.height + mask_mc.height;
    function dragScroller(event:MouseEvent):void
        var dragX:Number = line_mc.x - scroller_mc.width/2 + 1;
        var dragY:Number = line_mc.y;
        var dragW:Number = 0;
        var dragH:Number = line_mc.height - scroller_mc.height;
        scroller_mc.startDrag(false, new Rectangle(dragX,dragY,dragW,dragH));
        stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
        stage.addEventListener(Event.ENTER_FRAME, setScrollPercent);
        stage.removeEventListener(Event.ENTER_FRAME, scrollText);
    function stopDragging(event:MouseEvent):void
        scroller_mc.stopDrag();
    function setScrollPercent(event:Event):void
        scrollPercent = (scroller_mc.y - line_mc.y) / (line_mc.height - scroller_mc.height);
        if(scrollPercent < 0)
            scrollPercent = 0;
        else if(scrollPercent > 1)
            scrollPercent = 1;
        targetScroll = (scrollPercent * (maxScroll - minScroll)) + minScroll;
        philText_mc.y -= (philText_mc.y - targetScroll) / easing;
    function scrollUp(event:MouseEvent):void
        setDirection(scrollAmt);
    function scrollDown(event:MouseEvent):void
        setDirection(-scrollAmt);
    function setDirection(dir:Number):void
        scrollDirection = dir;
        stage.addEventListener(Event.ENTER_FRAME, scrollText);
        stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);
        stage.removeEventListener(Event.ENTER_FRAME, setScrollPercent);
    function scrollText(event:Event):void
        targetScroll += scrollDirection;
        philText_mc.y -= (philText_mc.y - targetScroll) / easing;
        if(philText_mc.y > minScroll)
            philText_mc.y = minScroll;
            targetScroll = minScroll;
        else if(philText_mc.y < maxScroll)
            philText_mc.y = maxScroll;
            targetScroll = maxScroll;
        scrollPercent = (philText_mc.y - minScroll) / (maxScroll - minScroll);
        scroller_mc.y = (scrollPercent * (line_mc.height - scroller_mc.height)) + line_mc.y;
    function stopScrolling(event:MouseEvent):void
        scrollDirection = 0;
    textLoader.load(textReq);
    scroller_mc.buttonMode = true;
    philText_mc.external_txt.autoSize = TextFieldAutoSize.LEFT;
    scroller_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragScroller);
    textLoader.addEventListener(Event.COMPLETE, philosophyTextLoaded);
    up_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollUp);
    down_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollDown);

    Hello again,
    Maybe I am asking this question wrong. Instead of making you try and figure out what's going on in my file what I really need to know is how you would take this code I am attaching and make it happen on another frame besides frame 1 and it doesn't appear on frame 1. I think this may help me understand a little better.
    Also another way I was thinking to get around this would be to pull in an external swf into the spot where I want this text to go because I can make the scrollbars and external text work when it is the only thing going on in the movie. Would this be a bad way to set this up? and also SInce it is an external movie would I have maintimeline issues with mouse/scroller control?
    thanks! sandra
    Here is working code:
    var textLoader:URLLoader = new URLLoader();
    var textFile:URLRequest = new URLRequest("text/external.txt");
    var scrollPercent:Number = 0;
    var minScroll:Number;
    var maxScroll:Number;
    var targetScroll:Number = text_mc.y;
    var easing:Number = 5;
    var scrollAmt:Number = 15;
    var scrollDirection:Number = 0;
    function textLoaded(event:Event):void
        text_mc.external_txt.text = textLoader.data;
        minScroll = text_mc.y;
        maxScroll = minScroll - text_mc.height + mask_mc.height;
    function dragScroller(event:MouseEvent):void
        var dragX:Number = line_mc.x - scroller_mc.width/2 + 1;
        var dragY:Number = line_mc.y;
        var dragW:Number = 0;
        var dragH:Number = line_mc.height - scroller_mc.height;
        scroller_mc.startDrag(false, new Rectangle(dragX,dragY,dragW,dragH));
        stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
        stage.addEventListener(Event.ENTER_FRAME, setScrollPercent);
        stage.removeEventListener(Event.ENTER_FRAME, scrollText);
    function stopDragging(event:MouseEvent):void
        scroller_mc.stopDrag();
    function setScrollPercent(event:Event):void
        scrollPercent = (scroller_mc.y - line_mc.y) / (line_mc.height - scroller_mc.height);
        if(scrollPercent < 0)
            scrollPercent = 0;
        else if(scrollPercent > 1)
            scrollPercent = 1;
        targetScroll = (scrollPercent * (maxScroll - minScroll)) + minScroll;
        text_mc.y -= (text_mc.y - targetScroll) / easing;
    function scrollUp(event:MouseEvent):void
        setDirection(scrollAmt);
    function scrollDown(event:MouseEvent):void
        setDirection(-scrollAmt);
    function setDirection(dir:Number):void
        scrollDirection = dir;
        stage.addEventListener(Event.ENTER_FRAME, scrollText);
        stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);
        stage.removeEventListener(Event.ENTER_FRAME, setScrollPercent);
    function scrollText(event:Event):void
        targetScroll += scrollDirection;
        text_mc.y -= (text_mc.y - targetScroll) / easing;
        if(text_mc.y > minScroll)
            text_mc.y = minScroll;
            targetScroll = minScroll;
        else if(text_mc.y < maxScroll)
            text_mc.y = maxScroll;
            targetScroll = maxScroll;
        scrollPercent = (text_mc.y - minScroll) / (maxScroll - minScroll);
        scroller_mc.y = (scrollPercent * (line_mc.height - scroller_mc.height)) + line_mc.y;
    function stopScrolling(event:MouseEvent):void
        scrollDirection = 0;
    textLoader.load(textFile);
    scroller_mc.buttonMode = true;
    text_mc.external_txt.autoSize = TextFieldAutoSize.LEFT;
    scroller_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragScroller);
    textLoader.addEventListener(Event.COMPLETE, textLoaded);
    up_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollUp);
    down_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollDown);

  • Constructor in document class runs twice?

    Hi Folks,
    I'm working on my document class and the contructor is running twice, hence it is running almost all of my code twice.  I'm not quite sure why this is the case.  Any help is appreciated.
    I've attached my code below.
    package {
    import flash.display.MovieClip;
    import flash.display.DisplayObject;
    import flash.events.*;
    import flash.geom.*;
    import flash.net.*;
    import flash.utils.getDefinitionByName;
    public class ASIFL048_DND extends MovieClip {
      private var startDragX:Number = new Number();
      private var startDragY:Number = new Number();
      private var xmlPath:String = "../ObjectFiles/xmlIFL0480016.xml";
      private var itemList:Array = new Array();
      private var targetList:Array = new Array();
      private var gameArray:Array = new Array();
      private var myXML:XML = new XML();
      private var myTargetName:String = new String();
      private var XMLLoader:URLLoader = new URLLoader();
      private var XMLRequest:URLRequest = new URLRequest(xmlPath);
      trace("RUNNING ONCE!");
      public function ASIFL048_DND() {
       stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
       stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
       XMLLoader.addEventListener(Event.COMPLETE, completeHandler);
       trace("RUNNING TWICE?");
       loadXML();
      private function loadXML():void {
       //var XMLLoader:URLLoader = new URLLoader();
       //var XMLRequest:URLRequest = new URLRequest(xmlPath);
       XMLLoader.load(XMLRequest);
       //XMLLoader.addEventListener(Event.COMPLETE, completeHandler);
      private function completeHandler(e:Event):void {
       myXML = XML(e.target.data);
       var i:int = 0;
       var j:int = 0;
       for each (var item:XML in myXML..equip) {
        itemList[i] = item.@name;
        for each (var target:XML in item..myTarget) {
         targetList[j] = [i,target];
         j++;
        i++;
       //trace(targetList);
       selectDragItems(10);
      private function selectDragItems(gameLength:int):void {
       var randomSeed:Number = new Number();
       var randomItem:Number = new Number();
       for (var k:int = 0; k<gameLength; k++) {
        randomSeed = targetList.length;
        randomItem = Math.floor(Math.random() * targetList.length);
        gameArray = targetList.splice(randomItem, 1);
        trace(gameArray+"\n");
        //display game array
        //trace("CLASS:\t"+itemList[gameArray[k][0][0]]);
             //var ClassReference:Class = getDefinitionByName(itemList[gameArray[k][0]]) as Class;
        //var instance:Object = new ClassReference();
        //addChild(DisplayObject(instance));
      private function mouseDownHandler(e:MouseEvent):void {
       startDragX = e.target.x;
       startDragY = e.target.y;
       trace(startDragX + " " + startDragY);
       e.target.startDrag(true,new Rectangle(e.target.width/2,e.target.height/2, stage.stageWidth-e.target.width, stage.stageHeight-e.target.height));
      private function mouseUpHandler(e:MouseEvent):void {
       stopDrag();
       myTargetName = "fwdLHWindscreen_mc";
       var myTarget:DisplayObject = getChildByName(myTargetName);
       //trace(" TARGET VAR: "+myTarget.name);
       if (e.target.dropTarget != null && e.target.dropTarget.parent == myTarget) {
        trace("correct");
        e.target.x = e.target.dropTarget.parent.x;
        e.target.y = e.target.dropTarget.parent.y;
        e.target.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        e.target.removeEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
       } else {
        trace("incorrect");
        e.target.x = startDragX;
        e.target.y = startDragY;

    My bad. The order of output is:
    RUNNING ONCE!
    RUNNING TWICE?
    The first trace is a static initializer, while the second is in the constructor.

  • Link doesn't work in an external htmlText

    Hello!!!
    I am trying to fix this problem. My external text display fine and also the CSS. The problem is
    when I am using any tag in html like <a> doesn't work, doesn't try to open the link and also the mouse
    doesn't change to the default hand. I am attaching my code in AS3. If you see I am using a scroller
    and also a mask. Could you try to help me please?
    Thanks in advance!!!
    J
    var textLoader:URLLoader = new URLLoader();
    var textReq:URLRequest = new URLRequest("text/news.txt");
    var cssLoader:URLLoader = new URLLoader();
    var cssRequest:URLRequest = new URLRequest("styles/style.css");
    var style:StyleSheet = new StyleSheet();
    var scrollPercent:Number = 0;
    var minScroll:Number;
    var maxScroll:Number;
    var targetScroll:Number = text_mc.y;
    var easing:Number = 5;
    var scrollAmt:Number = 15;
    var scrollDirection:Number = 0;
    function textLoaded(event:Event):void
    cssLoader.load(cssRequest);
    cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
    text_mc.external_txt.htmlText = textLoader.data;
    minScroll = text_mc.y;
    maxScroll = minScroll - text_mc.height + mask_mc.height;
    function cssLoaded(event:Event):void
    style.parseCSS(cssLoader.data);
    text_mc.external_txt.styleSheet = style;
    text_mc.external_txt.htmlText = textLoader.data;
    function dragScroller(event:MouseEvent):void
    var dragX:Number = line_mc.x - scroller_mc.width/2 + 1;
    var dragY:Number = line_mc.y;
    var dragW:Number = 0;
    var dragH:Number = line_mc.height - scroller_mc.height;
    scroller_mc.startDrag(false, new Rectangle(dragX,dragY,dragW,dragH));
    stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    stage.addEventListener(Event.ENTER_FRAME, setScrollPercent);
    stage.removeEventListener(Event.ENTER_FRAME, scrollText);
    function stopDragging(event:MouseEvent):void
    scroller_mc.stopDrag();
    function setScrollPercent(event:Event):void
    scrollPercent = (scroller_mc.y - line_mc.y) / (line_mc.height - scroller_mc.height);
    if(scrollPercent < 0)
    scrollPercent = 0;
    else if(scrollPercent > 1)
    scrollPercent = 1;
    targetScroll = (scrollPercent * (maxScroll - minScroll)) + minScroll;
    text_mc.y -= (text_mc.y - targetScroll) / easing;
    function scrollUp(event:MouseEvent):void
    setDirection(scrollAmt);
    function scrollDown(event:MouseEvent):void
    setDirection(-scrollAmt);
    function setDirection(dir:Number):void
    scrollDirection = dir;
    stage.addEventListener(Event.ENTER_FRAME, scrollText);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);
    stage.removeEventListener(Event.ENTER_FRAME, setScrollPercent);
    function scrollText(event:Event):void
    targetScroll += scrollDirection;
    text_mc.y -= (text_mc.y - targetScroll) / easing;
    if(text_mc.y > minScroll)
    text_mc.y = minScroll;
    targetScroll = minScroll;
    else if(text_mc.y <maxScroll)
    text_mc.y = maxScroll;
    targetScroll = maxScroll;
    scrollPercent = (text_mc.y - minScroll) / (maxScroll - minScroll);
    scroller_mc.y = (scrollPercent * (line_mc.height - scroller_mc.height)) +
    line_mc.y;
    function stopScrolling(event:MouseEvent):void
    scrollDirection = 0;
    textLoader.load(textReq);
    scroller_mc.buttonMode = true;
    text_mc.external_txt.autoSize = TextFieldAutoSize.LEFT;
    scroller_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragScroller);
    textLoader.addEventListener(Event.COMPLETE, textLoaded);
    up_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollUp);
    down_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollDown);

    Hi Kglad,
    I have this in news.txt:
    <span class="title">FUTURE ENGAGEMENTS</span>
    JUNE 2009
    Dates                 1,3,5,7,8,9
    Role                  Fenton (Cover)
    Event                Falstaff
    Company            <a href="http://www.yahoo.com">Glyndebourne Opera Festival </a>
    NOVEMBER 2009
    <span class="titles">Dates</span> 1,3,5,7,8,9
    <span class="titles">Role</span> Fenton (Cover)
    <span class="titles">Event</span> Falstaff
    <span class="titles">Company</span> Glyndebourne Opera Festival
    Thanks!!!
    J

  • Compiler Error: 1120 / 1067. please help!

    I've been stuck on this error for a whole day now, trying to find out whats wrong. im new to AS3, but i have been following the tutorials with lynda.com
    i've been trying to make a scrollbar and everything works fine, until i have to connect it with the text. theres an image and a title that i want to scroll with the (static) text so i created a movie clip (instance name cafe_txt), and when i wrote the script and tested the movie, i come up with the 1120 error that cafe_txt is not defined.
    So i changed the clip(thinking that the problem was the scrollbar had to be in the same instance as the text) so that the scrollbar was inside, and i come up with error 1067(1067: Implicit coercion of a value of type flash.display:MovieClip to an unrelated type flash.text:TextField.)
    I've tried changing names, double checking that instance names are correct, moving things, changing the text so that its dynamic not static(if the scrollbar is connected to just the dynamic text it works, it just doesnt scroll the full length of the text)
    here's the code in my stage:
    scrollbar_mc.textField = cafe_txt
    and my code from the scrollbar.as file:
    package com.lynda.ui
        import flash.display.*;
        import flash.events.*;
        import flash.geom.Rectangle;
        import flash.text.TextField;
        public class Scrollbar extends Sprite
            public var value:Number;
            public var padding:Number = 5;
            private var _textField:TextField;
            private var max:Number;
            private var min:Number;
            public function Scrollbar()
                min = bar_mc.y;
                max = bar_mc.height - drag_mc.height;
                drag_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
            private function dragHandle(event:MouseEvent):void
                drag_mc.startDrag(false, new Rectangle(0,min,0,max));
                stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
                stage.addEventListener(MouseEvent.MOUSE_MOVE, updateValue);
            private function stopDragging(event:MouseEvent):void
                drag_mc.stopDrag();
                stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
                stage.removeEventListener(MouseEvent.MOUSE_MOVE, updateValue);
            private function updateValue(event:MouseEvent=null):void
                value = (drag_mc.y - min) / max;
                if(_textField && event)
                    _textField.scrollV = Math.ceil(value * _textField.maxScrollV);
                dispatchEvent(new Event(Event.CHANGE));
            public function set textField(tf:TextField):void
                _textField = tf;
            public function get textField():TextField
                return _textField;
    thanks for the help...

    click file/publish settings/flash and tick "permit debugging".  retest.  the problematic line of code will be listed in the error message.
    copy and paste the error message and highlight the problematic line of code.

  • Run automatically FLVPlayer

    Hi
    I'm a FLVPlayer
    I want to run automatically after being executed. But now I do not know how to change the code.
    Class code is as follows:
    package Classes
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.NetStatusEvent;
    import flash.events.TimerEvent;
    import flash.geom.Rectangle;
    import flash.media.SoundTransform;
    import flash.media.Video;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.net.NetStreamAppendBytesAction;
    import flash.system.System;
    import flash.utils.Timer;
    import flash.utils.setTimeout;
    dynamic public class VideoPlayer extends MovieClip
      public var FirstTimeShow:int=300;//in stop display first ,
      public const DEFAULT_VOLUME:Number    = 0.6;
      public const SMOOTHING:Boolean     = true;
      private const BUFFER_TIME:Number    = 8;
      private var ncConnection:NetConnection;
      private var nsStream:NetStream;
      private var vidDisplay:Video;
      private var objInfo:Object;
      private var MainTime:Number=0;
      private var StreamTime:Number=0;
      private var strSource:String     = "";
      private var CanStart:Boolean=false;
      private var TotalTime:Number=0;
      private var intLastVolume:Number    = 0;
      private var CanAutoSeek:Boolean=false;
      private var _DisplayMode:Boolean=false;
      private var _firstTime:Number=0;
      private var EmbedMode:Boolean=false;
      private var Started:Boolean=false;
      public function VideoPlayer():void
       if(stage)
        initVideoPlayer();
       else
        addEventListener(Event.ADDED_TO_STAGE,initVideoPlayer);
      private function initVideoPlayer(evt:Event=null):void
       removeEventListener(Event.ADDED_TO_STAGE,initVideoPlayer);
       PreSettings();
      private function PreSettings():void
       CanStart=true;
      public function Start(address:String,FirstDisplay:Boolean=false,Time:int=3):void
       if(CanStart&&!Started)
        Started=true;
        EmbedMode=false;
        intLastVolume=DEFAULT_VOLUME;
        strSource=address;
        _firstTime=(Time>=0)?Time:StreamTime;
        _DisplayMode=FirstDisplay;
        MainTime=_firstTime;
        Panel.Timeline.AreaFill.Red.width = 1;
        Panel.Timeline.AreaFill.Gray.width = 1;
        Panel.Timeline.AreaFill.mouseEnabled=false;
        Panel.Timeline.AreaFill.mouseChildren=false;
        Panel.S.SHandle.buttonMode=true;
        Panel.Timeline.Handle.buttonMode=true;
        ncConnection=new NetConnection();
        ncConnection.connect(null);
        nsStream = new NetStream(ncConnection);
        nsStream.client = this;
        nsStream.soundTransform=new SoundTransform(intLastVolume);
        //================================Not Very Important
        nsStream.inBufferSeek=true;
        nsStream.bufferTime = BUFFER_TIME;
        //================================
        vidDisplay=new Video();
        vidDisplay.attachNetStream(nsStream);
        nsStream.play(strSource);
        vidDisplay.smoothing = SMOOTHING;
        //===============================================ShowAll Placement OF Video
        var FirstW:Number=VidContainer.width;
        var FirstH:Number=VidContainer.height;
        var H:Number=0;
        var W:Number=0;
        var Width:Number=VidContainer.width;
        var Height:Number=VidContainer.height;
        if(vidDisplay.width>=vidDisplay.height)
         H=FirstH*(Width/FirstW);
         W=Width;
         if(H>Height)
          H=Height;
          W=FirstW*(H/FirstH);
        else
         W=FirstW*(Height/FirstH);
         H=Height;
         if(W>Height)
          W=Width;
          H=FirstH*(W/FirstW);
        vidDisplay.width=W;
        vidDisplay.height=H;
        VidContainer.addChild(vidDisplay);
        vidDisplay.x=(Width/2)-(W/2);
        vidDisplay.y=(Height/2)-(H/2);
        //==================================================================================
        Panel.S.SHandle.x =((Panel.S.SArea.width-Panel.S.SHandle.width) * intLastVolume);
        Panel.S.Red.width = Panel.S.SHandle.x;
        Panel.btnPause.IDBTN = "PauseGo";
        Panel.btnPlay.IDBTN = "PlayGo";
        Panel.btnMute.IDBTN="MuteGo";
        Panel.btnUnmute.IDBTN="UnMuteGo";
        Panel.btnUnmute.visible = false;
        setVolume(intLastVolume);
      public function StartBytes(_ns:NetStream,FirstDisplay:Boolean=true,Time:int=-1):void
       if(CanStart)
        Started=true;
        EmbedMode=true;
       //@1Comments
      private function setVolume(intVolume:Number = 0):void
       if(intVolume>=0&&intLastVolume<=1)
        var newTransform:SoundTransform=new SoundTransform();
        newTransform.volume=intVolume;
        nsStream.soundTransform=newTransform;
      public function onMetaData(info:Object):void
       objInfo = info;
       TotalTime=objInfo.duration;
       nsStream.pause();
       if(!_DisplayMode)
        Panel.btnPause.visible = false;
        Panel.btnPlay.visible = true;
        CanAutoSeek=false;
       else
        Panel.btnPause.visible = true;
        Panel.btnPlay.visible = false;
        CanAutoSeek=true;
       StartEvents(true);
       setTimeout(PlayGo,10);
      private function playClicked(evt:MouseEvent):void
       if(evt.currentTarget.IDBTN=="PauseGo")
        Panel.btnPause.visible = false;
        Panel.btnPlay.visible = true;
        nsStream.pause();
        MainTime=nsStream.time;
        StreamTime=nsStream.time;
        CanAutoSeek=false;
        _DisplayMode=false;
       else if(evt.currentTarget.IDBTN=="PlayGo")
        Panel.btnPause.visible = true;
        Panel.btnPlay.visible = false;
        CanAutoSeek=true;
        nsStream.seek(MainTime);
        nsStream.resume();
        _DisplayMode=true;
      private function PlayGo():void
       if(nsStream!=null)
        if(MainTime>0&&MainTime<=TotalTime)MainTime=MainTime;
        else MainTime=StreamTime;
        nsStream.seek(MainTime);
        if(_DisplayMode) nsStream.resume();
       Panel.Timeline.Handle.x=(MainTime/TotalTime)*(Panel.Timeline.Area.width-Panel.Timeline.Handle.width);
       Panel.Timeline.AreaFill.Red.width = Panel.Timeline.Handle.x;
      private function StartEvents(Pos:Boolean):void
       if(Pos)
        nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        if(ncConnection!=null)ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        Panel.Timeline.Handle.addEventListener(MouseEvent.MOUSE_DOWN, SeekHandleDrag);
        Panel.Timeline.Area.addEventListener(MouseEvent.CLICK, playCustomClicked);
        Panel.btnPause.addEventListener(MouseEvent.CLICK, playClicked);
        Panel.btnPlay.addEventListener(MouseEvent.CLICK, playClicked);
        Panel.btnStop.addEventListener(MouseEvent.CLICK, stopClicked);
        Panel.S.SHandle.addEventListener(MouseEvent.MOUSE_DOWN, VolDrag);
        Panel.btnMute.addEventListener(MouseEvent.CLICK, UmuteClicked);
        Panel.btnUnmute.addEventListener(MouseEvent.CLICK, UmuteClicked);
        if(stage)stage.addEventListener( MouseEvent.MOUSE_UP, mouseReleased);
        addEventListener(Event.ENTER_FRAME,runtime);
       else
        if(nsStream)nsStream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        if(ncConnection!=null)ncConnection.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        Panel.Timeline.Handle.removeEventListener(MouseEvent.MOUSE_DOWN, SeekHandleDrag);
        Panel.Timeline.Area.removeEventListener(MouseEvent.CLICK, playCustomClicked);
        Panel.btnPause.removeEventListener(MouseEvent.CLICK, playClicked);
        Panel.btnPlay.removeEventListener(MouseEvent.CLICK, playClicked);
        Panel.btnStop.removeEventListener(MouseEvent.CLICK, stopClicked);
        Panel.S.SHandle.removeEventListener(MouseEvent.MOUSE_DOWN, VolDrag);
        Panel.btnMute.removeEventListener(MouseEvent.CLICK, UmuteClicked);
        Panel.btnUnmute.removeEventListener(MouseEvent.CLICK, UmuteClicked);
        if(stage)stage.removeEventListener( MouseEvent.MOUSE_UP, mouseReleased);
        removeEventListener(Event.ENTER_FRAME,runtime);
      private function netStatusHandler(evt:NetStatusEvent):void
       switch (evt.info.code)
        case "NetStream.Play.StreamNotFound":
         trace("Stream not found! From VideoPlayer");
        break;
        case "NetStream.Play.Stop":
         trace("NetStream.Play.Stop From VideoPlayer");
         stopClicked(null);
        break;
        default:
         //trace("Progressing...");
         break;
      private function runtime(evt:Event):void
       var timeStream:Number=nsStream.time;
       var h:int=Math.floor(Math.abs(timeStream/3600));
       var m:int=Math.floor(Math.abs((timeStream-(h*3600))/60));
       var s:int=Math.abs(timeStream-((h*3600)+(m*60)));
       Panel.TXT.text=String(h)+" : "+String(m)+" : "+String(s);
       if(CanAutoSeek)
        Panel.Timeline.Handle.x=(timeStream/TotalTime)*(Panel.Timeline.Area.width-Panel.Timeline.Handle.width);
        Panel.Timeline.AreaFill.Red.width = Panel.Timeline.Handle.x;
        if(timeStream>=TotalTime)
         stopClicked(null);
      private function playCustomClicked(evt:MouseEvent):void
       if(Panel.mouseX<=Panel.Timeline.Area.width-Panel.Timeline.Handle.width)
        CanAutoSeek=false;
        nsStream.pause();
        Panel.Timeline.Handle.x=Panel.mouseX;
        Panel.Timeline.AreaFill.Red.width = Panel.Timeline.Handle.x;
        MainTime=(Panel.Timeline.Handle.x/(Panel.Timeline.Area.width-Panel.Timeline.Handle.width))*TotalTime;
        StreamTime=MainTime;
        nsStream.seek(MainTime);
        if(_DisplayMode)nsStream.resume();
        CanAutoSeek=true;
       else
        stopClicked(null);
      private function stopClicked(e:MouseEvent):void
       Panel.btnPause.visible = false;
       Panel.btnPlay.visible  = true;
       StreamTime=0;
       MainTime=0;
       nsStream.pause();
       nsStream.seek(MainTime);
       Panel.Timeline.Handle.x=0;
       Panel.Timeline.AreaFill.Red.width = Panel.Timeline.Handle.x;
       _DisplayMode=false;
      private function UmuteClicked(evt:MouseEvent):void
       if(evt.currentTarget.IDBTN=="MuteGo")
        intLastVolume=nsStream.soundTransform.volume;
        setVolume(0);
        Panel.S.SHandle.x    = 0;
        Panel.S.Red.width = 0;
        Panel.btnMute.visible  = false;
        Panel.btnUnmute.visible = true;
       else if(evt.currentTarget.IDBTN=="UnMuteGo")
        Panel.S.SHandle.x = (Panel.S.SArea.width-Panel.S.SHandle.width)*intLastVolume;
        Panel.S.Red.width = Panel.S.SHandle.x;
        Panel.btnMute.visible  = true;
        Panel.btnUnmute.visible = false;
        setVolume(intLastVolume);
      private function VolDrag(e:MouseEvent):void
       Panel.S.SHandle.startDrag(false, new Rectangle(0, 0, Panel.S.SArea.width-Panel.S.SHandle.width, 0));
       stage.addEventListener(MouseEvent.MOUSE_MOVE,moveSound);
      private function moveSound(evt:MouseEvent):void
       setTimeout(SoundSet,100);
      private function SoundSet():void
       Panel.S.Red.width = Panel.S.SHandle.x;
       var newTransform:SoundTransform=new SoundTransform(Panel.S.SHandle.x/(Panel.S.SArea.width-Panel.S.SHandle.width));
       nsStream.soundTransform=newTransform;
      private function SeekHandleDrag(e:MouseEvent):void
       CanAutoSeek=false;
       nsStream.pause();
       MainTime=nsStream.time;
       StreamTime=nsStream.time;
       Panel.Timeline.Handle.startDrag(false,new Rectangle(0,3,Panel.Timeline.Area.width-Panel.Timeline.Handle.width,0));
       stage.addEventListener(MouseEvent.MOUSE_MOVE,moveHandleSlider);
      private function moveHandleSlider(evt:MouseEvent):void
       setTimeout(MovieSeekDrag,50);
      private function MovieSeekDrag():void
       Panel.Timeline.AreaFill.Red.width = Panel.Timeline.Handle.x;
       MainTime=(Panel.Timeline.Handle.x/(Panel.Timeline.Area.width-Panel.Timeline.Handle.width))*TotalTime;
       nsStream.seek(MainTime);
      private function mouseReleased(e:MouseEvent):void
       Panel.S.SHandle.stopDrag();
       Panel.Timeline.Handle.stopDrag();
       try
        stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveSound);
        stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandleSlider);
       catch(Err:Error){}
       if(!CanAutoSeek&&_DisplayMode)
        CanAutoSeek=true;
        nsStream.seek(MainTime);
        nsStream.resume();
      public function Distructor():void
       if(CanStart)
        removeEventListener(Event.ADDED_TO_STAGE,initVideoPlayer);
        Started=false;
        StartEvents(false);
        Panel.S.SHandle.stopDrag();
        Panel.Timeline.Handle.stopDrag();
        if(stage)stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveSound);
        if(stage)stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandleSlider);   
        try
         nsStream.pause();
         nsStream.close();
        catch(Err:Error)
        try
         ncConnection.close();
        catch(Err:Error)
        try
         vidDisplay.clear();
        catch(Err:Error)
        try
         VidContainer.removeChild(vidDisplay);
        catch(Err:Error){}
        objInfo=null;
        MainTime=0;
        StreamTime=0;
        strSource     = "";
        TotalTime=0;
        intLastVolume    = 0;
        CanAutoSeek=false;
        _DisplayMode=false;
        _firstTime=0;
        ncConnection=null;
        vidDisplay=null;
        nsStream=null;
        System.gc();

    hi
    yes i have it
    and above code was class
    i attached flv file &  thx a lot
    http://www.dgfhfhhg.com/VideoPlayer.rar

Maybe you are looking for