A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: Using Brightcove Player in Flash (AS3 & Classes)

  1. #1
    Junior Member
    Join Date
    Dec 2000
    Posts
    5

    Wink Using Brightcove Player in Flash (AS3 & Classes)

    OK this is well beyond my flash knowledge and was wondering if there is anyone out there that can help. Simply I need to get this Brightcove player working in a flash file, having never worked with AS3 and Classes before I'm at a total loss as to what to do. If its possible (and i know this rather cheeky to ask) could you upload an example .fla

    Code:
    // By use of this code snippet, I agree to the Brightcove Publisher T&C 
    // found at http://corp.brightcove.com/legal/terms_publisher.cfm. 
    
    /*
    * To use this class to load your Brightcove player instance, save this code into the root directory
    * of your project as BrightcovePlayer.as. Then, within your application, you can instantiate this player
    * using the following syntax:
    *
    *	var player:BrightcovePlayer = new BrightcovePlayer();
    *	addChild(player); /// must be added to a display object container, such as a Sprite instance
    *
    */
    package {
    
    	import flash.display.Loader;
    	import flash.display.LoaderInfo;
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.events.ProgressEvent;
    	import flash.net.URLRequest;
    	import flash.system.ApplicationDomain;
    	import flash.system.LoaderContext;
    	import flash.system.SecurityDomain;
    	import flash.system.Security;
    
    	public class BrightcovePlayer extends Sprite {
    
    		private var bcPlayer:Object;
    
    		public function BrightcovePlayer() {
    			init();
    		}
    		
    		private function init():void {
    			var config:Object = new Object();
    
    			// change the playerID to load a different player
    			config["playerID"] = 14146705001;
    			config["width"] = 464;
    			config["height"] = 394;
    		
    			Security.allowDomain("http://admin.brightcove.com");
    			createPlayer(config);
    		}
    
    		private function onPlayerLoadInit(pEvent:Event):void {
    			var pLoaderInfo:LoaderInfo = pEvent.target as LoaderInfo;
    			var pLoader:Loader = pLoaderInfo.loader;
    			var pPlayer:Sprite = pLoaderInfo.content as Sprite;
    			if (bcPlayer && pPlayer != bcPlayer) {
    				if (bcPlayer.parent) {
    					bcPlayer.parent.removeChild(bcPlayer);
    				}
    			}
    			bcPlayer = pPlayer;
    			addChild(bcPlayer as Sprite);
    			if (contains(pLoader)) removeChild(pLoader);
    		}
    	
    		private function onPlayerLoadProgress(pEvent:ProgressEvent):void {
    			// place preload feedback here for shell movie
    		}
    
    		private function createPlayer(config:Object):void {
    			var cacheServerServices:String = "http://c.brightcove.com/services";
    			var cdnURL:String = "http://admin.brightcove.com";
    			var publisherID:String = "1815805388";
    
    		    var configItems:String = "";
    		    for (var i:String in config) {
    		       if (i == "flashID" || i == "width" || i == "height") continue;
    		       configItems += "&" + i + "=" + escape(config[i]);
    		    }
    		
    			var file:String = cacheServerServices + "/viewer/federated_f9/" +
    				config["playerID"] + "?isVid=1&isUI=1" +
    				"&flashID="+escape(config["flashID"])+
    				"&playerWidth="+escape(config["width"])+
    				"&playerHeight="+escape(config["height"])+
    				"&publisherID="+escape(publisherID)+
    				configItems;
    							
    			var player:Loader = new Loader();
    			addChild(player);
    			player.contentLoaderInfo.addEventListener(Event.INIT, onPlayerLoadInit);
    			player.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onPlayerLoadProgress);
    			var context:LoaderContext = new LoaderContext();
    			context.applicationDomain = ApplicationDomain.currentDomain;
    			player.load(new URLRequest(file), context);
    		}
    
    		public function onTemplateLoaded():void {
    			dispatchEvent(new Event("templateLoaded"));
    		}
    
    		public function getModule(pModule:String):Object {
    			return Object(bcPlayer).getModule(pModule);
    		}
    
    	}
    
    }
    Last edited by lukusdukus; 03-02-2009 at 03:28 PM. Reason: more descriptive title ;)
    if is the middle word in life

Tags for this Thread

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