WidgetFactory
WidgetFactory is an ActionScript API that makes building widgets easier.
Easier than what? Easier than the way Captivate gives you. Captivate has a Widget Template that it kindly copies and pastes into a Flash file for you when you go to File > New Project > Widget in Flash. Okay, so what does this template look like?
Uhhhh… Show ▼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| import flash.external.ExternalInterface;
import com .adobe .captivate .widgets .*;
import com .adobe .captivate .events .*;
var m_WidgetMode : String = '';
var m_WidgetParam : String = null;
var m_VariableHandle : Object = null;
var m_MovieHandle : CPMovieHandle = null;
var m_EventHandle : IEventDispatcher = null;
var m_EditModeWidth : int = 411;
var m_EditModeHeight : int = 328;
this.addEventListener( "enterFrame" , FuncOnEnterFrame );
try {
if(ExternalInterface.available == true)
{
ExternalInterface.addCallback( "isStatic" , isStatic );
ExternalInterface.addCallback( "getInspectorParameters" , getInspectorParameters );
ExternalInterface.addCallback( "setInspectorParameters" , setInspectorParameters );
ExternalInterface.addCallback( "setParameters" , setParameters );
ExternalInterface.addCallback( "cpSetValue" , cpSetValue );
ExternalInterface.addCallback( "getEditModeWidth", getEditModeWidth );
ExternalInterface.addCallback( "getEditModeHeight", getEditModeHeight );
ExternalInterface.addCallback( "IsReadyForSnapShot", IsReadyForSnapShot );
}
} catch( e ){
};
function FuncOnEnterFrame ( inEvent : Event ) : void
{
var l_WidgetModeParam : String = m_WidgetMode ;
if( null == l_WidgetModeParam )
{
l_WidgetModeParam = 'Stage';
}
if( 'Edit' == l_WidgetModeParam )
{
}
else if( 'Preview' == l_WidgetModeParam )
{
}
else
{
if( m_MovieHandle != null )
{
m_WidgetParam = m_MovieHandle .widgetParams ();
}
if( m_WidgetParam != null )//at runtime inside Captivate movie
{
var myXml :XML = new XML(m_WidgetParam );
}
}
}
function isStatic ():Boolean
{
return true;
}
function getInspectorParameters () : Object
{
var l_Parameters : Object = new Object();
return l_Parameters ;
}
function setInspectorParameters ( inParam : Object ) : void
{
if ( null != inParam )
{
}
}
function IsReadyForSnapShot ():Boolean
{
return true;
}
function setParameters ( inParam : Object ) : void
{
if ( null != inParam )
{
}
}
function cpSetValue ( inVariable : String, inValue ) : void
{
if( 'movieHandle' == inVariable )
{
m_MovieHandle = CPMovieHandle (inValue );
if(m_MovieHandle )
{
var l_MovieProps :CPMovieProperties = m_MovieHandle .getMovieProps ();
if(l_MovieProps )
{
m_VariableHandle = l_MovieProps .variablesHandle ;
if(m_EventHandle == null)
{
m_EventHandle = l_MovieProps .eventDispatcher ;
if(m_EventHandle != null)
{
}
}
}
}
}
else if( 'widgetMode' == inVariable )
{
m_WidgetMode = inValue ;
}
}
function getEditModeWidth ( ): int
{
return m_EditModeWidth ;
}
function getEditModeHeight ( ): int
{
return m_EditModeHeight ;
} |
Believe me when I say this is enough to make even an experienced programmer run to the hills, and this code is just to get the widget to start communicating with Captivate.
So how would the same widget done in WidgetFactory look?
1 2 3 4 5 6 7
| package {
import widgetfactory.StaticWidget;
public class MyWidget extends StaticWidget {
}
} |
In a word: Simpler. In a sentence: There’s a bit of setup involved, but in the end it’s simpler. Click here to learn how to set up WidgetFactory.