9 Replies Latest reply on Jun 11, 2011 4:32 PM by kglad

    Going fullscreen and playing files in order not randomly

    lifesabox

      Hey guys,

       

      I'm working on an AS 3 file but I can't make it go to fullscreen.
      The other problem is that it plays a list of youtube video's,
      but I want it to be just looping the list, not playing them randomly.

       

      Can anybody help? The script is below.
      If anybody could help me, that would be awesome!

       

      Thanks!

       

      Raoul

       


      package 
      {
          import flash.display.*;
          import flash.display.MovieClip;
          import flash.display.StageAlign;
          import flash.display.StageScaleMode;
          import flash.events.Event;
          import flash.events.MouseEvent;
          import flash.filters.*;
          import flash.system.Security;
          import itaynoy.filters.pixelate.Pixelate;
          import youtube.youtubePlayer;
          import flash.events.MouseEvent;
          import flash.ui.Mouse;
          import flash.display.StageDisplayState;
          Mouse.hide();
          /**
           * ...
           * @author Itay Noy
           */
          public class stageMain extends MovieClip
          {
              var n1 = 75;
              //youtube player instance
              private var m_youtubePlayer:youtubePlayer;
             
              //button to switch videos
              private var m_stageBT:MovieClip;
             
              //black background for the player
              private var m_BG:MovieClip;
             
              //The pixel bender filter object
              private var m_Filter:Pixelate;
             
              // An array of youtube videos ID's
              private var movies_arr:Array;
             
              //the width of the player
              private var playerW:int     =     600;
             
              //the height of the player       
              private var playerH:int        =    480;
             
              //x position of the player
              private var playerX:int        =    20;
             
              //y position of the player
              private var playerY:int        =    20;
             
             
              public function stageMain()
              {
                 
                  if (stage) {
                          init();
                  }else{
                      addEventListener(Event.ADDED_TO_STAGE, init);
                  }
                 
              }
             
              private function init(e:*= null) {
                 
                  //I'm chekcing maybe someone wanted his own videos from youtube and send their ID's in the flashvars
                  if (loaderInfo.parameters.movies_arr) {
                      movies_arr         = String(loaderInfo.parameters.movies_arr).split("|");
                  }else {
                      movies_arr         = String("LhOl6BT18RU|QNik8pOFAmo|V6deTsUYk5E|a2jKgExxf9I|4yj29Eo61u0|PQ3FnD6PhZM|Xo1yHvavR Zc|b4r86C4agtc|4fDwjO-5rD4|QWG-Cg44Zu4|zJFdF8Wqz7Q|3ZSspsY0l-U|UKh8wPdkISc|AAZ-7cJMXUI|qUw 6cLL-i-o|tUZ944WWrws|yF3Dq4I5WS4|YF-xLB4wTlA|4rsWY_CpyrU|mKInjxOH3yA|e1b55B0u0P|E6Dm6Tr4cO I|kxv-DDtQ8n0|ujwQtM43guk|gOgTQCAUOCY|8ndVF18OKeQ|fuu9jDIvCvs|eZ4XUPku7Sg|0I7Lw6RMUUs|xoEt xEdgsJk|jnRzZeD2ysw|IinsiPUMkvE|GVV6OcAgwm4|9GcDdr5auts|IY1YlLgsg-4|FGAnBQDJDVY|rRWbCZ6bcg Y|tp0CxA_zsow|cysJEh2jnK0|1BMPUPX6myU|fuDrL2yBSWw|KaYXNaBr_2E|rjQ_BTbCmSk|rJhBVy6DBr8|x7RU x2ucqv8|_4ID6-e0-PY|n7frx-2P8cQ|McDnwiJaSA4|WWB816SHtBc|3YZ8zpY52ww|P_cKWpdKVBY|bVhM-ODIU6 I|bsUgrUcEoII|NeBN6YNSnc0|mc8uNO4-E8M|BBFDUBJeSiI|CNov_UG71bA|OJsdA91Lu18|hHboJXGXEWg|aIZo n7owttQ|aIZon7owttQ|i-IzVwmwdqE|bsAlSmLaZVE|7flXwSv9aQ0|7lx5FRBQGK0|RUNV4m2heI8|kYFh9A-LLG U|L13OGjEpgy8|xrMDmU4fVnk|3-cN81qP8-4|f7qtq93CXX4|UpZxVyLCm1I|edxU1SQCZQU|5rq-B1VRwuk|2fKT fGc3f6k|rclpehNOIUg|iv5xWixtoI0|86ViV0PX2jo|XvTOnp3q6ac|nkjS-yI84Ts|nRIZUN9flHk|7-S8o_RPFM Q|shJPAcqmVew|x9ZP5AYYYqk|VZLX7BBuZGQ|kkESRqpthRE|zYvcmJiWGmU|xceq-68zJak|Dwox35cQ1vY|GCBp 7XjPyvs|").split("|");;
                  }
                  // define stage align and resize mode
                  setStage();
                 
                  // creat a black background for the player (design purpose only)
                  m_BG                     = new MovieClip();
                  m_BG.graphics.beginFill(0x000000, 1);
                  m_BG.graphics.drawRect(0, 0, playerW, playerH);
                 
                  // create the youtube player we're using in this demo
                  m_youtubePlayer         = new youtubePlayer();
                  m_youtubePlayer.addEventListener(youtubePlayer.PLAYER_READY, playerReadyHandler);
                  m_youtubePlayer.addEventListener(youtubePlayer.STATE, playerStateHandler);
                 
                  // create a button to switch random videos
                  m_stageBT                 = new MovieClip();
                  m_stageBT.buttonMode = true;
                  m_stageBT.graphics.beginFill(0xFF0000, 0);
                  m_stageBT.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
              //    m_stageBT.addEventListener(MouseEvent.CLICK, loadRandomVid);
                 
                  // add all assets to stage
                  addChild(m_BG);
                  addChild(m_youtubePlayer);
                  addChild(m_stageBT);
                  addChild(control);
                 
                 
                  //init the youtube player
                  m_youtubePlayer.init();
                 
                  stageResizeElements();
                 
              }
             
              private function playerReadyHandler(e:Event = null) {
                 
                  //youtube player is ready for action
                  m_youtubePlayer.player.setPlaybackQuality("large");
                  m_youtubePlayer.setSize(playerW, playerH);
                  // I load avideo to the player (the first one from the movie array in this case)
                  m_youtubePlayer.loadVideo(movies_arr[0]);
                 
                  // this is where the magic happens
                  // create a new instance of the filter and set the target movieclip (i.e. m_youtubePlayer)
                  m_Filter                 = new Pixelate(m_youtubePlayer);
                 
                  // next I create a loop to set the filter parameters
                  addEventListener(Event.ENTER_FRAME, applyFilterParams);
                 
              }
             
              private function playerStateHandler(e:Event) {
                  //trace("player state chAnged to ", e.target.state);
                  if (e.target.state==3)
                      stageResizeElements();
                  if (e.target.state == 0) {
                      //state 0 means the movie has ended, so we load a new random vid
                      loadRandomVid();
                  }
              }
             
              private function loadRandomVid(E:*= null) {
                  var i:Number             = Math.floor((Math.random()*movies_arr.length));
                  m_youtubePlayer.loadVideo(movies_arr[i]);
              }
              private function downHandler(event:MouseEvent):void {
      trace("downHandler");
      n1 = 1;
      }
          private function upHandler(event:MouseEvent):void {
      trace("upHandler");
      n1 = 75;
      }

             
              private function applyFilterParams(e:*= null) {
                  //I get the values from my control, in this case its the slider on stage
              m_stageBT.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
              m_stageBT.addEventListener(MouseEvent.MOUSE_UP, upHandler);
                  // var n1                     = control.mc_slider_noise1.value;
              //     var n1                     = 75;
                  // render their values to a textfields (obviously this is for demo purposes only)
                  control.txt1.text         = n1 + "px";
                  trace(control.txt1.text, n1);
                 
                  /*
                   apply all the values I've gathered to the filter
                      m_Filter.applyFilter(
                                  n1:Number                            = pixel size
                              );
                  */
                     
                  m_Filter.applyFilter(n1);
                 
              }
             
              private function setStage() {
                 
                  stage.scaleMode         = StageScaleMode.SHOW_ALL
                  stage.align             = StageAlign.TOP_LEFT;
                 
              }
             
              private function stageResizeElements() {
                 
                  // set the player width,height and position
                 
                  m_BG.x                     = playerX;
                  m_BG.y                     = playerY;
                  m_BG.width                 = playerW;
                  m_BG.height             = playerH;
                 
                  m_youtubePlayer.width     = playerW;
                  m_youtubePlayer.height    = playerH;
                  m_youtubePlayer.x         = playerX;
                  m_youtubePlayer.y         = playerY;
                 
                  m_stageBT.x             = playerX;
                  m_stageBT.y             = playerY;
                  m_stageBT.width         = playerW;
                  m_stageBT.height         = playerH;
                 
              }
             
          }

       

      }

        • 1. Re: Going fullscreen and playing files in order not randomly
          kglad Adobe Community Professional & MVP

          i don't see any code to make your app go fullscreen so i assume you're using an flvplayback component with a skin that contains a fullscreen button.  if so, make sure you're publishing an html that allows fullscreen.  ie, check your publish settings/html/template and select flash only - allow full screen.

           

          to play videos in a non-random fashion change loadRandom() to

           


                  private function loadRandomVid(E:*= null) {
                     // var i:Number             = Math.floor((Math.random()*movies_arr.length));
                      m_youtubePlayer.loadVideo(movies_arr[index]);

          index=(index+1)%movies_arr.length; 
                  }

           

          and initialize index with your other class variables:

           

          private var index:int=0;

          • 2. Re: Going fullscreen and playing files in order not randomly
            lifesabox Level 1

            Hi KGlad,

             

            Indeed there is no fullscreen code in there.

            All the code that I know works with the mouse key,

            and that function is already taken. So I was actually

            wondering if it is possible to make it go fullscreen with

            for instance the spacebar.

             

            I'm kinda new at this. Sorry.

             

            Thanks,

             

             

            Raoul

            • 3. Re: Going fullscreen and playing files in order not randomly
              kglad Adobe Community Professional & MVP

              1.  you should have an object that when clicked triggers fullscreen

              2.  if i understand you correctly, there's no such thing as "that function is already taken" in as3.  in as2, that was true.

              3.  are your flvs playing the way you want?

              4.  please mark correct/helpful answers, if there are any.

              1 person found this helpful
              • 4. Re: Going fullscreen and playing files in order not randomly
                lifesabox Level 1

                Hi KGlad,

                 

                Thanks for your reply.

                The playlist is playing in order now, not randomly, so thanks for that.

                The fullscreen is still a bit problematic.

                 

                The script makes a pixelate filter pop back to the normal video when clicked by the left mouse button.

                It will continue playing the playlist, but I want it to play fullscreen.

                 

                In order to go into fullscreen mode I will have to get there without using the mouse, since it is used

                to flick the filter on and off.

                 

                I think it needs to be done with a stage.addEventListener and a listener for Keyboard.SPACE,

                but I am to much of a noob to figure out how it would have to come together.

                 

                If you have any suggestions I'd appreciate it.

                 

                Thanks,

                 

                 

                Raoul

                • 5. Re: Going fullscreen and playing files in order not randomly
                  kglad Adobe Community Professional & MVP

                  there has to be user input to trigger fullscreen.  so, a keypress will work.

                   

                  i'm not sure what problem you're seeing and i'm not sure how triggering fullscreen with a keypress will be any different than a button click.

                   

                  what kind of filter are you using?  and when you go fullscreen the filter is removed?

                  • 6. Re: Going fullscreen and playing files in order not randomly
                    lifesabox Level 1

                    Hi Kglad,

                     

                    There isn't a big difference, only that I don't know how to make this script into a keystroke instead of a mouse click.

                    And the filter hopefully is still applied to the fullscreen video.

                    It is a realtime pixelate filter.

                     

                    http://activeden.net/item/realtime-video-pixelate-effect/157276

                     

                    The filter is lifted when the mouse is pressed.

                    So in order to keep that effect working, fullscreen needs to be activated in another way.

                    I was found the version for mouseevent, but want to turn it into a space click but I don't know

                    how.

                     

                    Thanks,

                     

                     

                    Raoul

                     

                     

                    03function goFullScreen():void
                    04{
                    05    if (stage.displayState == StageDisplayState.NORMAL) {
                    06        stage.displayState=StageDisplayState.FULL_SCREEN;
                    07    } else {
                    08        stage.displayState=StageDisplayState.NORMAL;
                    09    }
                    10}
                    11
                    12stage.addEventListener(MouseEvent.CLICK, _handleClick)
                    13
                    14function _handleClick(event:MouseEvent):void
                    15{
                    16    goFullScreen();
                    17}
                    • 7. Re: Going fullscreen and playing files in order not randomly
                      kglad Adobe Community Professional & MVP

                      if you only want video (flv) to go fullscreen you should be playing your video using the netstream class or an flvplayback component.  are you using one of those?

                       

                      or, when you said video, did you just mean you swf?

                      1 person found this helpful
                      • 8. Re: Going fullscreen and playing files in order not randomly
                        lifesabox Level 1

                        Yes, I think I ment my SWF.

                        I don't know if the filter will be applied when I use a netstream class or a flvplayback.

                        But I'll look into that as well.

                         

                        Thanks,

                         

                         

                        Raoul

                        • 9. Re: Going fullscreen and playing files in order not randomly
                          kglad Adobe Community Professional & MVP

                          :

                           

                          import flash.events.KeyboardEvent;

                           

                          stage.addEventListener(KeyboardEvent.KEY_DOWN,f);

                           

                          function f(e:KeyboardEvent):void{
                              if(e.keyCode==Keyboard.SPACE){
                                  stage.displayState=(stage.displayState=="normal")?"fullScreen":"normal";
                              }
                          }