ActionScript - Part II

Creating a Slide Show

One can create a slide show by importing pictures, one to a frame, adding button for previous and next, and then using ActionScript in connection with these buttons. When the pictures are imported, if the first one imported is part of a numbered sequence of pictures in the same folder, Flash will ask you whether you want to import all of them, and will import them in the order of their numbering within the file names.

prevFrame(); -- this moves the timeline back one frame and stops
nextFrame(); - this moves the timeline forward one frame and stops

Using the above methods, if one is at the last frame, the nextFrame() will result in no change. If one wants instead to go to the first frame, one would use a conditional statement:

if (currentFrame == totalFrames) gotoAndStop(1);
else nextFrame();

If one is at the first frame, and one clicks the back button, the prevFrame() will result in no change. If one wants instead to go to the last frame, one would use a conditional statement:

if (currentFrame == 1) gotoAndStop(totalFrames);
else prevFrame();

Going to a URL

var goURL_req:URLRequest = new URLRequest("http://www.gmu.edu");
function goURL(event:MouseEvent):void {navigateToURL(goURL_req, "_blank");}

Whatever you want to be clickable (for the purpose of going to the URL), you would make a button symbol and then you would add an event listener to that button that would execute the goURL function when clicked.

Creating "Multipage" Content within Flash

1) Put each "page" of content in a separate frame -- do not put the material in adjacent frames, but instead space it out to leave room for frame labels to show up

2) Create a labels layer - give the first frame an appropriate name, name each of the other frames containing content using an appropriate name - remember to create a blank keyframe in any frame that you want to name. For the label to be visible, there have to be enough frames for you to see the label; if not, press F5 to add frames until the entire label is visible.

3) Create a buttons layer and add a button corresponding to each page of content. Since the artwork on these buttons will differ, one must create separate symbols for each button, but it may be easier to duplicate an existing button and then modify the content. Name each button instance appropriately in the Property Inspector.

4) Create an actions layer. Add a stop(); command to stop the main timeline. Suppose the layers and frames are both named bkgd and aboutus. Then the code would be:

function buttonClick1(event:MouseEvent):void {gotoAndStop("bkgd");
aboutus.enabled = true;
bkgd.enabled = false; }

function buttonClick2(event:MouseEvent):void {gotoAndStop("aboutus");
aboutus.enabled = false;
bkgd.enabled = true; }

bkgd.addEventListener(MouseEvent.CLICK, buttonClick1);
aboutus.addEventListener(MouseEvent.CLICK, buttonClick2);

--------------

The purpose of the statements which set the enabled property of the button instances is to disable the button that refers to the current location just as one often in web pages "delinks" a link that refers to the current page.

Refinements to Creating "Multi-Page" Content within Flash

The above approach used ActionScript to disable the button symbol that referred to the current frame. Another approach requires one to create an instance of the buttons in the buttons layer for each frame that is labelled (in the frames layer). (In the ActionScript approach where simply places an instance of each button in the initial frame and then adds frames (using F5) to the buttons layer so that they button show up in later frames). If one instead places an instance of each button in each "labelled" frame, then one changes the button instance referring to the current frame from a button to a graphic symbol. It will no longer function as a link.

Another approach can be used where the name of the layer is the same as the name of the button instance (as is the case above). In this case, the above code can be shortened to the following:

function buttonClick(event:MouseEvent):void {
gotoAndStop(event.target.name);
aboutus.enabled = true;
bkgd.enabled = true;
event.target.enabled = false; }
}

bkgd.addEventListener(MouseEvent.CLICK, buttonClick);
aboutus.addEventListener(MouseEvent.CLICK, buttonClick);

-----------

Thus, because we are able to get the name of the button when we click it, we are able to write a single buttonClick function

Revised: August 2, 2010. Comments to William Pegram, bill@billpegram.com