Skip navigation
Thijs1987
Currently Being Moderated

Need help with video-scroll

Mar 30, 2013 9:12 AM

Tags: #flash #video #3.0 #action_script_3 #flash_cs6 #mouse_position

Hello,

 

I need some help with a project. What I eventually want is that a webcam controls the mouse position and the mouse position

controls a video. But first I would like the part where the mouse position controls the video.

So if the mouse is on the left on your screen the video will be at the first frame and when you move you're mouse to

the right the video will play accordingly to the movement. and stop when the mouse is all the way to the right.

Effectivly the mouse scrolles through the video. It only needs to be on the x-axis.

 

I'm not that formilliar with flash so any help would be great

 

Thx!

Thijs

 
Replies
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 30, 2013 9:26 AM   in reply to Thijs1987

    by video, do you mean an flv or f4v?  if yes, are you playing the video in an flvplayback component?  or. using the netstream class?

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 30, 2013 11:26 AM   in reply to Thijs1987

    if flv_pb is your flvplayback component, you can use something like:

     

    import fl.video.MetadataEvent;

    import flash.events.MouseEvent;

     

    var duration:Number;

    var m,b:Number;

    var prevX:Number = 0;

     

    flv_pb.addEventListener(MetadataEvent.METADATA_RECEIVED,f);

    flv_pb.addEventListener(MouseEvent.MOUSE_MOVE,moveF);

     

    function moveF(e:MouseEvent):void{

        if(Math.abs(prevX-e.stageX)>100){  // you'll need to do something to prevent too frequent video seeks.

            flv_pb.seek(m*e.stageX+b);

            prevX = e.stageX;

        }

    }

    function f(e:MetadataEvent):void{

        paramF(0,0,stage.stageWidth,e.info.duration);

    }

    function paramF(x1:Number,y1:Number,x2:Number,y2:Number):void{

        m = (y1-y2)/(x1-x2);

        b = y1-m*x1;

    }

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 30, 2013 12:20 PM   in reply to Thijs1987

    do you have a skin for your component and is your component more than 100 px wide?  if yes, move the mouse over the skin (controls).

     

    if no, attach the listener to some other object.

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 30, 2013 2:53 PM   in reply to Thijs1987

    what you should do is designate a rectangle where users can use their mouse to scroll the video.  if that rectangle has instance name bar, you can use:

     

    var m,b:Number;

    var lastSeek:int = getTimer();

     

    flv_pb.addEventListener(MetadataEvent.METADATA_RECEIVED,f);

    bar.addEventListener(MouseEvent.MOUSE_MOVE,moveF);

     

    function f(e:MetadataEvent):void {

        paramF(0,0,stage.stageWidth,e.info.duration);

    }

     

    function moveF(e:MouseEvent):void {

        if(getTimer()-lastSeek>1000){

            flv_pb.seek(m*e.stageX+b);

            lastSeek = getTimer();

            flv_pb.play();

        }

    }

     

    function paramF(x1:Number,y1:Number,x2:Number,y2:Number):void {

        m = (y1 - y2) / (x1 - x2);

        b = y1 - m * x1;

    }

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 1, 2013 12:06 PM   in reply to Thijs1987

    you're welcome.

     

    (but that looks like code for timeline embedded video which is not recommended.  the code i suggested is better.)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points