7.4. Scripting the Flash Viewer

The 3DSOM Flash Viewer is written in ActionScript 3 which is supported by the Flash 9 player. The information in this section allows ActionScript developers to customize the viewer controls and more experienced users to include the viewer as part of a larger application.

Writing a control bar

The control bar should be an AS3 SWF movie. The controls parameter in the "parameters.xml" file defines the location of the movie.

The 3DSOM Flash Viewer is responsible for loading and displaying the control bar. The viewer then sets the member variable mainViewer of the control bar to reference the viewer to allow the control bar movie to access public functions in the viewer class.

TIP:

Every control bar movie should have an associated AS3 public class with a public member variable as follows:

public var mainViewer:Object;

Using the above mechanism the control bar movie can script the main viewer class. The full list of public functions available will be described later in this section. For example the code for handling clicking the control bar "reset" button should look like...

private function onReset(event:Event):void {
    if (mainViewer && mainViewer.onReset) {
    	mainViewer.onReset(); 
    }
}
Viewer API

The following public functions and variables are available...

public var dragMode:uint
An integer that defines the currently used interaction mode. This defines how the viewer handles left-dragging with the mouse. The values used are...
public function onReset()
Resets the 3D view to the default position and rotation.
public function onZoomIn()
Zoom-in towards the model. Should be called by zoom-in button handler.
public function onZoomOut()
Zoom-out from the model. Should be called by zoom-out button handler.
public function setupFromFile(filename:String)
filename (string) - XML filename relative path.
This function loads the XML file with the given path (relative to the viewer movie) and sets up the viewer using the parameters defined within. The XML file should have the same format as the "parameters.xml" file. This function can be used to change the model currently being displayed. Not all the parameters need to be defined in the XML file.
public function setupFromString(filename:String)
filename (string) - String containing valid XML.
This function can be used to change any or all of the viewer parameters. The input string contains one or more lines containing the <parameter name="XXX" value="yyy"/> where XXX is a parameter name and YYY is the desired value. See Flash Viewer Parameter Reference for details.
public function setup(xmldata:XML)
xmldata (XML) - valid XML.
This function changes the viewer parameters as for the previous functions but takes XML as input. For details on the available viewer parameters see Flash Viewer Parameter Reference.
public function setSize(width:uint, height:uint)
width (unsigned int) - width in pixels.
height (unsigned int) - height in pixels.
Sets the size of the 3D viewer movie. Ignored if the "resizeToStage" parameter has been set to true.
public function setInteractive()
Start running in interactive quality mode. The lower quality interactive model will be shown even if the object is static.
public function clearInteractive()
Stop running in interactive quality mode. The higher resolution model will be rendered when the object is static (i.e. not rotating, translating etc).
Including the 3DSOM Flash Viewer as part of a Flash project

The Flash viewer is not currently available as a Flash component. Instead the Flash movie should be loaded dynamically using standard AS3 to be included as part of a larger presentation or application. Here is an example...

var viewer3d:Object;
var urlReq:URLRequest = new URLRequest("3dsom_viewer.swf");
var ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.INIT, onViewerLoaded);
ldr.load(urlReq);
stage.addChild(ldr);

Once the viewer has been loaded as an Object, the public functions can be called to control the 3D content. For example the following function handles the initialisation event for the viewer...

function onViewerLoaded(evt:Event):void
{
    var params:XML = 
<parameters>
<param name="rotateX" value="0"/>
<param name="rotateY" value="2"/>
<param name="width" value="600"/>
<param name="height" value="550"/>
<param name="resizeToStage" value="false"/>
<param name="model" value="defaultModel.123"/>
</parameters>;
    viewer3d.setup(params);
}