µSprite

µSprite Script Examples


Below is a sample drawing created in µSprite. To view it copy the sample to the clipboard. Run µSprite, choose a theme color, click the open eyes to get a blank drawing area and then the Scene Script button. Click in the script window and right-click Select All and Paste. Or use keyboard shortcuts (Ctrl/A and Ctrl/V on Windows). To compile the program with mxmlc paste it into a file named AppBlue.as.

To transform the AS3 samples into haXe script click on the Settings tab and select the generate haXe button then switch back and copy the haXe script to your editor. See the readme in the source download doc/samples/haxe for details on how to compile with haXe.

Next is an example of how to create a custom MXML cursor class. I have not found it documented that cursors can be Shape objects but it works. To create your own custom cursor paste the µSprite generated Shape method into a class similar to the following, call it from the constructor and replace the 'new Shape()' with 'this' so it is drawn in the instance itself. To view the sample cursor in µSprite, paste the createCustomCursor method into the script window and zoom with the grid controls to (-6, 30).

You can use the custom cursor in an MXML application such as the little test program below. To try it paste the code from above into a file named CustomCursor.as and the code below into another file named TestCursor.mxml and place both in the same directory.

Adding custom icons to MXML buttons require the same basic class as the cursor did. Additionally the class must implement the IFlexDisplayObject interface. This is shown in the sample script below. To try it, place the code in a CustomIcon.as file and add icon="{CustomIcon}" as an attribute to the first Button control in the MXML from above.

You can also create code in µSprite to use as a basis for programmatic skins for MXML buttons. It requires quite a bit of manual coding to make the shapes resizable etc. so for details see the 'Flex 2 Developer’s Guide', 'Using skins' especially the 'Programmatic skinning' chapter. Using ActionScript is generally easier, just use addChild to add your Shape to the display list.