Ultrashock Tutorials > Flash 8 > XML Portfolio Viewer  
 
by Jim Armstrong, 2112 FX::Singularity
Download Source Files 
 
XML Portfolio Viewer
 
 Introduction and Code Requirements 
 Section 01: Layout XML  
 Section 02: Portfolio XML  
 Section 03: Architecture  
 Section 04: Preloading  
 Section 05: Error Handling  
 Section 06: pair & triple classes 
 Section 07: Observer-Observable Utility

 Section 08: Style Manager 
 Section 09: Layout Items  
 Section 10: Custom Layout Classes  
 Section 11: Glyph Class  
 Section 12: Multi-dimensional Thumbnailer  
 Section 13: Model 
 Section 14: View 
 Section 15: Controller 
 Section 16: Suggestions for Improvement 

Preloading

In a typical project, I would develop an application as a single-frame .SWF and then use an external preloader. Sometimes, it is necessary to work with internal preloaders, if only because that is what has been specified by the project manager. If I want to get paid, I keep everything in one .FLA and develop an internal preloader.

I do want to get paid, so let's look at an internal preloader for the portfolio viewer :) The problem with an internal preloader is that normal development in the Flash IDE causes classes and components to be exported on the first frame. In reality, these assets are loaded before frame-1 content in the application, so there is a delay before the preloader is displayed. The situation is compounded with symbols that are exported for Actionscript.

If you already feel comfortable with working around these issues, please go to the next section. If not, read on.

Driver .FLA

Open the driver file, portfoliodriver.fla in Flash 8 Professional. There are three main layers -

preloader - contains the internal preloader, placed directly on Stage in the first frame.

preloadAssets - contains references to assets that are exported for Actionscript.

actions - Actions on this layer interface with the Controller.

Open the Library for portfoliodriver.fla. The Components folder contains V2 UI Components used in the application. Normally, I avoid using V2 components, however, the UIScrollBar is used in the thumbnailer display (SCROLLER component). The TextArea and Button are used in the SimpleAlert class. These could all be replaced with third-party components, but the extra file size is actually useful as it provides an opportunity to exercise the preloader.

The MovieClips folder contains MovieClip symbols used in the application. Several are exported for Actionscript.

Export for Actionscript

Normally, when exporting a library symbol for Actionscript, the symbol is exported before frame-1 content in the .SWF so that symbols are available to be attached in the first frame. This implies that an internal preloader does not display until many of the assets are already loaded, defeating the whole purpose of a preloader.

The issue is compounded with UI Components. If we have no need for library symbols before a certain frame, it is only necessary that they be included in the timeline before that frame in order for the symbol to be exported in the .SWF. This means we can turn off 'export in first frame' and manually place the symbol on the timeline.

Examine the Linkage Properties of the 'background' symbol (right-click on the symbol in the Library and select 'Properties' or 'Linkage'). Note that the symbol is exported for Actionscript with a linkage ID of 'background.' The 'Export in first frame' option is unselected.

In frame 2 of the preloadAssets layer, there is an instance of the background clip at coordinates (-10,-10). The instance of this clip has been resized to 1x1. As long as the background clip is referenced on the timeline before that symbol is referenced by script, it is exported in the .SWF and available for use in attachMovie().

We can do the same thing with components. Examine the Linkage Properties of any component in the Components folder. Notice that all components have the 'Export in First Frame' option unchecked. There is an instance of each component referenced on the timeline before frame 8, which is where the Controller is first referenced.

Class Files

By default, class files are exported in a manner similar to library symbols. Fortunately, we may control the frame in which class files are exported. In the Publish Settings, click on the Flash tab. Click on the 'Settings' button by 'Actionscript Version.' Notice that for this application, classes are set to export on Frame 2.

Preloader

The preloader animation is placed on Stage in the first frame. Since no other content is loaded before this animation, it appears immediately when the first frame is loaded. Classes, components, and library symbols begin loading on the second frame. When all symbols are loaded, the Controller is instantiated and the application begins.

The preloader is controlled by the driver. The Controller has no need to worry about whether or not the application is preloaded. If there is a preloader, the Controller should not care whether it is internal or external. The Controller should work in the same manner with the same interface in all cases. Since the preloader is internal to the driver, the driver manages the preloader.

 
©2006 Ultrashock.com - All rights reserved