- Flash Guide 2006
- Welcome to the New Flash Reference Guide
- Flash Design Guide
- Introduction To Flash
- Working with the Authoring Tool
- Working with Templates
- FreeHand for the Power User
- Creating Animation with Fireworks
- Creating Animation in Flash
- Animating Text
- Working With Layers and Keyframes
- Working With Tweens
- Quickly Add Keyframes to Tweens
- Using Animation Paths
- Using Flash's Onion Skinning Tools
- Publishing Your Animation
- Preloading for Non-Programmers
- Drawing in Flash
- Using the Library
- Organizing Animations With Storyboards
- Working With Masks
- Making 2D Look 3D
- Working With Text
- Working With Input Text Fields
- Working With Dynamic Text
- Working with Text: Advanced Text Treatment With CSS
- Working With Text: Embedding Fonts
- Flash Interactive Developer Guide
- What is an Interactive Developer?
- Creating Flash Projects
- Using Form Applications
- Working with Form Components
- Setting up a Movie for Design and Animation
- Setting up a Movie for Programming
- Working with Components
- ActionScript Fundamentals
- Intro to Working With Arrays
- Understanding The Three Types of Arrays
- Control Data Stored in Arrays
- The Eolas Solution
- Intro to Flash Player 9
- Working with Strings
- Creating ActionScript Transitions
- Working with Boolean Objects in ActionScript
- Optimizing Delivery
- Working with Numbers in ActionScript
- Working with the Number Class
- Flash Professional 9 Preview
- Adobe Takes ActionScript Open Source
- Flash Rich Media Guide
- Pros and Cons of Flash 8 Video
- Using SMIL in Flash Video 8
- Stream an MP3 Audio File to Your Flash Movie
- Flash 8
- Introduction to Flash 8
- Advanced Text Rendering
- Using BitmapData Class in Your ActionScript
- The CacheAsBitmap Property
- Bitmap Rendering Improvements and Blend Modes
- Using The ExternalInterface Class
- Using Filters
- Downloading and Uploading Files with ActionScript
- Runtime Support for GIF and PNG Files
- Garbage Collection in Flash 8
- Using Enhanced Gradients
- Using Scale 9
- Stroke Enhancements in Flash 8
- Video Support in Flash 8
- How to Create a Slideshow
- Creating Dynamic Text in Flash
- Flash 3-D–Taking Flash to the Third Dimension!
- Object Collision Detection with Flash
- Create a Quiz With The Flash Quiz Template
- Working with Flash
- Uses for Flash
- Beyond Flash
- Flash Reference Guide
- Informit Articles and Sample Chapters
- Books
- Online Resources
- Blogs and Discussion
- Tools and Downloads
- Summary
- Flash MX Interface
- Welcome to Flash: the Designers' and Developers' Tool
- Using the Stage
- Panels, Panels Everywhere
- Using the Tools Pane
- Using the Property Inspector
- Using the Timeline Panel
- Using the Library
- Adding Interaction through the Actions Panel
- Integrating with Studio MX
- Saving and Publishing Flash Movies
- Informit Articles and Sample Chapters
- Books
- Online Resources
- Summary
- Drawing in Flash
- Shape Tools
- Applying Color
- Informit Articles and Sample Chapters
- Tools and Downloads
- Summary
- Flash Bitmaps
- Importing Bitmaps
- Exporting Bitmap Images
- Converting Bitmap Images to Vector Illustrations
- Informit Articles and Sample Chapters
- Online Resources
- Tools and Downloads
- Summary
- Flash Text and Text Fields
- Text Types
- Input Text
- Online Resources
- Tools and Downloads
- Summary
- Using the Library
- Library Organization
- Creating Instances
- Informit Articles and Sample Chapters
- Books
- Online Resources
- Summary
- Flash Animation
- Controlling Time
- Keyframe Animation
- Tweening
- Text Animation with Flash
- Informit Articles and Sample Chapters
- Books
- Online Resources
- Summary
- Flash Audio
- Using Audio in Flash
- Importing
- Linking to MP3
- Publishing Audio
- Streaming MP3 from the Flash Communication Server
- Informit Articles and Sample Chapters
- Online Resources
- Summary
- Video in Flash
- Video
- Flash Video
- Spark Codec
- Exporting Video
- Informit Articles and Sample Chapters
- Blog and Discussion
- Summary
- Flash Components
- Attaching Components to Movies
- Creating a Component
- Informit Articles and Sample Chapters
- Tools and Downloads
- Summary
- Exporting and Optimization
- Connecting Flash to the Internet
- Loading SWF Movies
- Sharing Fonts Between Movies
- Reusing Your ActionScripts
- Using Third-Party Tools
- Informit Articles and Sample Chapters
- Online Resources
- Tools and Downloads
- Summary
- Introduction to Design in Flash
- Introduction to Design
- Fundamental Design Concepts
- Breaking Up the Screen
- Branding
- Adding Forms to Movies
- Developing with ActionScript
- Introduction to Programming within Flash MX 2004
- Using ActionScript to Extend the Functionality of Flash
- ActionScript Fundamentals
- Using the Actions Panel
- Using the Reference Panel
- Rapidly Adding ActionScript with the Behaviors Panel
- Event Handling within ActionScript
- Timeline Events
- Triggering Events through User Interaction
- Flash MX 2004 Pro
- Summary
- Creating Interactive Movies
- Giving Users a Choice
- What it All Comes Down to
- Summary
- Testing your Flash Movies
- Naming Conventions
- Syntax Checker
- Testing your movies
- Summary
- Debugging
- Using the "Debugger"
- Reviewing ActionScript Error Codes
- Summary
- Using ActionScript to Control Your Movies
- Setting Up Your Movies for Interaction
- Making Movie Clips Behave Like Buttons
- Controlling Multiple Movie Clips
- Applying Different Types of Events to a Movie Clip
- Summary
- Using ActionScript to Control Text
- How ActionScript Can Control Text
- Using Cascading Style Sheets within Flash MX 2004 Dynamic Text Boxes
- Applying CSS formatting with ActionScript
- Where Do You Go Now?
- The Differences Between ActionScript 1 and ActionScript 2
- Working with Classes
- Which Version of the Flash Player should you use?
- What’s Next?
- Using Pre-Built Classes In Flash MX 2004
- Using a Class in ActionScript
- The List of Core Classes
- Flash Player-Specific Classes
- Summary
- Creating Your Own Classes
- Creating a Custom Class
- Working with External Data in Flash
- Why Use XML in Flash?
- Integrating Flash and XML
- Visual Elements
- Adding the ActionScript
- Future Shock
- Using Components
- Begin Using Components
- Building an Application with Components
- Gluing Components Together with ActionScript
- Summary
- Informit Articles and Sample Chapters
- Books and e-Books
- Online Resources
- Rich Internet Applications
- Introduction to Rich Internet Applications
- Why Use Flash for Building Application Solutions?
- Building Applications with Flash
- Getting Started
- Using Flash Variables
- Working with Parameters in the Object and Embed HTML Tags
- Linking data with Flashvars
- Getting Data Into Flash: Loading External SWF and JPG Files
- Why You Should Separate Your Files
- Loading Movies into Levels and Target Movie Clips
- Summary
- Loading SWF and JPG Images
- Working With XML: What is XML, and How Does it Relate to Flash?
- A Brief History of XML
- Why Structuring Your Data is Always a Good Thing
- How XML Came to Flash
- Summary
- Working with XML: Good XML vs. Bad XML
- Good Places to Start
- Writing Good XML
- XML Tools
- The Next Step - Using XML in your Flash Applications
- Working with XML: Loading XML into Flash
- Integrating Flash and XML
- Visual Elements
- ActionScript
- Future Shock
- Working with XML — Dynamically Building XML with .NET, ColdFusion, Java, and PHP
- ColdFusion
- .NET
- Java
- PHP
- Summary
- Working with XML — Web Services
- SOAP Support in Flash MX 2004
- Using Components to Bind Web Services into your Applications
- Summary
- Working with Data — Working with XML
- XML In Flash
- Writing XML In Flash
- Building Trees of Data with XML
- Working with Data: Pushing Data back to the Server with Load Vars
- Setting up the Database
- Writing the VB.NET Code
- Creating the Flash Movie
- Working with Data: Leveraging Persistent Connections
- Using XMLSocket Connections
- XMLSocket Server
- XMLSocket Security
- XMLSocket Class in Flash
- Creating a Pong Game with an XMLSocket Server
- Summary
- Flash Remoting
- What is Flash Remoting?
- Using Flash Remoting
- The Future of Flash Remoting
- Flash Remoting Links
- Working with Data: Macromedia Flex Presentation Server
- What Problem Does Flex Presentation Server Address?
- How does Flex work?
- Coding and Building Flex Applications
- Building Rich Internet Applications: Connecting Flash to a Database
- Using FlashVars
- Using LoadVars
- Loading XML
- Consuming a Web Service
- Live data connections with XMLSocket Connections
- Building Rich Internet Applications: Planning, Planning, Planning
- A Simple Plan
- Tools You Can Use
- Applying a Discipline
- Building Rich Internet Applications: Design Counts
- Do Not Be Afraid to Ask For Help
- What if You Do Not Have a Ben To Call
- Building Rich Internet Applications: Beyond the Movie Clip
- UI Components
- Data Components
- Media Components
- Manager Components
- Screen Components
- Building Rich Internet Applications: Using Macromedia Central
- What Central is All About
- Who is Using Central?
- Developing for Macromedia Central
- Next Steps You Need to Take
- Building Rich Internet Applications: Using Macromedia Flex
- Authoring with Flex
- Publishing with Flex
- Presenting the Solution: Delivering Flash Applications to the Web
- Flash's own Publishing Tools
- Using Dreamweaver
- Writing your Own HTML
- Presenting the Solution: Delivering Flash Over Non-PC Devices
- Using Macromedia's Flash Lite
- Programming for Flash Lite
- FlashCast
- Informit Articles and Sample Chapters
- Books and e-Books
- Flash for Designers: Rich Media Production
- Graphic Control in Flash
- Drawing in Flash
- Importing Vector Art
- Importing Raster
- Scripting Images
- Introduction to the Rich Media Production
- Using Video, Audio and Images in your Flash Movies
- Using SWF Flash Movies
- Using JPEG Images
- MP3 Sound Files
- Flash Video
- Using Components to Build Rich Media Solutions
- Using the Loader Component
- Using the Media Components
- Controlling Components with ActionScript
- Controlling the Loader Component
- Media Components
- Using Audio in Flash
- Linking to MP3
- ActionScript-Controlled Audio
- Volume Control
- Publishing Audio
- Summary
- Video in Flash
- Working with Video
- Controlling Video with Components
- Exporting Video
- Summary
- Choosing Which Version of Flash Communication Server to Use
- Server Requirements
- Installation
- Running Communication Server on Different OS Platforms
- Pitfalls to Watch for
- Summary
- Streaming Video
- Live Video
- Broadcast Video on Demand
- Flash Video Components
- The Communication Server MX Server Code for the VideoPlayBack Component
- Record Video with VideoRecord Communication Component
- Create A Video Conference
- Examining the VideoConferencing Component
- The Communication Server MX Server Code for the VideoConferencing Component
- Summary
- Using the Microphone and Camera Core Classes
- Microphone
- Camera
- Constructing Large Applications That Leverage Video and Audio
- Configuring the Server
- Creating the Movie
- Broadcasting
- Summary
- Informit Articles and Sample Chapters
- Books and e-Books
- Matthew's Predictions for 2006
- Matthew's Favorite Flash Books
- Matthew's Favorite Flash Web Resources
- Macromedia as Part of Adobe
- First Look: Flash Player 8
- First, the Facts
- What Macromedia Brings to the Table
- What Adobe Brings to the Table
- What the Two Companies Can Do for Each Other
- A Brief History of Flash
Creating three-dimensional Web sites is not new. In fact, almost a decade ago, Netscape founder Marc Andreessen declared that 1997 would be the year the Web became 3-D. Obviously, things didn’t quite work out according to Marc's plans. The initial technologies used to create 3D sites required large plug-ins and downloads and computers just weren’t very fast back then. This made even the most ambitious 3-D projects look, well, lame.
But, 3-D is back. And, you know what, I think they have it right this time. There is a little plug-in, called Flash, capable of delivering 3-D models, that over a quarter billion Internet users have already installed on their computers.
Creating 3-D in Flash, however, is not as easy as it is using a 3-D design studio, such as 3D Studio Max. Flash doesn’t have tools that allow you to easily create 3-D vector-based models. With Flash, you have to do it the hard way—you must use ActionScript.
To demonstrate this, let's go ahead and build a 3-D wire cube, as shown below. When you have the cube built, you’ll be able to spin it with your cursor.
Building A Solid Foundation
Let's begin by creating the buttons and movies you’ll need in your Flash Library. Open Flash and begin by creating a new movie (press CTRL+N). This movie will need four layers. You’ll need to name the layers Scripts, Cube, 3-D, and Movement as shown below.
The Scripts layer will hold all of the information critical to calculating your 3-D cube. The Cube layer will contain a movie that you’ll need to create the sides of the 3-D cube. The 3-D layer will contain a single movie needed to draw the perpendicular lines of the final 3-D cube; and the Movement layer will allow the mouse to control the view of the cube.
Make each layer three frames long. To do this, click, hold, and drag your cursor from frame 1 of the Scripts to frame 3 of the Movement layer. This will highlight the first three frames in the four layers. Press F5 to insert the needed frames.
Go to frame 1 of the Scripts layer. Press F6 to convert the frame to a Key Frame. Do this with the next two frames as well. Later, ActionScript will be added to these three frames.
Now, let's add the objects to the Stage that will generate a 3-D cube. Select the Cube layer. Choose the Line Tool. On the Stage, draw a line that’s 100 pixels long at a 45-degree angle. Press F8 to convert the line to a Movie. Name the new movie "Outline," as shown in Figure C.
The line on the stage is now an instance of the Outline movie. Press CTRL+I to open the Instance panel. Name this instance of the Outline movie "Wirecube," as shown below. Later, in your ActionScript, you will reference this movie.
Select the 3-D layer. With the Pencil Tool, draw a single dot on the Stage. Press F8 and convert the dot to a Movie. Name the new movie "Outline." Press Ctrl+I to open the Instance Panel and name the new instance of the Outline movie "Vertices." This movie is pivotal in creating the 3-D effect.
Finally, select the Movement layer. The final 3-D cube will be spun using your mouse. To do this, you need to begin by adding a little script. You’re going to tell Flash to drag the cube.
On the stage, draw a rectangle that’s 40 pixels wide and 20 pixels high. Press F8 and convert the graphic to a button. Call the button "movementbutton."
In the Library, open the new "movementbutton" in Edit mode. The button has four frames: up, over, down, and hit. The frames reflect the state of a mouse clicking on the button. Right now, you only have "up" and "hit" to select. Select the "hit" frame and convert the frame to a Key Frame by selecting F6. Now select the" up" frame and delete the rectangle on the stage. What you have left is a transparent button, as shown below. This new button is now tremendously useful. ActionScripts can be applied to it and a user can interact with it without ever knowing it is on the stage!
On the stage, select the instance of "movementbutton" and open the Actions panel (CTRL+ALT+A). The following script must entered:
on (press) { _root.pr=true; } on (release) { _root.pr=false; }
The code controls a variable, called "pr," that’s used in the script you’ll be adding to frame 1. Essentially, the action of the mouse being either pressed or released controls how the 3-D cube is drawn.
With the script in place, convert the button to a movie. Select the "mousebutton" instance on the stage, press F8, and name the movie "Movement." Open the Instance panel and name the instance of the movie "cursor."
Save you current movie as 3-D Cube.fla.
Adding the Script
Now comes the hard bit.
The vast majority of the script needed to create the 3-D cube will be placed in frame 1 and 2 of the Scripts layer.
Select frame 1 and open the Actions panel. You’ll need to be working in Expert mode. With the Actions panel open, press CTRL+E to convert the mode to Expert. Define all of your variables before writing any script.
It’s good practice to keep all of your variables at the top of your script. This makes it easier for troubleshooting later on.
cube = 8; cubeoutline = 12; fov = 180; rotate_x = 0; rotate_y = 0;
Sin " Cos are the mathematical kingpins behind this 3-D model. Yes, it’s back to Math 101. But the value is that an intricate 3-D model can be drawn with very little scripting. The following script is the array that generates Sin and Cos.
cos = new Array(360); sin = new Array(360); for (i=-180; i<=180; i++) { cos[i+180] = Math.cos(i*Math.PI/180); sin[i+180] = Math.sin(i*Math.PI/180); }
The following array defines the structure of the wires surrounding the final cube.
wirecube._visible = false; c = new Array(cubeoutline); for (n=1; n<=cubeoutline; n++) { wire-cube.duplicateMovieClip("c" add n, n); c[n] = eval("c" add n); } c[1].per1 = 1; c[1].per2 = 2; c[2].per1 = 2; c[2].per2 = 3; c[3].per1 = 3; c[3].per2 = 4; c[4].per1 = 4; c[4].per2 = 1; c[5].per1 = 5; c[5].per2 = 6; c[6].per1 = 6; c[6].per2 = 7; c[7].per1 = 7; c[7].per2 = 8; c[8].per1 = 8; c[8].per2 = 5; c[9].per1 = 1; c[9].per2 = 5; c[10].per1 = 2; c[10].per2 = 6; c[11].per1 = 3; c[11].per2 = 7; c[12].per1 = 4; c[12].per2 = 8;
After the lines of the cube have been calculated a similar array must be used to calculate the perpendicular lines.
perp._visible = false; per = new Array(cube); for (n=1; n<=cube; n++) { perp.duplicateMovieClip("per " add n, n+cubeoutline*2+cube); per [n] = eval("per " add n); }
The final array defines the vertices.
vertices._visible = false; v = new Array(cube); sv = new Array(cube); for (n=1; n<=cube; n++) { verti-ces.duplicateMovieClip("v" add n, n+cubeoutline); v[n] = eval("v" add n); } v[1].perx = -50; v[1].pery = -50; v[1].perz = 50; v[2].perx = 50; v[2].pery = -50; v[2].perz = 50; v[3].perx = 50; v[3].pery = 50; v[3].perz = 50; v[4].perx = -50; v[4].pery = 50; v[4].perz = 50; v[5].perx = -50; v[5].pery = -50; v[5].perz = -50; v[6].perx = 50; v[6].pery = -50; v[6].perz = -50; v[7].perx = 50; v[7].pery = 50; v[7].perz = -50; v[8].perx = -50; v[8].pery = 50; v[8].perz = -50;
To allow you to drag a cursor over the cube, you must add the "Drag" method. This is the final element of code you need for frame 1.
cursor.startDrag(true);
Now, select Frame 2 from the Scripts layer. The function of the code in Frame 2 is to calculate the spin and redraw the 3-D cube. This is calculated through a "for" action, as shown in the following script:
for (n=1; n<=cube; n++) {
Next, the vertices of the cube are redrawn with the following code:
with (v[n]) { k = _root.fov/(_root.fov-perz); _x = 200+perx*k; _y = 200-pery*k; _xscale = 100*k; _yscale = 100*k; _alpha = 50*k; }
Following the vertices, the perpendicular lines are then calculated.
per[n]._x = v[n]._x; per[n]._y = v[n]._y; per[n]._yscale = (100+v[n].pery)*fov/(fov-v[n].perz); per[n]._alpha = v[n]._alpha; } for (n=1; n<=cubeoutline; n++) {
Finally, the rotation of the X- and Y-axis are defined.
tz = v[n].perz; ty = v[n].pery; rotate_x2 = int(rotate_x)+180; v[n].perz = tz*cos[rotate_x2]-ty*sin[rotate_x2]; v[n].pery = ty*cos[rotate_x2]+tz*sin[rotate_x2]; // Rotate Axis Y tx = v[n].perx; tz = v[n].perz; rotate_y2 = int(rotate_y)+180; v[n].perx = tx*cos[rotate_y2]-tz*sin[rotate_y2]; v[n].perz = tz*cos[rotate_y2]+tx*sin[rotate_y2]; // The following code draws the outline of the cube c[n]._x = v[c[n].per1]._x; c[n]._y = v[c[n].per1]._y; c[n]._xscale = v[c[n].per2]._x-v[c[n].per1]._x; c[n]._yscale = v[c[n].per2]._y-v[c[n].per1]._y; c[n]._alpha = (v[c[n].per1]._alpha+v[c[n].per2]._alpha)/2; s[n]._x = c[n]._x; s[n]._xscale = c[n]._xscale; s[n]._alpha = c[n]._alpha; s[n]._y = 200+100*(fov/(fov-v[c[n].per1].perz)); s[n]._yscale = 100*(fov/(fov-v[c[n].per2].perz)-fov/(fov-v[c[n].per1].perz)); } if (pr) {
The following code will allow Flash to remember where the cube has been and allow for the new lines of the cube to be created:
rotate_x = (legacyy-_ymouse)/2; rotate_y = (legacyx-_xmouse)/2; } else { rotate_x *= 0.9; rotate_y *= 0.9; } legacyx = _xmouse; legacyy = _ymouse;
When this is all done, the final step is to add code to Frame 3 that will ensure that the movie keeps playing. Select Frame 3 of the Scripts layer and add the following code to the Actions panel:
gotoAndPlay (2);
Frame 1 draws the cube and Frame 2 controls how the cube is redrawn as determined by the user’s interactions with it. Now, press F12 and watch it all come together. Your cube will spin in a 3-D world as you drag your cursor over it.
What Next?
A true 3-D world is not easily created in Flash, but 3-D models can be built with the use of some ActionScript—and the rewards are great. The 3-D cube created in this article is only 4Kb in size. This makes the model highly portable for anyone connecting to the Web. Every 3-D model that is created follows the fundamentals you have now mastered. The 3-D revolution is about to begin.