Archive

Posts Tagged ‘ActionScript 3’

Event Listeners

June 2, 2008 bmorrise 2 comments

Event listeners are an important part of Flash. What they allow you to do is to “listen” for an event that occurs on a specific object. For example, one event that often occurs in Flash is a button getting clicked. When a button is clicked the button object dispatches an event telling flash that is was clicked. Often times we want to respond to a click and function. Say we have a window that pops up and on the window there is a cancel button. We want the window to close when the cancel button is clicked. Here is the code:

cancelButton.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(event:MouseEvent):void
{
//Write the code here that closes the window
}

In this example I have added a button to the window and given it the instance name cancelButton. This allows me to listen to that button and respond to the events.

Full Screen in ActionScript 3

April 28, 2008 bmorrise 49 comments

I’ve gotten several hits from search engines with the keywords “Full Screen” and I don’t have anything on here that actually shows how to do full screen. It’s pretty easy. Here is the code:

import flash.display.StageDisplayState;

function goFullScreen():void
{
    if (stage.displayState == StageDisplayState.NORMAL) {
        stage.displayState=StageDisplayState.FULL_SCREEN;
    } else {
        stage.displayState=StageDisplayState.NORMAL;
    }
}

stage.addEventListener(MouseEvent.CLICK, _handleClick)

function _handleClick(event:MouseEvent):void
{
    goFullScreen();
}

This code is pretty simple. What it does is make the Flash movie go full screen when you click anywhere on the stage. This could easily be tweaked so that it responds to a button click.

Keep in mind that this will only work when you view this in the browser. It’s doesn’t work when compiled inside of Flash CS3.

One thing you want to make sure of is that your embed code has the
<param name=”allowFullScreen” value=”true” /> tag in the param tags list as well as the allowFullScreen as an attribute in the embed tag. Here is an example:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="Untitled-3" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<font color="#0000FF"><param name="allowFullScreen" value="true" /></font>
<param name="movie" value="Untitled-3.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="Untitled-3.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="Untitled-3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

Basic Functions and Sprites

April 21, 2008 bmorrise Leave a comment

This tutorial shows you the basics of function writing as well as some programmatic drawing.

Note: You can watch the videos in full screen by clicking the full screen button on the tutorial’s control bar.

Watch the Tutorial

Control Structures, Loops, and Arrays

April 17, 2008 bmorrise 3 comments

In this tutorial we focus on if statements, for and while loops. We’ll also be taking a look at arrays.

Note: You can watch the videos in full screen by clicking the full screen button on the tutorial’s control bar.

Watch the Tutorial

Basic ActionScript 3

April 16, 2008 bmorrise 1 comment

This tutorial is probably only for those who don’t have much programming experience. I show you how to open the Actions panel that we use to input ActionScript. I also show how to use String variables and how to set the text of a Text Field dynamically. I also show how to create a simple function.

Note: You can watch the videos in full screen by clicking the full screen button on the tutorial’s control bar.

Watch the Tutorial