Quiero hacer mi propio reproductor de vídeo de AS3

  • ScottG
  • Proficient
  • Proficient
  • No Avatar
  • Registrado: Jul 06, 2010
  • Mensajes: 280
  • Status: Offline

Nota Marzo 14th, 2012, 2:07 pm

Im bueno en AS2, pero quería hacer mi propio AS3 reproductor de vídeo al hacerlo me daría a entender bien el código. Este es probablemente el tema más fácil Ive publicado aquí principalmente desde Im nuevo en AS3 y sólo jugó con unos tid fragmentos de código.

Así que sé cómo hacerlo en AS2 pero AS3 me esta dando problemas. Tengo un reproductor de vídeo que se carga un archivo swf externo que contiene los botones y controles de las animaciones que hacen. Sin embargo, toda la funcionalidad será tratada por la película de raíz o pare no dependiendo de cómo desea llamarlo.

ACTIONSCRIPT Código: [ Select ]
 
// Make a url Loader object
var player_loader:URLLoader = new URLLoader();
 
// Setup and event listener
player_loader.addEventListener(Event.COMPLETE, setup_player);
 
// Load the XML file
player_loader.load(new URLRequest('config.xml'));
 
// Setup the player
function setup_player(e:Event):void {
   
   var xml_config:XML = new XML(e.target.data);
   
   var skin_loader:Loader = new Loader();
   // var skin_url:URLRequest = new URLRequest(xml_config.skin.text()); // This is how the skin will be loaded however for the sake test testing use the line below
   var skin_url:URLRequest = new URLRequest('skin.swf');
 
   skin_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, set_buttons);
   skin_loader.load(skin_url);
   player_controls.addChild(skin_loader);
   
}
 
function set_buttons(e:Event):void {
   trace('In Set Buttons');
      player_controls.play_button.addEventListener(MouseEvent.CLICK, play_video);
 
}
 
function play_video(e:MouseEvent):void {
   trace('clicked')
}
 
 
  1.  
  2. // Make a url Loader object
  3. var player_loader:URLLoader = new URLLoader();
  4.  
  5. // Setup and event listener
  6. player_loader.addEventListener(Event.COMPLETE, setup_player);
  7.  
  8. // Load the XML file
  9. player_loader.load(new URLRequest('config.xml'));
  10.  
  11. // Setup the player
  12. function setup_player(e:Event):void {
  13.    
  14.    var xml_config:XML = new XML(e.target.data);
  15.    
  16.    var skin_loader:Loader = new Loader();
  17.    // var skin_url:URLRequest = new URLRequest(xml_config.skin.text()); // This is how the skin will be loaded however for the sake test testing use the line below
  18.    var skin_url:URLRequest = new URLRequest('skin.swf');
  19.  
  20.    skin_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, set_buttons);
  21.    skin_loader.load(skin_url);
  22.    player_controls.addChild(skin_loader);
  23.    
  24. }
  25.  
  26. function set_buttons(e:Event):void {
  27.    trace('In Set Buttons');
  28.       player_controls.play_button.addEventListener(MouseEvent.CLICK, play_video);
  29.  
  30. }
  31.  
  32. function play_video(e:MouseEvent):void {
  33.    trace('clicked')
  34. }
  35.  
  36.  


Por lo que este código se carga cargará un XML cuando completa la piel una vez que la carga podría configurar las funciones de clic. todo esto funciona hasta configurar la función de clic
ACTIONSCRIPT Código: [ Select ]
player_controls.play_button.addEventListener(MouseEvent.CLICK, play_video);


Ahora sé que cuando lo hice con AS2 tuve que usar onLoadInit como este
ACTIONSCRIPT Código: [ Select ]
// Get the skin and make sure something is in it
var skin_swf = 'skin2.swf';
 
// Make a new movie clip loader for the skin
var SkinLoader:MovieClipLoader = new MovieClipLoader();
 
// Add a listener so we know when something has happened
SkinLoader.addListener(this);
 
// Load the skin into the empty movie clip
SkinLoader.loadClip(skin_swf, empty);
 
// This function is the onload listener for the skin loader. this is a must to have other wise there would be no way to communicate
// from the actions here to the buttons in the skin
function onLoadInit(mc:MovieClip) {
   control_bar.play_pause_button.onPress = function () {
     
      // Play the animation
      this.animation.gotoAndPlay('press');
   
   }
}
 
  1. // Get the skin and make sure something is in it
  2. var skin_swf = 'skin2.swf';
  3.  
  4. // Make a new movie clip loader for the skin
  5. var SkinLoader:MovieClipLoader = new MovieClipLoader();
  6.  
  7. // Add a listener so we know when something has happened
  8. SkinLoader.addListener(this);
  9.  
  10. // Load the skin into the empty movie clip
  11. SkinLoader.loadClip(skin_swf, empty);
  12.  
  13. // This function is the onload listener for the skin loader. this is a must to have other wise there would be no way to communicate
  14. // from the actions here to the buttons in the skin
  15. function onLoadInit(mc:MovieClip) {
  16.    control_bar.play_pause_button.onPress = function () {
  17.      
  18.       // Play the animation
  19.       this.animation.gotoAndPlay('press');
  20.    
  21.    }
  22. }
  23.  


