RSS Feed
Sep 23

External Clips in Flash CS3

Posted on Wednesday, September 23, 2009 in Flash

// Array of external clips to use. Variable index refers to next clip to be displayed.

var clips:Array = ["clip0.swf", "clip1.swf", "clip2.swf"];

var index:int = 0;

// Stuff for loading files

var thisLoader:Loader = new Loader();

thisLoader.contentLoaderInfo.addEventListener(Event.INIT, doneLoading);

var thisMC:MovieClip = new MovieClip();

stage.addChild(thisMC); // Add empty MC initially so the nextClip function works even on first call

// Gets the next MC, waiting for INITialization before adding it to the stage

function nextClip():void {

thisLoader.load( new URLRequest(clips[index]) );

}

// Remove old clip, tell AS that the loaded file is the new one, add it to the stage, and play.

function doneLoading(e:Event):void {

stage.removeChild(thisMC);

thisMC = MovieClip(thisLoader.content);

thisLoader.unload();

stage.addChild(thisMC);

thisMC.gotoAndPlay(1);

}

// “Next button” calls a nextClip and increments index mod the number of files in the list

btnNext.addEventListener(MouseEvent.CLICK, playNext);

function playNext(e:MouseEvent):void {

nextClip();

index = (index + 1)%(clips.length);

}

Sep 22

create a ComboBox using ActionScript

Posted on Tuesday, September 22, 2009 in Flash

1. Create a new Flash file (ActionScript 3.0) document.
2. Drag the ComboBox component from the Components panel to the Library panel.
3. Open the Actions panel, select Frame 1 in the main Timeline, and enter the following ActionScript code:

import fl.controls.ComboBox;
import fl.data.DataProvider;
import flash.net.navigateToURL;

var sfUniversities:Array = new Array(
{label:”University of California, Berkeley”,
data:”http://www.berkeley.edu/”},
{label:”University of San Francisco”,
data:”http://www.usfca.edu/”},
{label:”San Francisco State University”,
data:”http://www.sfsu.edu/”},
{label:”California State University, East Bay”,
data:”http://www.csuhayward.edu/”},
{label:”Stanford University”, data:”http://www.stanford.edu/”},
{label:”University of Santa Clara”, data:”http://www.scu.edu/”},
{label:”San Jose State University”, data:”http://www.sjsu.edu/”}
);

var aCb:ComboBox = new ComboBox();
aCb.dropdownWidth = 210;
aCb.width = 200;
aCb.move(150, 50);
aCb.prompt = “San Francisco Area Universities”;
aCb.dataProvider = new DataProvider(sfUniversities);
aCb.addEventListener(Event.CHANGE, changeHandler);

addChild(aCb);

function changeHandler(event:Event):void {
var request:URLRequest = new URLRequest();
request.url = ComboBox(event.target).selectedItem.data;
navigateToURL(request);
aCb.selectedIndex = -1;
}

4. Select Control > Test Movie.