Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Introduction to assets

mzyndul edited this page Nov 23, 2012 · 1 revision

Table of Contents

Overview

This is an AS3 example project built to demonstrates how to use the media asset types in Gaia AS3: BitmapAsset, BitmapSpriteAsset, SoundAsset, NetStreamAsset and MovieClipAsset.

View Demo

Site XML

Here is the site.xml for this example site.

<site title="Gaia Framework Site: %PAGE%" menu="true" assetPath="assets/">
    <page id="index" src="index.swf">
        <page id="image" title="BitmapAsset" src="image.swf" menu="true">
            <asset id="galaxy" src="galaxy.jpg" depth="nested" />
            <asset id="image1" src="junglebook.jpg" depth="top" type="sprite" />
            <asset id="image2" src="rollingrock.jpg" preload="false" type="sprite" />
            <asset id="image3" src="grain.jpg" preload="false" type="sprite" />
            <asset id="image4" src="tiberium.jpg" preload="false" type="sprite" />
        </page>
        <page id="sound" title="SoundAsset" src="sound.swf" menu="true">
            <asset id="sound" title="Funky Loop" src="sample.mp3"/>
        </page>
        <page id="video" title="NetStreamAsset" src="video.swf" menu="true">
            <asset id="video" title="Scooter Race" src="sample.flv" preload="false"/>
        </page>
        <page id="swf" title="MovieClipAsset" src="movieclip.swf" menu="true">
            <asset id="clip" src="sample.swf" />
        </page>
    </page>
</site>

BitmapAsset

The purpose of this page is to demonstrate some simple functionality for BitmapAssets and BitmapSpriteAssets. The page has a background graphic, galaxy, which loads with the page and is nested inside the page. Because it is nested in the page, the page's alpha transition affects galaxy, as well.

There are four on-demand assets which are BitmapSpriteAssets, by virtue of their type="sprite". You can drag these around the stage. The Jungle Book thumbnail has its depth set to top to demonstrate how it stays on top of all the other thumbnails. Each of the other thumbnails is brought to the top of the display stack when clicked on. Because these assets are not nested, they are transitioned out explicitly, unlike the galaxy asset.

SoundAsset

This page demonstrates basic usage of a SoundAsset. The sound is preloaded with the page and starts playing when transitionIn() is called. There is information displayed in dynamic text fields, and three buttons. One to pause/play the audio, one to fade the audio down and up, and one to fade the pan left to right.

NetStreamAsset

This page is nearly identical to the SoundAsset page except it is using a NetStream video and demonstrates how to attach a NetStreamAsset to a Video and how to display information about the video. It has the same controls as the SoundAsset page.

MovieClipAsset

This page shows the basics of how to use MovieClipAssets. There are two buttons, one that calls a public method inside the loaded MovieClip's document class, and one that sets a public property of the loaded MovieClip's document class, both of which update the text field inside the MovieClip.

Casting Assets To Interfaces

Using the Interfaces for Assets is optional and the code in the class files shows how you can either cast or not. If you prefer strict typing and code hints, you can cast the assets to their interfaces if you like, but it is not required. The sample code does it both ways, and either would work in any of the specific uses.

Source Code

The source code for this lesson can be found here:

AS3: http://www.gaiaflashframework.com/lessons/assets/AssetLesson.zip

Clone this wiki locally