Video asset as a customizable property of a wigdet

Create unique Flash widgets you can import into SmartBuilder

Moderator: Nav

Video asset as a customizable property of a wigdet

Postby VIN_andrew » Fri Jun 22, 2007 3:26 pm

Below is the Class definition for a custom FLV-player Widget:

Code: Select all
class com.vin.flvplayer.Widget extends MovieClip implements sb.SB_ExternalWidget
{
   private var adapter:SB_Adapter;
   private var flvPlayerMC:MovieClip;
   private var videoKey:Object;

   
      
   function Widget() {
   }
   
   function onCreate(adapter:SB_Adapter) : Void
   {
      adapter.saveData("Time",SBC.DATA_STRING, "1.0" );
      adapter.saveData("Sound",SBC.DATA_BOOLEAN, false );
   }
   
   function onInit(adapter:SB_Adapter) : Void
   {
      //save the adpater reference for future use
      this.adapter = adapter;

      //register widget properties
      adapter.registerProperty("Time",SBC.PARAM_STRING);
      adapter.registerProperty("Sound",SBC.PARAM_BOOLEAN);
      adapter.registerProperty("Video",SBC.PARAM_VIDEO);

      flvPlayerMC.flvTime=adapter.retrieveData("Time",SBC.DATA_STRING);
      flvPlayerMC.flvSound=((adapter.retrieveData("Sound",SBC.DATA_BOOLEAN))?"1":"0");
      this.videoKey=adapter.retrieveData("Video",SBC.DATA_VIDEO);
      flvPlayerMC.flvPath=adapter.getResourceURL(videoKey);
      
      this.flvPlayerMC.initVideo();
   }
   


   // property getters/setters

   function setTime(propertyValue:String) : Void {
      flvPlayerMC.flvTime = propertyValue;
      adapter.saveData("Time",SBC.DATA_STRING, flvPlayerMC.flvTime );
   }   
   
   function getTime():String  {
      return flvPlayerMC.flvTime;
   }   


   function setSound(propertyValue:Boolean) : Void {
      flvPlayerMC.flvSound = (propertyValue?"1":"0");
      adapter.saveData("Sound",SBC.DATA_BOOLEAN, propertyValue );
   }   
   
   function getSound():Boolean  {
      return (flvPlayerMC.flvSound=="1"?true:false);
   }

   function setVideo(videoKey:Object) : Void  {
      adapter.saveData("Video", SBC.DATA_VIDEO, videoKey );
      this.videoKey = videoKey;
      flvPlayerMC.flvPath=adapter.getResourceURL(this.videoKey);
   }

   function getVideo() : Object  {
      return videoKey;
   }   


   /** do something whenever a size change is requested
   */
   function setSize(w:Number,h:Number) : Void {}


   /** for this widget, the behaviour is the same when selected or de-selected
   */   
   function onAuthoringSelect() : Void {}   

   function onAuthoringDeselect() : Void {}   
   
   
   /** called whenever a format change is triggered from external source, such as the formatting bar (authoring mode only)
   */   
   function setTextFormat(myformat:TextFormat):Void {}
   
   /** called whenever a external source is query about the format of the current widget(or part of the widget) (authoring mode only)
   */   
   function getTextFormat():TextFormat {return;}
   

}


In this code I've adapted from the demo widget that comes with the SDK, attempting to "duplicate" how the icon (a PARAM_GRAPHIC type property) is handled as there.

Unfortunately, this code isn't working. No custom parameter appears on the Properties panel to allow me to select the video asset to be used by this Widget.

So, what am I doing wrong?

Thanks for the help :)
----------------------------
Andrew Corbett, Ph.D.
Online Multimedia Director
Veterinary Information Network
VIN_andrew
 
Posts: 7
Joined: Tue Apr 03, 2007 8:30 am

Postby ffox » Fri Jun 29, 2007 1:49 pm

The Widget SDK requires all property names and their getter / setter methods to use Java Bean Naming conventions.

1. Member names are CamelCase http://en.wikipedia.org/wiki/CamelCase. That is, the first character is lower case and the first character of subsequent words are Upper case. Example: myVideoProperty.

2. If the member variable has a getter, the first character is upper case and prepended with "get". Example: getMyVideoProperty.

3. If the member variable has a setter, the first character is upper case and prepended with "set". Example: setMyVideoProperty.

In your specific example, you will need to rename: Time to time, Sound to sound and Video to video.

The adapter.registerProperty method allows the display name (the name shown in the properties panel) to be different then your registered name.
Code: Select all
adapter.registerProperty("time",SBC.PARAM_STRING,"Time");

In this example, the property name is all lowercase and the displayed name has the first character uppercase.


Frank
ffox
 
Posts: 4
Joined: Fri Jun 29, 2007 1:09 pm

Postby VIN_andrew » Fri Jul 06, 2007 9:41 am

Thanks. It's working now. Very cool ;)
----------------------------
Andrew Corbett, Ph.D.
Online Multimedia Director
Veterinary Information Network
VIN_andrew
 
Posts: 7
Joined: Tue Apr 03, 2007 8:30 am


Return to Using the Object SDK

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Not able to open ./cache/data_global.php