|
|
||||
|
|
Ultrashock Tutorials > Flash MX > Live Preview | |||
|
||||
|
|
Live Preview |
|
||
|
Key Elements of a Live Preview In the Live Preview file there is a special variable on _level0 named xch. This holds the values that the developer has entered in the Component Parameters panel. There is also a special event which is called, onUpdate(). This is called whenever xch has been updated with new properties from the component parameters. If you used custom UI’s in Flash 5 you will recognize xch. In Flash 5 you would have to have an empty movieclip named xch and the data would be put in it, in Flash 6 xch is an object that is automatically created for you. Usually the Live Preview will be your actual component. Yep, it's that easy--you can just create a SWF with your component in it, add a few hooks for setting its properties, and surprise; you have an accurate Live Preview. To start, you MUST put these two lines at the top of your Live Preview FLA file if you want the preview to be accurate. Stage.align = "TL"; This will make sure the alignment and scaling are correct. onLoad function onLoad(){ onUpdate function onUpdate(){ pushPreview is the push button component. onResize Stage.addListener(this); You can look at the LivePreview.fla for a complete example. Creating the Live Preview There is a very simple source file that you can look at that is a Live Preview. You can find it in the source zip under the filename LivePreview.fla This source file takes one of the standard components and recreates the Live Preview by just adding a few hooks. To test this file you can create a new movie and drag the push button onto the stage.
You will notice it looks exactly the same, in a few lines code it was very easy to recreate the push button’s Live Preview. Even the most advanced components can be easy to add a preview too since the preview is simply the component itself with a couple hooks. The next section will walk you through a slightly more complicated example. Exercise – Recreating the Message Box Component’s Live Preview The Message Box component is available in the freely distributed Flash UI Component Set 2. The Message Box has seven component parameters that can be shown in the Live Preview.
The only preview item that will not hook into the component is the Visible parameter. You wouldn’t want to hide the component completely so you can just do something to indicate that it will be invisible at runtime. The original Live Preview for the Message Box component changed the component’s _alpha property to make it somewhat transparent. Below are the steps to recreating the Live Preview for this component, if you have trouble with any of the steps you can open the source file MessageBox_preview.fla for help.
As you can see above all you have to do is to hook into the component for the preview, except for the last line. Instead of making the component invisible you give an indicator that it will be by setting its _alpha property to 20%. When creating your own components and Live Previews you can follow these
same steps. The Live Preview is a regular SWF that runs in the IDE. That
is why you can use your component as the Live Preview itself. It’s
that simple! If you have any issues be sure to look through the example,
if you are still having trouble feel free to email me at gburch@squarelabs.com. |
||||
|
|
©2002 Ultrashock.com Inc. - All rights reserved
|
|