Embed Nimbb in an Adobe Flash Builder application

The Nimbb Player can be easily embedded into any Adobe Flash Builder application. You can use the Nimbb Player as a component into your Flash application, just like you can use it into a web page. You simply embed the SWF file using the SWFLoader component of Flash. Then, you can interact with the Nimbb Player using its methods and events. The following example shows how to insert Nimbb into a Flash application built using Adobe Flash Builder 4.6 (works also with Adobe Flex Build 3).

This example requires you to specify your developer key (see tutorial).

Example

Nimbb Player embedded into an Adobe Flash Builder application:

ActionScript 3 code (Flex Framework)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    width="540" height="300" backgroundColor="white">
	
  <mx:Script>
  <![CDATA[

    import flash.net.navigateToURL;
    import mx.managers.SystemManager;
    import mx.controls.Label;
    import mx.core.UIComponent;
    import mx.controls.SWFLoader;
    import mx.events.FlexEvent;

    private var _SM:SystemManager;
    private var _Nimbb:Object;
    private var _Guid:String;

    private function swfLoader_Completed():void
    {
      // Prepare access to Nimbb object.
      _SM = SystemManager(swfLoader.content);
      _SM.addEventListener(FlexEvent.APPLICATION_COMPLETE, SM_Ready);
    }
		
    private function SM_Ready(e:FlexEvent):void
    {
      // Get reference to Nimbb object.
      _Nimbb = _SM.application;

      // Prepare listeners to trap Nimbb events.		
      _Nimbb.addEventListener("Nimbb_initCompleted", Nimbb_initCompleted);
      _Nimbb.addEventListener("Nimbb_stateChanged", Nimbb_stateChanged);
      _Nimbb.addEventListener("Nimbb_videoSaved", Nimbb_videoSaved);
    }
			
    private function Nimbb_initCompleted(event:Event):void
    {
      // Nimbb is ready.
      trace("Nimbb_initCompleted");
    }
	
    private function Nimbb_stateChanged(event:Event):void
    {
      // Display state of player.
      stateText.text = _Nimbb.getState();
    }
	
    private function Nimbb_videoSaved(event:Event):void
    {
      // The video was saved, get the GUID.
      _Guid = _Nimbb.getGuid();

      // Update interface.
      guidText.text = _Guid;
      shareButton.enabled = true;
    }
				
    private function Share():void
    {
      // Open a new browser to share the video.
      navigateToURL(new URLRequest("http://nimbb.com/v/" + _Guid), "_blank");
    }

  ]]>
  </mx:Script>
	
  <mx:Panel x="10" y="10" width="340" height="280" layout="absolute" title="Nimbb Player">
    <mx:SWFLoader id="swfLoader" x="0" y="0" width="320" height="240"
     source="http://player.nimbb.com/nimbb.swf?mode=record&amp;key=XXXXXXXXXX&amp;simplepage=1&amp;lang=en" 
     trustContent="true" complete="swfLoader_Completed()"/>
  </mx:Panel>
  
  <mx:Panel x="358" y="10" width="170" height="280" layout="absolute" title="Results">
    <mx:Label x="10" y="10" text="Guid:" fontSize="12" fontWeight="bold"/>
    <mx:TextInput id="guidText" x="10" y="38" width="130" fontSize="12" editable="false"/>
    <mx:Label x="10" y="76" text="State:" fontWeight="bold" fontSize="12"/>
    <mx:TextInput id="stateText" x="10" y="104" width="130" editable="false" fontSize="12"/>
    <mx:Button id="shareButton" x="10" y="185" label="Share video!" width="130" height="45"
     click="Share()" enabled="false" fontSize="14"/>
  </mx:Panel>
	
</mx:Application>


To try this code, create a new application into Adobe Flash Builder and paste it. Make sure to replace the key code with your developer key. Compile the application and run it from your Web server. If you have a Flash sandbox security error, make sure that your Flash application is executed from an URL (starting with "http://").

It's easy to embed the Nimbb Player in a Flash application using the SWFLoader component. Notice that you can specify any Nimbb parameters by separating them with "&amp;". The property trustContent lets Flash access the Nimbb component within your Flash application.

Using a SystemManager object, we are able to get a reference to the Nimbb object and then call its methods like getGuid(). You can call all the methods of the Nimbb Player, just like using JavaScript.

To intercept the Nimbb Player's events, we create Flash listeners using the method addEventListener(). Then again, you can access all the events of the Nimbb Player, just like using JavaScript.

This code is easy to paste into Adobe Flash Builder, but you should be able to use it with other Flash creation tools.

View more tutorials.

SIGN UP NOW 7-day free trial

Check out our Developer guide to get started with Nimbb.