I want to make my own AS3 video player

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

I'm good at AS2 but I wanted to make my own AS3 video player doing so would give me a OK understanding of the code. This is most likely the easiest issue I've posted here mainly since I'm new to AS3 and only played with a few tid bits of code.

So I know how to do this in AS2 but AS3 is giving me issues. I have a video player that loads an external swf file that contains the buttons and controls any animations they do. however all functionality will be handled by the root movie or parent depending on how you want to call it.

ACTIONSCRIPT Code: [ 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.  


So this code would load an XML when it completes it will load the skin once that loads it would setup the click functions. this all works up until setting up the click function
ACTIONSCRIPT Code: [ Select ]
player_controls.play_button.addEventListener(MouseEvent.CLICK, play_video);


Now I know when I did this with AS2 I had to use onLoadInit like this
ACTIONSCRIPT Code: [ 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.  


I've looked for the AS3 onLoadInit or something like it and cant seem to find anything.

So to recap I have a swf(swf1) that loads a swf(swf2) swf2 has the buttons and swf1 contains the actionscipt for the buttons in the swf2. If anyone knows how to do this or can direct me to some documentation that may help. Your help would be appreciated.

If I discover a solution I will post it.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

OK ... I love when that happens. Post my issue and find the answer here it is

ACTIONSCRIPT Code: [ 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.  


I had to move the skin loader class outside of the setup player function due to the the fact that I needed access to the skin_loader in the set_buttons function. I also move the addChild to the set buttons function. I had to declare the content was a movie clip by this line here
ACTIONSCRIPT Code: [ Select ]
var mc:MovieClip = skin_loader.content as MovieClip;
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Sometimes writing out a post allows you to see things you have missed before, and sometimes the timing is just funny. I don't know how many times I have begun to write a post and either figure it out on my own while writing it, or shortly after. Glad you found a resolution and shared it for others who come across a similar issue.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

I always try to post solutions to threads I start. I just hate searching for an issue and finding someone having exactly the same issue and the thread is a year or more old and no solution.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 20 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.