A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Help me translate AS2 to AS3

  1. #1
    Member
    Join Date
    Feb 2009
    Posts
    49

    Help me translate AS2 to AS3

    Ok so I was looking for a nice tutorial on scrubbing through a video by mousing down over it and dragging through the frames but it couldn't actually find any (not a scrub bar where the flv loads).....

    But I've managed to get a hold of this AS2 code for what I'm trying to do. Now I know nothing about AS2 but I can sort of work out for myself whats going on here. But I cant translate it to AS3. Can someone please help me write this out in AS3 syntax/format

    PHP Code:
    onMouseDown = function() { //when the mouse is clicked
        
    mouseLocV _xmouse// mouseLoc = x co-ordinates of the mouse at time of clicking

        
    imgMC.onEnterFrame = function() {  //initiate a constant checking of the mouse x location 
            
    differenceV _xmouse mouseLocV//finds the difference between the current mouse location and the previous location
            
            
    differenceV differenceV 10//***makes the movieclip advance 1 frame for every 10 pixels the mouse moved
            
            
    gotoFrameV = (imgMC._currentframe differenceV) % imgMC.totalFrames//finds the remainder the use for which frame to go to
            
    imgMC.gotoAndStop(gotoFrameV); //stops the movieclip at the frame specified
            
    mouseLocV _xmouse// mouseLoc = the new x co-ordinates of the mouse 
        
    }
    }

    onMouseUp = function() { //when the mouse button is released
        
    delete imgMC.onEnterFrame//stop checking mouse position

    I tried this just off the top of my head but its way off...probably will make things worse trying to work off it

    PHP Code:
    stage.addEventListener(MouseEvent.MOUSE_DOWNscrub);
    stage.addEventListener(MouseEvent.MOUSE_UPstopScrub);
    video.addEventListener(Event.ENTER_FRAMEdiff);

    function 
    scrub (event:MouseEvent):void {
        var 
    mouseLocation mouseX;
        
        function 
    diff (e:Event):void {
            var 
    difference mouseX mouseLocation
            difference 
    difference /10;
            var 
    goToFrame = (video.currentFrame difference) % video.totalFrames;
            
    video.gotoAndStop(goToFrame);
            
    mouseLocation mouseX
        
    }
    }

    function 
    stopScrub (event:MouseEvent):void {
        
    delete video.ENTER_FRAME;
    }

    onMouseUp = function() { 
        
    delete imgMC.onEnterFrame


  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    I didn't compile this so there might be a couple errors, but this is roughly what the code should look like. I set it to use the entire video as a scrub surface but it would be a pretty easy change to use any other object (say a progress bar).

    PHP Code:
    video.addEventListener(MouseEvent.MOUSE_DOWNstartScrubbing);
    stage.addEventListener(MouseEvent.MOUSE_UPstopScrubbing);

    var 
    scrubbing:Boolean false;


    function 
    startScrubbing(e:MouseEvent):void{
        if(
    scrubbing){ return };
        
        
    scrubbing true;
        
    stage.addEventListener(MouseEvent.MOUSE_MOVEliveScrub);
        
    liveScrub(null);
    }

    function 
    stopScrubbing(e:MouseEvent):void{
        if(!
    scrubbing){ return };
        
        
    scrubbing false;
        
    stage.removeEventListener(MouseEvent.MOUSE_MOVEliveScrub);
    }

    function 
    liveScrub(e:MouseEvent):void{
        var 
    mouseLocation:Number stage.mouseX video.x;
        if(
    mouseLocation 0mouseLocation 0;
        if(
    mouseLocation video.widthmouseLocation video.width;

        var 
    mousePercentage:Number mouseLocation video.width;
        
        
    video.playheadPercentage mousePercentage;    


Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center