Skip to Content
ActionScript for Flash MX: The Definitive Guide, Second Edition
book

ActionScript for Flash MX: The Definitive Guide, Second Edition

by Colin Moock
December 2002
Intermediate to advanced
1088 pages
192h 4m
English
O'Reilly Media, Inc.
Content preview from ActionScript for Flash MX: The Definitive Guide, Second Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
44
|
Chapter 2: Variables
Changing and Retrieving Variable Values
After we create a variable, we can assign and reassign its value as often as we like, as
shown in Example 2-1.
Notice that we changed the variable
x’s datatype from numeric to text data by sim-
ply assigning it a value of the desired type. Some programming languages don’t allow
the datatype of a variable to change, but ActionScript does.
Of course, creating variables and assigning values to them is useless if you can’t
retrieve the values later. To retrieve a variable’s value, simply use the variable’s name
wherever you want its value to be used. Anytime a variable’s name appears (except in
a declaration or on the left side of an assignment statement), the name is converted
to the variable’s value.
Here are some examples. Note that
_x is a built-in property representing a movie clip’s
horizontal position with no relation to the variable named
x used in preceding exam-
ples (see the “Variable Naming Styles” sidebar in Chapter 1, and see MovieClip._x in
the Language Reference).
newX = oldX + 5; // Set newX to the value of oldX plus 5
ball._x = newX; // Set the horizontal position of the
// ball movie clip to the value of newX
trace(firstName); // Display the value of firstName in the Output window
Note that in the expression ball._x ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Essential ActionScript 3.0

Essential ActionScript 3.0

Colin Moock
ActionScript 3.0 Bible

ActionScript 3.0 Bible

Roger Braunstein

Publisher Resources

ISBN: 059600396XCatalog PageErrata