inserturlactionpublic class inserturlaction extends GenericCommand
Fields Summary |
---|
String | colorParam | private Context | mContext | private int | mFrameCount | private Script | mScript | private Script | mTemplateScript | private FlashEnvironment | mEnv | private Properties | mProperties |
Methods Summary |
---|
private Button | createButton(int r_width, int r_height, java.lang.String colorString)
Button buttonObj = null;
try
{
/* Call the private method createShape to retrieve the shape
* information for the box. */
Shape shape1 = createShape( r_width, r_height, colorString );
/* Create a button object */
buttonObj = new Button();
/* Allocate an identity matrix (see above comment on why you
* need to allocate a matrix.) */
Matrix matrix1 = new Matrix();
/* Add the shape to the button object, for each state of
* the button. */
buttonObj.addShape( shape1, matrix1, Button.buttonStateTest, 1);
buttonObj.addShape( shape1, matrix1, Button.buttonStateUp, 1);
buttonObj.addShape( shape1, matrix1, Button.buttonStateOver, 1);
buttonObj.addShape( shape1, matrix1, Button.buttonStateDown, 1);
}
catch (Exception e)
{
mEnv.logError("Exception: " + e);
}
return buttonObj;
| private Shape | createShape(int r_width, int r_height, java.lang.String colorString)
Shape shapeObj = null;
try
{
/* Create a color, and then set the RGB value using
* setRGBValue. */
Color color = new Color();
color.setRGBValue( colorString);
/* In order to specify a FillStyle color using the
* setFillStyle method, you must first must create 2
* instances of FillStyle class. */
FillStyle fill_1 = new FillStyle();
fill_1.setColor( color );
FillStyle fill_2 = new FillStyle();
fill_2.setColor( color );
/* Create a shape */
shapeObj = new Shape();
/* Apply the 2 previously defined instances of the
* FillStyle class to the shape */
shapeObj.setFillStyle(fill_1, fill_2);
/* Draw the shape using the moveTo and lineTo methods in the
* Shape class. --- (0,0) is the center point of the gray
* placeholder box that represents a Generator object in the
* interface.
*/
shapeObj.moveTo(0, 0);
shapeObj.lineTo(0, r_height);
shapeObj.lineTo(r_width, r_height);
shapeObj.lineTo(r_width, 0);
shapeObj.lineTo(0, 0);
}
/* Catch an exception and display the name of the exception in
* the Generator Output window if there are any errors. The
* exception may not throw detailed mesasge.
*/
catch (Exception e)
{
mEnv.logError(" An exception occured at: " + e.getClass() + " with message: " + e.getMessage());
}
return shapeObj;
| public void | doCommand(FlashEnvironment env, Script script, Context context, int cmdIndex, java.util.Properties params)
/* All Generator object .java files must contain the doCommand.
* The doCommand is called by Generator when the custom object is
* processed.
*/
String colorParam;
mContext = context;
mEnv = env;
mScript = script;
mProperties = params;
try
{
/* Use the getCommandScript method to retrieve the script
* for the object being created. A script represents a
* Flash movie symbol containing * a timeline, and possibly
* shapes, symbols, and text.
*/
Script clip = script.getCommandScript(cmdIndex);
if (clip == null)
throw new Exception("template script missing");
/* Use getCommandFrameCount to retrieve the number of frames
* associated with the command. */
int frameCount = script.getCommandFrameCount(cmdIndex);
/* Use the getIntParam and getStringParam methods in the
* GenericCommand class to obtain the properties information
* needed to create the button. Please note that for each
* getOOParam method, the third parameter must be matched
* with the 'token' name in the inserturlaction.def file.
*/
int r_height = getIntParam( context, params, "height", 500 );
int r_width = getIntParam( context, params, "width", 500 );
String colorString = getStringParam( context, params, "color", "blue" );
String urlString = getStringParamEmpty( context, params, "url");
String windowString = getStringParam( context, params, "window", "_self");
/* Call the private method createButton to create a button
* with the specified height, width, and color.
*/
Button button = createButton( r_width, r_height, colorString);
/* Create an instance of the Action class to allocate a
* default action. */
Action action = new Action();
/* Use setTranstionState method to attach an action to a
* button state. */
action.setTransitionState( Action.bsOverUpToOverDown );
/* Add the GetURL action to the current action. The URL
* and target window are specified by the user in the
* Generator inspector.
*/
action.addGetURL( urlString, windowString);
/* Add the action to the button */
button.addAction( action );
/* In order to use the insertButton method in the Script
* class, you must first create an instance of the Matrix
* class. The methods in the Matrix class are used to
* manipulate the size, scale and rotation of Generator
* objects. However, because many of the methods in the
* API require an instance of the Matrix class as one of
* the arguments, you will probably need to create an
* instance of the Matrix class even if you do not wish to
* transform your object.
*/
Matrix matrix2 = new Matrix();
/* Use the insertButton method to insert the button object
* created above into the script. */
clip.insertButton( button, 0, 0, matrix2, frameCount, matrix2 );
}
catch (Exception e)
{
mEnv.logError(" An exception occured at: " + e.getClass() + " with message: " + e.getMessage());
}
|
|