A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: using keypress to play video

  1. #1
    Junior Member
    Join Date
    Jul 2015
    Posts
    4

    using keypress to play video

    Hi All

    I'm making changes to a very old project that was made using AS2.

    I'm trying to give the user some hotkeys to trigger videos playing on a scoreboard.
    I'm using this code on a movie clip:-

    Code:
    onClipEvent (keyDown) {
    	//showing overlay on with control + e
    	if (Key.isDown(17) and Key.isDown(49))
    	{
    		var my_video:Video;// my_video is a Video object on the Stage
    		var my_nc:NetConnection = new NetConnection();
    		my_nc.connect(null);
    		var my_ns:NetStream = new NetStream(my_nc);
    		my_video.attachVideo(my_ns);
    		my_ns.play(_root.vid);
    		_root.my_video._alpha = 100;
    	}
    but its not doing much.

    I know that the same code on a button does the trick, but not it seems on a listener. I've also put something different within the it statement to check that the keypress trigger works and it does.

    Can anyone help me figure out why its not working?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You missed the _root for the video player,
    PHP Code:
    [onClipEvent (keyDown) {
        
    //showing overlay on with control + e
        //1 = 49
        // e = 69
        // 17 = control
        
    if (Key.isDown(17) && Key.isDown(49))
        {
            
    trace("1 & control are both pressed");

            var 
    my_video:Video;
            var 
    my_nc:NetConnection = new NetConnection();

            
    my_nc.connect(null);
            var 
    my_ns:NetStream = new NetStream(my_nc);

            
    _root.my_video.attachVideo(my_ns);
            
    my_ns.play("video.flv");// I used my video for testing

            //_root.my_video._alpha = 100;
        
    }


  3. #3
    Junior Member
    Join Date
    Jul 2015
    Posts
    4
    Perfect, that fixed it!
    Many thanks

    Quote Originally Posted by fruitbeard View Post
    Hi,

    You missed the _root for the video player,
    PHP Code:
    [onClipEvent (keyDown) {
        
    //showing overlay on with control + e
        //1 = 49
        // e = 69
        // 17 = control
        
    if (Key.isDown(17) && Key.isDown(49))
        {
            
    trace("1 & control are both pressed");

            var 
    my_video:Video;
            var 
    my_nc:NetConnection = new NetConnection();

            
    my_nc.connect(null);
            var 
    my_ns:NetStream = new NetStream(my_nc);

            
    _root.my_video.attachVideo(my_ns);
            
    my_ns.play("video.flv");// I used my video for testing

            //_root.my_video._alpha = 100;
        
    }


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