Ive buscó el onLoadInit AS3 o algo que gusta y no parecen encontrar nada.

Así que en resumen tengo una swf(swf1) que carga un swf2 swf(swf2) tiene los botones y swf1 contiene el actionscipt para los botones en el swf2. Si alguien sabe cómo hacer esto o me puede dirigir alguna documentación que puede ayudar. Se agradece su ayuda.

Si descubro una solución que será publicarlo.
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Marzo 14th, 2012, 2:07 pm

  • ScottG
  • Proficient
  • Proficient
  • No Avatar
  • Registrado: Jul 06, 2010
  • Mensajes: 280
  • Status: Offline

Nota Marzo 14th, 2012, 2:47 pm

OK...me encanta cuando eso ocurre. Publicar mi problema y buscar la respuesta aquí es

ACTIONSCRIPT Código: [ Select ]
// Make a skin loader
var skin_loader:Loader = new Loader();
 
// Setup the player
function setup_player(e:Event):void {
   
   // Get and build the XML
   var xml_config:XML = new XML(e.target.data);
   
   // Make an url request object for the skin loader
   var skin_url:URLRequest = new URLRequest("skin.swf");
   
   // Load the skin
   skin_loader.load(skin_url);
   
   // Set the on complete listener
   skin_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, set_buttons);
   
}
 
// Setup the buttons
function set_buttons(e:Event):void {
     
   if(skin_loader.content) {
     
      // Add the movie clip to the container
      player_controls.addChild(skin_loader);
     
      // When you explicitly coerce the type to MovieClip, all works fine.
      var mc:MovieClip = skin_loader.content as MovieClip;
     
      // Set the button listeners
      mc.play_button.addEventListener(MouseEvent.CLICK, play_video);
   
   }
 
}
 
  1. // Make a skin loader
  2. var skin_loader:Loader = new Loader();
  3.  
  4. // Setup the player
  5. function setup_player(e:Event):void {
  6.    
  7.    // Get and build the XML
  8.    var xml_config:XML = new XML(e.target.data);
  9.    
  10.    // Make an url request object for the skin loader
  11.    var skin_url:URLRequest = new URLRequest("skin.swf");
  12.    
  13.    // Load the skin
  14.    skin_loader.load(skin_url);
  15.    
  16.    // Set the on complete listener
  17.    skin_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, set_buttons);
  18.    
  19. }
  20.  
  21. // Setup the buttons
  22. function set_buttons(e:Event):void {
  23.      
  24.    if(skin_loader.content) {
  25.      
  26.       // Add the movie clip to the container
  27.       player_controls.addChild(skin_loader);
  28.      
  29.       // When you explicitly coerce the type to MovieClip, all works fine.
  30.       var mc:MovieClip = skin_loader.content as MovieClip;
  31.      
  32.       // Set the button listeners
  33.       mc.play_button.addEventListener(MouseEvent.CLICK, play_video);
  34.    
  35.    }
  36.  
  37. }
  38.  


He tenido que mover la clase loader de piel fuera de la función de reproductor de instalación debido a la el hecho de que necesitaba acceso a la skin_loader en la función set_buttons. También mover el addChild a la función de conjunto de botones. He tenido que declarar que el contenido fue un clip de película por esta línea aquí
ACTIONSCRIPT Código: [ Select ]
var mc:MovieClip = skin_loader.content as MovieClip;
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Nota Marzo 14th, 2012, 2:59 pm

A veces escribir un post le permite ver las cosas que se han perdido antes, y a veces el tiempo es simplemente curioso. No sé cuántas veces he empezado a escribir un post y tampoco figura fuera mío mientras escribía TI o poco después. Alegre se encontró una resolución y había compartida para otros que vienen a través de un problema similar.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • ScottG
  • Proficient
  • Proficient
  • No Avatar
  • Registrado: Jul 06, 2010
  • Mensajes: 280
  • Status: Offline

Nota Marzo 14th, 2012, 7:48 pm

Siempre intenta publicar soluciones para iniciar los subprocesos. Odio sólo buscando un tema y encontrar a alguien tener exactamente el mismo problema y el subproceso es un año o más viejo y ninguna solución.

Publicar Información

  • Total de mensajes en este tema: 4 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 34 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC