1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Macromedia Flash 8 (P2) ppt

20 662 3
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Chapter 1: Exploring Flash 8
Thể loại Bài giảng
Định dạng
Số trang 20
Dung lượng 398,16 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Everything inside the movie clip on which you want 9-slice scaling to work must be plain shapes not clip instances.. This also means that, if you want to employ one of the new Flash 8 fe

Trang 1

Undo command works (the Undo feature is

accessible by pressing Ctrl+Z) The default,

Document-level Undo, means that every time

you undo (by pressing Ctrl+Z), you go back

to the state before the last change Perhaps

this is the most intuitive behavior However,

the other option, Object-level Undo, is very

useful With this option, if you make changes

while inside one movie clip and then make

changes to another movie clip, you can

return to the first clip and press Ctrl+Z to

undo the last thing you did in that clip! It’s

the way Flash used to work (before version

MX2004), and it’s back as a preference

The margins for your text fields are also

easier to modify in Flash 8 You can now

grab any one of the six handles, as shown in

Figure 1.6 In previous editions, there was

only one special margin-changing handle;

dragging any other handle scaled and

stretched the text rather than the text field In

Flash 8, if you want to scale the text, you can

use the Free Transform tool or the Properties

panel’s W (width) and H (height) fields

FIGURE 1.6 Drag any handle on a text field to modify the

margin width in Flash 8.

In addition to the previously mentioned fact

that gradients can be applied to strokes,

gradients also sport a new overflow setting

(accessible in the Color Mixer panel) An

Overflow setting of Extend makes your gradi-ent fade off infinitely; a setting of Repeat lets the gradient fade from the beginning to the end and then repeat and fade from the begin-ning to the end; a setting of Reflect fades the gradient from the beginning to the end, fades

it back up to the beginning, and continues to fade it up and down Another change to the way gradients work in Flash 8 is that radial gradients support a focal point, which means you can create oblong off-center radial gradients

Some of the new Flash 8 features appear subtle or esoteric—and they are Although the 9-slice feature can be hard to see initially, it’s quite powerful When you select the Enable Guides for 9-slice Scaling option in a movie clip’s Symbol Properties dialog box (shown in Figure 1.7), you are given four special guides that make a tic-tac-toe pattern on the clip’s contents (The guides are editable only while you’re editing the symbol from the Library— that is, not by double-clicking an instance on the stage.)

The contents of your clip in the four outer squares don’t get scaled when the clip is scaled The midsections stretch as needed but not the corners This means you can use a single symbol scaled to multiple sizes and dimensions, but the corners won’t stretch or appear distorted You can see the difference between shapes scaled in various ways with 9-slice scaling in Figure 1.8 Notice how the wordclosedoesn’t appear stretched even though the clip’s width and height vary

Trang 2

FIGURE 1.8 The same symbol scaled to different

dimen-sions, yet the corners don’t scale.

FIGURE 1.7 The Enable

Guides for 9-slice Scaling

option lets you identify

which portions of your clip

shouldn’t scale (the four

corner squares).

One drawback of the Enable Guides for 9-slice Scaling

option is that it doesn’t work when your clip contains

nested clips Everything inside the movie clip on which

you want 9-slice scaling to work must be plain shapes

(not clip instances).

NOTE

Flash Player

Interestingly, it took a separate team about the same size as the team that built Flash 8 Professional just to build the new Flash player! Flash (the authoring tool) just creates swffiles, but the Flash player has to render those.swffiles—plus work with all kinds of browsers on different operating systems And

it does all this with a file size under 1MB My point is that the Flash player makes many of the new features possible For example, Flash player 8 now lets you load pngor.giffiles You don’t even need to author your applica-tion in Flash 8 to take advantage of this feature, but your users will need the Flash player 8 to properly load the content of your files

This also means that, if you want to employ one of the new Flash 8 features, your users must have the Flash player 8 plug-in

Trang 3

Two ways to face the prospect of forcing a plug-in upgrade on your users are to look at which new features you want (or need) and

to look at the upgrade experience the users will have to endure Every Flash version has some killer feature that—for the right project—makes an upgrade requirement worthwhile I’d imagine the video quality or alpha channels will be enough to convince many users to make the leap to Flash player

8 Only you can answer whether a new feature is profound enough or saves you enough time in production to require Flash 8—but there’s a lot of new stuff that could easily tip the scale

The upgrade process to Flash player 8 has

been vastly improved through what’s called

Express Install If your user has Flash player 6.0r65 or later, he already has an integrated feature you can trigger to install Flash player

8 inline That is, the user doesn’t have to download something, quit the browser, run

an installer, and so on He simply clicks Yes

in a security dialog box that appears right inside the Flash application (shown in Figure 1.10); a new browser window opens with your content, and Flash player 8 has been installed!

FIGURE 1.10 The inline Express Install dialog box appears inside your Flash application.

installed One nice new feature when

plan-ning to deliver to an earlier version of the

Flash Player is that you’re given feedback (as

to which features are not available) while

authoring Say you select File, Publish

Settings; click the Flash tab; and pick an older

target Flash player version (such as Flash

player 7) In that case, any newer Flash 8

features that don’t work in the older Flash

player version you selected are grayed out

In fact, if, after you select an older Flash

player, you attempt to access a grayed-out,

off-limits feature such as 9-slice, you are

presented with a dialog box and the option to

revisit your Publish Settings (as shown in

Figure 1.9)

FIGURE 1.9 Flash informs you when a feature is off-limits

to the Flash player you’re targeting.

Although you, the developer, undoubtedly

want to require your users to upgrade to Flash

player 8 so you can use all the cool new

features, your boss, client, or customers might

not be so eager to upgrade their browser

plug-ins to Flash player 8 On one hand, I

under-stand this reality It’s going to be a matter of

time before Flash player 8 is an accepted

minimum requirement for websites However,

it’s also important that you educate your boss,

client, or customers

Express Install is not the only upgrade approach and has its drawbacks, such as needing to first check which version the user

Trang 4

has and creating a Flash player 6 swfto

perform the Express Install Just read the

25-page document and associated sample files

in the Flash Deployment Kit (www

macromedia.com/go/fp_detectionkit), and

you’ll learn all the available options I

predict that this Express Install feature, along

with the killer features such as filters and

video, will greatly accelerate the adoption

rate for Flash 8 (historically taking 12

months for a new player version to reach

80% of all Internet users)

The express install is simply the most advanced option

available because it performs the install from within

the older Flash player Traditional ways of upgrading

users still exist For example, the default .html

gener-ated when you publish automatically presents the user

with a traditional Active X install dialog box in Internet

Explorer or the Missing Plug-ins button in Netscape

and Firefox.

NOTE

Flash Professional 8 and Flash Basic 8

I suppose this is a bit of a sour way to end an

otherwise exciting section about what’s

possi-ble with Flash 8, but I have to explain the

differences between the two versions of the

Flash 8 product Unlike the confusing and

subtle differences between Flash MX 2004 and

Flash MX 2004 Professional, the split between

Flash Professional 8 and Flash Basic 8 is

profound In a nutshell, the only reason to

purchase Flash Basic is if you need

supple-mental copies for machines dedicated for

some sort of Flash assembly line Macromedia

says Basic is for the “occasional user,” which

is accurate if you don’t plan on using most of

the new Flash 8 features, including using the

Flash interface to control filters or blends, producing videos that use the new On2 VP6 codec, and using advanced FlashType text settings—none of which are fully supported

in Flash Basic

Granted, Flash Basic is almost half the price

of Flash Professional But it’s not even that easy to purchase it You can’t purchase Basic

as part of Macromedia Studio 8 (the bundle that also includes Dreamweaver, Fireworks, and Contribute) And all upgrades from any older version of Flash lead to Flash

Professional Ultimately, the only good feature in Flash Basic is the fact there’s an integrated upgrade system to turn your version of Basic into Flash Professional 8

ActionScript Additions

ActionScript hasn’t gotten the same facelift it did when AS2.0 was introduced in Flash MX2004 Nevertheless, there are some pretty major additions to the ActionScript feature list—too many, in fact, to list them all here However, I’ll list the major new features in the following sections because most appear

in later chapters (even if the appearance is often hidden away in the support files)

A Programming Primer

Because the section that follows this section covers new ActionScript features, you’ll find it

peppered with terms such as variables, instances, and properties If this kind of

infor-mation is familiar to you, feel free to skip ahead to the next section (on the

flash.filterspackage) If such terms are

new to you, you’ll find additional definitions for such terms in the Glossary (as well as in

Trang 5

underscore in their names) Movie clip instances are the easiest type of object to understand because you can see them But there are also instances of the Sound and Date classes—just to name two

Chapter 2) However, instead of having you

keep one thumb in the Glossary while you

read this chapter, here’s a narrative

defini-tion of the terms that appear throughout the

rest of this chapter and the book Let me

stress two things before I start: First, if you

find this material basic, don’t worry, I

promise you’ll get plenty of opportunities to

adapt the projects in this book and flex your

programming skills (I won’t treat anyone

like a baby.) If, on the other hand, this

mate-rial is totally new to you, this explanation

will only provide an introduction to the

terms I use in this book I don’t suspect this

quick lesson will turn you into a hardcore

programmer, but at least you can follow

along when I explain the code behind the

scenes of each project You don’t have to add

any custom programming to build the

proj-ects, but you can And for me to explain

what’s going on, I have to use a

program-mer’s vocabulary

It’s easiest to start with the most common

object type, movie clips, because they have a

visual representation on stage A movie clip

symbol on stage is called an instance You

can give each instance on stage a unique

instance name by using the Properties panel

The instance name is used in your

ActionScript code to refer to the clip—or,

more technically, to address the clip The

reason you don’t use the symbol name (from

the master Movie Clip symbol in the Library)

is because you might have multiple instances

of that same symbol on stage and you want

to address each one individually Why would

you want to address a clip? Usually to

change one of its properties such as its

posi-tion on stage (either its _xproperty or _y

property, although there are many other

properties and they don’t always have an

I capitalized SoundandDatebecause, when you create an instance of these object types, you must use the exact, case-sensitive spelling.

NOTE

Think of this analogy: People have properties (such as hair color, weight, and age) and cars have properties (such as horsepower, make, and model) Interestingly, sometimes two

different object types share the same property.

Cars and humans both have a weight prop-erty Similarly, movie clip instances and button instances both have a widthproperty Often, however, the available properties depend on the type of object you’re working with Sound instances have a duration prop-erty, but movie clip instances don’t

The good news is that the code you write to address clips and their properties uses the

same form (or syntax) in every case regardless

of the object type Namely, the syntax to refer

to an instance’s property always looks like this:myInstance.myProperty(or “object dot property”) I use the prefix myto indicate something I made up so you don’t think the terms myInstanceormyPropertyare built in

to ActionScript Note that sometimes you

want to set a property (perhaps set a clip

instance’s _rotationproperty to make it

spin); other times you’ll just need to get a

property’s value to use within a larger

statement (A statement is a complete

Trang 6

instruction—basically one line of code.)

Check out this example:

myClip._x = otherClip._x

When Flash encounters this line of code, it

interprets the code and executes the

instruc-tions (meaning it does what the code says to

do) In this example, the instance called

myClipgets its _xproperty set to a value

equal to the _xproperty of another instance

calledotherClip (Anytime you see a single

equals sign, it’s an assignment meaning “is

now equal to,” as in “myClip’s _xis now

equal to otherClip’s _x”.) Notice that you’re

setting the _xproperty of myClipbut only

getting the property of otherClip

Another important concept is methods.

Methods are like processes or procedures

applied to a single instance You can also

think of methods as the capabilities a

partic-ular object type supports Back to the human

analogy: walk, talk, and comb your hair are

all methods—they’re all things an instance of

a human being is capable of doing Methods

you can apply to movie clip instances

includeplay(),stop(), and gotoAndPlay() I

like to compare properties to methods

because their syntaxes are nearly identical

It’s always “object dot method,” as in

myClip.play() An easy way to distinguish

methods is that they always have

parenthe-ses Some methods accept parameters (also

called arguments) that provide needed

addi-tional details For example, when you say

myClip.gotoAndPlay(1),1is a parameter

indicating which frame you want to go to

Events are things that happen while a Flash

movie plays The most intuitive event types

are things the user does, such as clicks, drags,

or presses a key Naturally, there are all kinds

of events, and like properties and methods, events vary depending on the object type For

example, Sound instances trigger or fire

events when the event onSoundCompleteis encountered (that is, when the sound ends)

A button instance has an onPressevent (but

noonSoundCompleteevent) Just as trees can fall in the woods without anyone to hear them, events can fire in Flash and—unless

your code is listening for that event—they go unnoticed You have to write code to trap (or

listen for) an event and define exactly how

you want to handle that event What’s a little

freaky is that events are really properties to which you assign a value Just as you might saymyClip._x = 100(to make the clip appear at the x position of 100), you could say myClip.onEnterFrame = myAnimationFunction—that says the myClip’s onEnterFrameevent (which fires every 1/12 of

a second if your frame rate is 12 fps)

is now equal to something called myAnimationFunction In both cases, a prop-erty (_xoronEnterFrame) is assigned a value

In this case, the value of the _xproperty is

assigned a value in the data typeNumber If you were to assign the labelproperty for a Button component, you would want to use a value of the data type String The value you assign to an event is of the type Function You can create variables as a way to store data for later use For example, you could assign a variable’s value with this code: myName = “Phillip”(which means the vari-able named myNameis now equal to the string

“Phillip”) You can change the value of a variable by simply reassigning a value, but

at any one instant, a variable has a single value You can store any data type in your

variable, but you’ll often want to type your

Trang 7

Sometimes the class you instantiate is part of Flash and other times the definition for its behavior resides in a class file (MyClass.as, for example) For instance, I created an EventChannelclass (in a file named EventChannel.as) for Chapter 3 You create

an instance by using the following syntax: myECInstance = new EventChannel();

After you have an instance of a class stored

in a variable, you can do anything you want with that instance That is, the class will probably expose public methods, which are methods you’re allowed to access and trigger Just as you can say myMovieClip.play(), you can also say myECInstance

startMonitoring()because I defined a public method called startMonitoring() (Exactly what happens when that method gets triggered depends on what the program-mer designed the class to do.) I should note

that private methods can be triggered only

from within the class itself; they are like internal utilities to help the class do its work Many times, you need to reference a class’s complete path, as in this example:

myInstance = new foldername.subfolder.MyClass()

I’ll discuss class paths in Chapter 2, but just realize that there may be a MyClassclass in the previous path shown and another— completely different—version of the same name in another path There’s no conflict because the code doesn’t refer to MyClassbut rather to foldername.subfolder.MyClass Think how we have a president (like the

variables—that is, to define the variable with

the data type it is allowed to contain Here is

an example of typing the myNamevariable as

aStringdata type:

var myName:String = “Phillip”;

The reason you type a variable is simply so

that Flash will give you a warning when you

publish if you write code that tries to assign a

value that doesn’t match the data type you

declared That way, Flash helps you uncover

mistakes in your code

In future versions of the Flash player, typing your

vari-ables will make your projects perform much faster.

NOTE

Finally, terms such as object and class are

thrown around a lot, but they’re actually

quite simple I’ve been talking about movie

clip instances because they’re so common,

but they’re actually instances of the class

MovieClip You could say that their object

type is MovieClip Instances of the class

MovieClipare easy to understand because

you make an instance by simply dragging the

symbol from the Library onto the stage For

most other object types, you must formally

instantiate them (as in “make an instance

of”) You always instantiate an instance of a

class by using this syntax:

myInstance = new MyClass()

You replace MyClasswith the class you’re

instantiating (By convention, all class names

begin with an uppercase character.)

Trang 8

code applies a BlurFilterwith a factor of 50

to a clip instance named myClipwhen the user clicks the stage; it then applies a differ-ent filter, with a factor of 5, when the user lets go:

onMouseDown = function(){

var veryBlurry = new flash.filters.BlurFilter(50,50); myClip.filters = [ veryBlurry ];

} onMouseUp = function(){

var lessBlurry = new flash.filters.BlurFilter(5,5);

myClip.filters = [ lessBlurry ];

}

Theflash.filterspackage lets you create any kind of filter the Filters panel can create, but you do it with ActionScript so it can respond to any event, such as the user’s mouse movement One other thing to note is that movie clip instances in Flash 8 have a filtersproperty

In addition to ActionScript equivalents to all the filters in the Filters panel, ActionScript offers three other classes (in the

flash.filterspackage) for even more advanced effects—namely,

ColorMatrixFilter,DisplacementMapFilter, andConvolutionFilter You’ll learn more about these in Chapter 9, “Creating Special Effects.” They’re identical to the

flash.filterspackage in that you still apply them to the filtersproperty, but the way in which you create them is much more involved

president of the United States), but you can

also have the Portland Cactus Collectors

President—and they reference different

posi-tions A class path is like a qualifier

With your ActionScript primer out of the way,

we will move onto the key new ActionScript

features in Flash 8

The flash.filters Package

Filters can be applied using the Filters panel

(while authoring) or using ActionScript code

This enables you to write scripts that modify a

filter’s effect at runtime For example, you

could make some text get blurrier as the user

moves the mouse away and sharper as the

mouse moves closer Writing the code to

apply a filter at runtime is a two-step process

First, you create a filter instance and store it

in a variable Second, you apply the filter to a

movie clip instance through its filters

prop-erty If you want to change the filter applied

to a clip, you simply modify the filter or

create another filter with different properties

and (in either case) overwrite the clip’s

filtersproperty Here’s a simple example in

which we apply a blur filter to a movie clip

instance named myClip:

myFilter = new flash.filters.BlurFilter();

myClip.filters = [ myFilter ];

Notice that the filters property is assigned an

array that contains just one item (myFilter)

By putting more filters in the array you can

apply more than one filter In addition, you

can set various parameters when you first call

theBlurFilter()function to affect how

much of a blur you want For example, this

Trang 9

myClip.attachBitmap(myBitmap, 0);

For some reason, I often forget that second parameter (the level number), but this parameter works the same way as how attachMovie()places a clip into a level number Every object, BitmapDataor MovieClip, that you create dynamically is

placed into its own level within another

movie clip—even if that movie clip is the main Timeline The higher level numbers make the object appear above objects in lower-numbered levels For the preceding code to work, you’d have to have previously created the myBitmapinstance Chapter 2 shows a simple example using the BitmapDataclass

I use the BitmapDataclass constantly to effec-tively take a snapshot of part of the screen For example, if I need to fade out one image while another image fades in, I simply make

aBitmapDatainstance by copying the pixels from the outgoing image Then I attach that BitmapDatacopy to a new clip (that I place

on top of the old clip) and then load a new image into the old clip When the new image

is fully loaded, I can fade out the clip with theBitmapDatainstance This is the same technique used in Chapter 4, “Creating a Portfolio.”

The flash.geom Package

On the surface, you might think the classes

in the flash.geompackage would be attrac-tive only to a true geometry nerd And, in fact, when you look at flash.geom.Point andflash.geom.Rectangle, they’re pretty much as you might expect: They offer methods for such things as calculating the

The flash.display.BitmapData Class

There’s just one class in the flash.display

package, and it’s a powerful one Many

people believe the BitmapData class is the

biggest improvement in Flash 8 Basically, it’s

a way to store raster images, which are really

just grids of pixels, into variables You can

create a bitmap image from scratch (for

example, you can create a grid of 10 × 10

white pixels); you can load a bitmap from an

image in your library (effectively copying the

pixels from an imported image); or you can

copy pixels from an area or a clip on stage

After the bitmap data is stored in a variable,

you can modify it—for example, you can

change its contrast or shape—and then

display it on stage This key step (necessary

to see a BitmapData instance) is the

MovieClip class’ attachBitmap()method

This method works just like attachMovie(),

as you can see in the following example:

Package Names

Many of the names used in the section headings that

follow are based on the respective class package name.

A package is simply the folder path to where the class

files are defined (within the Classes\FP8folder

inside the FirstRunfolder adjacent to your installed

version of Flash) The reason you’ll want to become

familiar with these paths is that you need to include

the full package path in your ActionScript code For

example, to use the BitmapDataclass, you have to say

flash.display.BitmapData Chapter 2,“Producing

a Flash Project,” covers more of the technical details of

referring to ActionScript classes (including how to use

theimportstatement), but for now, realize that I

included the package names in the following

descrip-tions to be more explicit and help begin to make them

more familiar.

Trang 10

distance between two points or determining

the union between two rectangles First,

doing those sorts of operations in the past

was much harder—so this package actually

makes things easier In the past, for example,

calculating the distance between two clips

(say, instances mc1andmc2) required you to

remember the Pythagorean Theorem (you

know, a squared plus b squared equals c

squared—except to solve for c you need to

take the square root) and this not-so-lucid

code:

a = mc1._x - mc2._x;

b = mc1._y - mc2._y;

cSquared = (a * a) + (b * b);

c = Math.sqrt( cSquared );

trace(“distance is “ + c);

Using the new flash.geom.Pointclass makes

it much clearer, I believe:

a = new flash.geom.Point(mc1._x, mc1._y);

b = new flash.geom.Point(mc2._x, mc2._y);

c = flash.geom.Point.distance(a, b);

trace(“distance is “ + c);

In addition to helping you solve geometry

problems, you’ll also end up using the classes

in the flash.geompackage because several

other classes require that you pass

parame-ters with the data type PointorRectangle

In fact, every project in this book uses this

package!

Like the new filtersproperty for movie clip

instances, movie clips have new properties

related to the flash.geompackage For

example, there’s a new scrollRectproperty

you can set equal to a Rectangleinstance

This is like a mask because it reveals a

rectangular portion of the clip, but the

scrollRectproperty is more like panning (or

scrolling) a camera’s view of an object For example, this code makes it appear as though the myClipinstance’s contents are shifting to the left when in fact it’s just the scrollRectthat is moving to the right: var panX:Number = 0;

onEnterFrame = function (){

panX++;

myClip.scrollRect = new flash.geom.Rectangle(panX,

0, 200, 200);

}

Another movie clip property related to the flash.geompackage is transform This prop-erty actually contains several other proper-ties, but I’ll start with just transform.matrix Thetransform.matrixproperty is a way to store all of a clip’s properties (such as _x,_y, and_xscale) in a single array (really, a

matrix of six numbers) In fact, you never

have to use _xor_yagain if you don’t want—all you have to do is modify the clip’s transform.matrixproperty The transform.matrixcan get very complicated

I have a simple and practical example in case you think matrixes are necessarily more complex than properties such as _xand_y Suppose you want to set all the properties of one clip (instance name oneClip) to match another clip (with an instance name otherClip) The “old” way would look like this:

oneClip._x = otherClip._x;

oneClip._y = otherClip._y;

oneClip._xscale = otherClip._xscale;

oneClip._yscale = otherClip._yscale;

//and so on ad infinitum

Ngày đăng: 13/12/2013, 02:16

TỪ KHÓA LIÊN QUAN