Creating the Components
Components are incredibly useful for developing well-constructed, object-oriented Flash applications. You should consider making elements of a movie into components when they meet either of these criteria:
The same elements, or similar elements, are used multiple times throughout a movie.
The element has complex behaviors and can be treated as a discrete unit.
For the image viewer/slideshow application, we will make seven components:
- Image
A component that loads images given a URL
- ImageViewPane
A component that allows an image to be moved and resized
- PreviewPane
A component into which image view panes are added
- SequenceViewer
The viewer for the full image slideshow sequence
- SequencerItem
One of the thumbnail items that can be added to the sequencer
- Sequencer
The component into which thumbnails are added and ordered
- Menu
The menu for the application
Designing the Image Element
The preview pane, sequencer, and sequence viewer all include elements that load images. Rather than reinvent the wheel with each, it makes sense to create a single Image component that can be utilized in each case. The Image component should have basic functionality that includes:
Loading an image from a given URL
Monitoring load progress with a progress bar
Invoking a callback function when loading is complete
Resizing itself to scale (maintaining the aspect ratio) to fit within specific dimensions
To create the Image component, complete the following steps:
Create a new movie clip symbol named
Image
.Edit ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.