Checkbox and AS3 in Flash CS4

| September 1, 2009 | 6 Comments

flashfinalCheckbox and AS3 in Flash CS4

This is part of series on using components in Flash CS 4 with AS 3!

In this tutorial I will show you how to create a checkbox application in Flash CS 4 & use Action Script 3 to add the interactivity. I will be using a small area as this might be something that you would like to become part of a webpage, such as a survey.

Related posts:

Open a new Flash AS 3 Document with size 420px by 160px

Change the background by clicking on stage, and using the color #6699CC

Create 2 layers

interface – this layer will hold all the visual designs

actions – this layer as you guessed will hold all the actions

timelinkkkeCheckbox and AS3 in Flash CS4

Now will will create the user interface

Container

First take the rectangle tool and draw a box tot he right of the stage leaving a broader.

Give the rectangle rounded conners with dimensions of 13.65 for all conners. I also picked the Style to be “Stippled” with a stroke of 6.70 and a color of #336699. below is the properties that I used. This will act as our container.

rectangleCheckbox and AS3 in Flash CS4

Dynamic Text

Take the Text Tool and draw a rectangle to cover the inside of the container.

Set the Text property in the Properties to “Dynamic text” with a instance name of response_txt.

I am using the Font “Bradley HandITC TT” and set the color to #000030, with a size of 20.

Don’t forget to use Character Embedding

enbeddingCheckbox and AS3 in Flash CS4

Import image

Now we will import our image to the library.

File >Import to Library find out beach image import it to the library

Now drag the beach image to the stage and match the dimensions of the container.

Convert the Images to a movie clip by right click –> convert to movie clip give it a name of beach.

In the Color Effect in the property inspector change the style to “Alpha” with a value of 44%. This was the reason to convert the image to a movie clip.

Drag the CheckBox components to the library. We will use Action Script this time for the CheckBox!

Lock the interface layer,as we are done.

In the first frame of the actions layer right click go to actions and we start coding!

ActionScript

First we import that necessary CheckBox Class, and set up the main text, and display it to the dynamic text field we set up with reponse_txt

setjjupCheckbox and AS3 in Flash CS4

Now we will set up the checkbox:

First we create a variable for each checkbox and set this to a new CheckBox();

then we set the label of the checkbox(the text displayed for the checkbox)

Then we position the labels of each checkbox to place the text to the right and center of each checkbox.

Finally we need to add the checkboxes tot he display list.

Note – the ordering of the checkbox results depends on where they are in the display list!

checkboxesCheckbox and AS3 in Flash CS4

Now we need to add the Event Listeners for each of the checkboxes, which is a MouseEvent, and we call a function “displayCheckBox”

eventsCheckbox and AS3 in Flash CS4

Now we set up the function displayCheckbox

this function of of type MouseEvent, and we set to void as it does not return anything.

Then we change the response_txt to “Your Choice is” and  ”n” skips a line for nice formatting.

the stucture of the if statement is:

if the checkbox is checked (== true) then add the label to the checkbox to the dynamic text field by using the checkbox variable name.

resultsCheckbox and AS3 in Flash CS4

That is it, we are done`-`

flashfinalCheckbox and AS3 in Flash CS4

See this in action

downloadsCheckbox and AS3 in Flash CS4

Download Source

the source has the fla and the image used

Any Question, please e-mail me

Until next time, happyy flashing`-`

Johnny

Tags: , , , ,

Category: Flash tutorials

About the Author ()

John Barrett is a ColdFusion & Flash Developer at the University of Hawaii. I am also the manager for the Adobe Hawaii Flash User Group When not doing ColdFusion & Flash I can be found surfing on the North shore.

Comments (6)

Trackback URL | Comments RSS Feed

  1. Jon says:

    Hi, I have followed your tutorial but when i test my movie I keep ending up with this message and the text along side the checkboxes doesnt show up… any ideas??
    ReferenceError: Error #1069: Property Label not found on fl.controls.CheckBox and there is no default value.
    at Form_fla::MainTimeline/displayResults()

    apart from that awesome tutorial

  2. Jon says:

    Hi, I have followed your tutorial but when i test my movie I keep ending up with this message and the text along side the checkboxes doesnt show up… any ideas??
    ReferenceError: Error #1069: Property Label not found on fl.controls.CheckBox and there is no default value.
    at Form_fla::MainTimeline/displayResults()

    apart from that awesome tutorial

  3. Jon O says:

    Why do I keep getting this error message when I test my movie??
    ReferenceError: Error #1069: Property Label not found on fl.controls.CheckBox and there is no default value.
    at Form_fla::MainTimeline/displayResults()
    Great tutorial

  4. Jon O says:

    Why do I keep getting this error message when I test my movie??
    ReferenceError: Error #1069: Property Label not found on fl.controls.CheckBox and there is no default value.
    at Form_fla::MainTimeline/displayResults()
    Great tutorial

  5. Anup says:

    how can we use this in interactive map to hide and display images at particular point

  6. Anup says:

    how can we use this in interactive map to hide and display images at particular point

Leave a Reply