This example shows you how to create your own custom window panel for Flash CS3. The functionality for this project will be to change the current document setting to the supplied attributes below. For example, this could be used to modify things such as document height, width, frame rate, new layers and add Library folder items.
1) First create a new flash document and change he background color to match the other panels use the value #EDEDED.
2) Drag and drop a Button component to the stage and give it the label name “Default Flash Setup”. Also set the Button’s instance name to “setup” in the properties panel.
3) Save the flash file as “Default Flash Setup.fla”. We want to make sure that the flash file name is logical to the panels functionality. Why? Because the panel’s name is derived from the flash file name.
4) Create an actionscript layer and copy and paste the code below into your actionscript panel.
////////////// START AS CODE ///////////////
setup.addEventListener(MouseEvent.CLICK, setup_CLICK);
function setup_CLICK(e:MouseEvent):void
{
var jsfl:String = "fl.getDocumentDOM().getTimeline().setLayerProperty('name', 'as');fl.getDocumentDOM().getTimeline().setLayerProperty('locked', true);fl.getDocumentDOM().library.newFolder('Sounds');";
MMExecute(jsfl);
}
////////////// END AS CODE ///////////////
The code above does two things:
- Adds an event handler to the button instance.
- Calls the MMExecute function to pass in jsfl code (Javascript API) for controlling the flash authoring tool.
5) Adding jsfl Codes are easy. You can find the jsfl code in side of the Help panel > Extending > Objects. For example to find ways to change the document, go to Help > Extending > Objects > Document object and select an object to view it’s sample code to copy and paste in to your actionscript. Also make sure there are no line-breaks. See sample code above.
To create jsfl code on the fly, use the History panel like you would the Photoshops’ Actions panel to create droplets or custom actions. Give it a try. Open the History panel and open a new document. Create a new layer and name it “as”. Create a new folder in the Library panel. Go back to the History panel, select all history listings and right click or control click to copy and past the code in to your project actionscript.
6) Publish the file and move the swf file to the “WindowSWF” directory located inside of your user’s folder. I’m not sure where this is located on the PC; however for Mac OS X, it’s located under User > Library > Application Support > Adobe > Flash CS > en > Configuration > WindowSwf.
Now restart your flash application, open a new document and you will find your new custom panel under Windows > Other Panels > Default Flash Setup.
Click the button and watch your document change before your very eyes.
That’s it.
Get the source here.
P.S.
For another cool example of creating your own custom panel, The flash blog has an Event Generator panel that will save you a lot of time in writing event handler code for movieclips that are placed on the stage.
Download the extension here: http://theflashblog.com/?p=331