insertbuttonpublic class insertbutton 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 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 of the color
* 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 (Exception e)
{
/* 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 a detailed message.
*/
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 Generator 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 box. Please note that for each
* get___Param method, the third parameter must be matched
* with the 'token' name in the insertbutton.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" );
/* Call the private method createShape to retrieve the
* shape information for the box. */
Shape shape1 = createShape( r_width, r_height, colorString );
/* In order to use the addShape 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 matrix1 = new Matrix();
/* Create a button object */
Button buttonObj = new Button(true);
/* Add the box's shape to 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);
/* Use the insertButton method to insert the button object
* created above into the script. */
clip.insertButton( buttonObj, 0, 0, matrix1, frameCount, matrix1 );
}
catch (Exception e)
{
mEnv.logError("Exception: " + e);
}
|
|