Flash Player 10 New Features

Flash Player 10 New Features

with Lee Brimelow

 


In Flash Player 10 New Features, Adobe evangelist Lee Brimelow highlights a number of the useful advancements and new capabilities in Flash Player 10. He walks through how to set up a system for development and testing, and he shows how to use the new Pixel Bender tools to create beautiful filters and export them to Flash. Lee covers the new sound and drawing APIs, which can be used to add real-time audio effects and UV texture mapping to any project. He explores new features that can take any Flash developer’s skills to the next level. Exercise files accompany this course.
Topics include:
  • Creating 3D animations in Flash CS4
  • Building an interactive 3D picture cube with correct mapping
  • Working with vertical and right-to-left international text
  • Generating dynamic sounds directly from Flash
  • Using the Speex audio codec for vocal audio compression

show more

author
Lee Brimelow
subject
Developer, Web
software
Flash Player 10
level
Beginner
duration
4h 0m
released
Oct 01, 2009

Share this course

Ready to join? subscribe


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00(Music playing.)
00:03Hi! My name is Lee Brimelow and I work as a platform evangelist at Adobe.
00:08In Flash Player 10 New Features, I am going to show you how to take advantage of
00:11all the new features in Flash Player 10, like native 3D support, a new text engine,
00:17dynamic sound generation, local file access, and much more.
00:22By the end of this title you'll have the knowledge and skills needed to create
00:25cutting-edge Flash content using the newest features the player has to offer.
00:30Now most educational materials for Flash are focused on a particular release of
00:35the Flash authoring tool, such as Flash CS4, but it's equally important for you
00:40to know how to use the newest features of the Flash Player.
00:43Many of these features, which are not even exposed yet in the authoring
00:47environment. So with that let's jump in and get started.
Collapse this transcript
How to use the exercise files
00:00If you are a premium member of the lynda.com Online Training Library or
00:04if you're watching this tutorial on a DVD-ROM, you have access to the Exercise Files
00:09that I use throughout this title.
00:11So if we look at the Exercise Files, we can see they are actually broken up
00:15by chapter and inside of each chapter there is a folder for each video in that chapter.
00:21So if I go inside of this one we can see it contains a number of different assets.
00:25We have an image here, we have a package of ActionScript files, we have the
00:30FLA that I start with in the video, and we also have a Pixel Bender filter in this example.
00:36And you can also see that I provided the Finished.fla and this is essentially
00:41the finished product that we create in this particular video.
00:44So now if you don't have access to the Exercise Files, you can of course follow
00:49along from scratch and use your own assets.
00:53So let's get started.
Collapse this transcript
Setting up your system
00:00So before we get started looking at all the new features in Flash Player 10,
00:04you go on and make sure you've set up your system so that you can actually publish
00:08to this new version of the Flash Player.
00:10So throughout this title, I am going to be using Flash CS4 to do my development.
00:14Now it's important to note that Flash CS3 doesn't have any built-in way of
00:19actually publishing for Flash Player 10.
00:21So you're going to need to use CS4.
00:24Now in addition to that, the first initial release of Flash CS4 had quite a few
00:29bugs in it and it was somewhat unstable.
00:33Luckily the Flash team has released a free update to Flash CS4, which you're
00:37going to want to make sure you have installed.
00:40To find out which version you have, you can go to the Flash menu if you are on Mac.
00:44If you are on PC, you can go to the Help menu and choose About Flash.
00:49And here it will actually tell you, your version number.
00:51So here I have 10.0.2 installed, which is the latest version.
00:57If you don't have that, you can go to the Flash downloads site and this is at
01:03http://www.adobe.com/ support/flash/downloads.html.
01:10And this page just essentially has any new downloads that relate to either the
01:15Flash Player or Flash CS4.
01:17We could see if we scroll down here this Adobe Flash CS4 Professional Update 10.0.2.
01:23So you're going to want to make sure you download this either for Windows or for
01:28Mac and update it, and your Flash installation is going to be a lot more stable.
01:34Now another tool that you're going to want to get is the Pixel Bender Toolkit,
01:37and this is used to create new filters and effects for Flash.
01:42So this can be found on the Adobe Labs website.
01:46If you go to labs.adobe.com/ technologies/pixelbender, this will allow you to
01:52download the free Pixel Bender Toolkit.
01:55So if I come into this Downloads part here and click this, we can see that I can
02:01again choose either a Mac or Windows installation.
02:05So throughout this title there going to be a few additional downloads of
02:10things like ActionScript libraries, but we'll deal with those when we actually get
02:14to them in the title.
02:16Now it's also important to note that although I'm using Flash CS4 to do my
02:20development, you could also use Flex Builder or even the Flash Builder Beta
02:25that's currently out to do your development.
02:28You just going to have to do the little bit of extra work of actually turning my
02:31code into class files for use in Flex Builder.
02:35So with these pieces installed, you are now ready to start developing for Flash Player 10.
Collapse this transcript
Overview of Flash Player 10
00:00So before we actually get started looking at the new features of Flash Player 10
00:04in detail, it's helpful just to have an overview of what is actually changed in
00:09this version of the Flash Player.
00:11Let's start with the new native 3D support.
00:14So this native 3D is meant for simple 3D effects and transitions.
00:19This isn't a full-blown 3D engine with lights, cameras and shaders.
00:24If you need to do simple 3D effects, this Native 3D Support is extremely easy to use.
00:30What this is, is essentially a set of new 3D properties on display objects and
00:36display objects are again things like sprites and movie clips.
00:39So now you just have some additional properties like the Z property to actually
00:44manipulate and position display objects in 3D space.
00:48This 3D is actually fully interactive, so let's say I have a movie clip with a
00:53button inside of it.
00:54If I put that movie clip in 3D space I can still click on that button inside of it,
00:59so the 3D remains fully interactive.
01:02Any 3D objects you create are also automatically anti-aliased, so there
01:06aren't jagged edges.
01:08Everything looks smooth and nice when you put it into 3D.
01:12And again, the important thing is this is not meant to replace 3D engines like
01:17Papervision3D, which are full-blown 3D environments.
01:21If you want to create these kind of immersive 3D worlds, you are still going to
01:25want to use open source engines like Papervision3D.
01:29Flash Player 10 also has a brand new text engine inside of it.
01:33This text engine has been completely rewritten, and it allows you to do some
01:37really advanced typography and text layouts inside of the Flash Player.
01:42So this text engine was used to create a set of advanced text components called
01:48the Text Layout Framework that we're actually going to look at that allows you
01:52to do some really advanced things with text.
01:54Now these components were actually worked on by the Adobe InDesign team, and
01:59it's basically their whole world is text.
02:02So if you want any team in the world to be working on these components, it would
02:05be the InDesign team.
02:07So the text engine is actually a really low level ActionScript 3 API.
02:12Now you have access to that API so if you are really knowledgeable about text,
02:16you can use that API.
02:18But most people are just going to use these new advanced text components that
02:22basically allows you to just right out of the box, do some advanced things with text.
02:27So with this text engine you can easily create right to left and vertical text,
02:31which is really important when you are internationalizing your Flash content, so
02:36languages like Japanese that actually is right to left and vertical, doing that
02:41in previous versions of the Flash Player was extremely difficult.
02:45Device fonts are now equal to embedded fonts, so every Flash developer has had
02:51that situation where you use a device font but then you try to animate it or
02:56fade it and you can't do it.
02:57Well in Flash Player 10, device fonts can now be animated. You can change the
03:03transparency of them.
03:05So Pixel Bender is a brand new technology that allows you to create your own
03:10filters and effects for Flash.
03:13So in Flash 8 we actually released some basic filters like Drop Shadows, Bevels, and Blurs.
03:19Well, this new language, a tool, allows you to create your own.
03:24Now these filters that you create in Pixel Bender can be used inside of Flash
03:29but also inside of Photoshop and After Effects.
03:32So we've unified the actual language that you use to write filters and effects
03:36for all three tools.
03:38And the place where you are going to actually write your Pixel Bender filters is
03:42called the Pixel Bender Toolkit, and we're going to look at how to create some
03:46simple Pixel Bender filters later on in the title.
03:50So sound has had a major overhaul in Flash Player 10.
03:53You now have the ability to actually create sound from scratch inside of the Flash Player.
03:59And the way you do this is to respond to an event and Flash is actually going
04:04to ask you for raw sound data.
04:06So if you know a lot about audio or sound, you can actually provide just raw
04:11binary data and have it be played back by Flash.
04:15You also have now the ability to extract the bytes of an external sound,
04:20let's say an external MP3 file that you're playing.
04:24You can extract the bytes of that file as it's coming into the Flash Player,
04:28manipulate those bytes before they actually get sent to the sound card.
04:31So this allows you to create real- time effects and processing for sound.
04:36There have also been several bug fixes to the existing sound API, especially
04:41surrounding the soundComplete event, so your general sound APIs have been
04:47improved in addition to having all of these new capabilities.
04:51Local file access is another really big feature in Flash Player 10, and this
04:55allows you to directly read local files from the user's machine and it also
05:01allows you to save files directly to the user's machine directly from the Flash Player.
05:07Now this saving and reading of local files actually requires user interaction.
05:12So you can't do it programmatically, so the user has to actually initiate this
05:18either through a key press or a mouse-click.
05:21So there are no more round trips to your server required.
05:24So let's take an instance of you wanted the user to be able to load in an image
05:28from their hard drive into your Flash movie.
05:31In previous versions of Flash you would actually have to have them uploaded
05:34to your web server and then you would download it from your web server into your Flash movie.
05:39Well, now we can do this directly without that round-trip.
05:42Now these new features are also part of some new security changes to the file
05:47reference class that we're going to look at as well.
05:50So there's been some major enhancements to the drawing API in Flash Player 10.
05:54So we now have an API for drawing triangles.
05:58Now if you've done 3D development before, you know that in 3D everything is
06:02made up of triangles.
06:03So we now have this low-level API to be able to draw triangles in 3D space.
06:08Now these triangles also support UV texture mapping and this is essentially how
06:14you would create say a 3D engine inside of Flash.
06:17You would be drawing triangles and you'd be mapping textures onto those triangles.
06:23We now have the ability to do gradient and bitmap strokes.
06:26There is a new object-based drawing model.
06:29So in previous versions of Flash you would have to say line to, line to, move to,
06:34all these commands. Now we can actually save those commands inside of an
06:38object, so we can easily either change them or update them.
06:42And the performance of the drawing API has been greatly increased also.
06:47And we're going to look at certain methods that you can use that greatly enhance
06:51the performance when you want to draw graphics at runtime.
06:55So there is also a whole host of smaller features.
06:58We have a new vector data type.
07:00Vectors are essentially mono-typed arrays.
07:03So in the regular array class you can store all different types of information.
07:08You could store a string, a movie clip.
07:10A vector is essentially an array that can only hold a single type of data and
07:15the benefits are greatly increased performance when you use vector over array.
07:20We now have partial fullscreen keyboard support in Flash Player 10.
07:24In previous versions of Flash if you went fullscreen with your application
07:29in the browser, you couldn't accept any keyboard input and this was for security reasons.
07:33So this made it pretty hard to actually create a fullscreen game in Flash.
07:38In Flash Player we've loosened the security restriction to allow you to accept
07:43any non-printing keys like the Spacebar or the Arrow keys.
07:47So it's now a lot more likely that you would be able to create fullscreen games in Flash.
07:51There have been some enhancements to the garbage collection features, especially
07:56when it relates to cleaning up external SWF files and content.
08:01You can now do multi-bit rate video streaming inside of the Flash Player and
08:05this is in conjunction with Flash Media Server 3.5 and this basically allows
08:10you to on-the-fly change the bit rate of the video that the user is seeing and
08:17the user won't have any idea that it's actually happened.
08:19So it's completely sceneless, so you are not asking them to switch to a
08:23lower bit rate stream.
08:25We have a microphone codec called Speaks, which is a high-quality codec
08:29specifically for voice.
08:31We've also added some new hardware acceleration features.
08:34The goal of Flash is to try to offload as much as we can to the user's GPU
08:40and Flash Player 10 has increased the amount that we're doing that, but
08:44definitely moving forward, that's a goal to continue to do that.
08:49So those are the major features in Flash Player 10 and now we can actually get
08:52started and learning how to use these features to create some cool content.
Collapse this transcript
1. 3D Effects
Understanding the new 3D capabilities
00:01So one of the biggest new features in Flash Player 10 is the introduction
00:05of native 3D support.
00:07This is something that the Flash community has been asking for for years,
00:11and Flash Player 10 represents our first attempt to add some native support
00:16in the Flash Player.
00:17So in this video, I'm just going to briefly describe the capabilities of
00:21this new 3D support.
00:23So you can open up 3-D_overview.fla file and let's just quickly look at the
00:30structure of this movie.
00:31So I have a movie clip here and I have double-click inside of it. I just have a
00:35simple two-frame movie with some actions and all it does is it changes the
00:41current frame when you rollover or roll out of it.
00:45So if we go back to the main timeline, I'll just test this so you can see
00:49it just essentially has a rollover state here.
00:53So the easiest way to use the new 3D capabilities is here inside of Flash CS4,
00:58because there are some new 3D tools that allow you to do it on the timeline
01:02without actually having to know any ActionScript.
01:06So if we come down here to the fourth tool group in the Tools panel, we can see
01:10we have a 3D Rotation tool.
01:13So if I select that and click on my movie clip, we can now see we have a little
01:17controller here that allows me to rotate this clip in 3D space.
01:22So I can move it on the Y-axis here.
01:24If I move to the blue circle, I can move it on the Z-axis and I can also move it on the Y-axis.
01:33So now this 3D is commonly known as postcards in space or 2.5D.
01:40That's because when I rotate this around, we can see that this actually has no depth to it.
01:46So it's just like taking a postcard and rotating it.
01:49So when you get around to the side, you essentially see nothing, because it has no depth.
01:54Now, this is the same type of 3D that you find in tools like After Effects.
02:00So that's the 3D Rotation tool.
02:02The other tool that's buried in here is the 3D Translation tool.
02:06So translation is just a fancy word for moving something.
02:10So here I can move it on the X-axis, I can move it on the Y-axis, or I can
02:16move it on the Z-axis.
02:18When I do that, we can see it's actually bringing it farther or closer away from the camera.
02:24Now, the 3D Engine in Flash Player 10, we don't have an actual camera, but
02:28you can just take your viewpoint as being the camera.
02:32So again, moving this is adjusting it on the Z-axis.
02:37So I can also do this inside of the Properties panel.
02:40So we have a new section in the Properties panel called 3D Position and View.
02:45So inside of here, I can now adjust it on the Z-axis.
02:49Now, this is different than adjusting it on the regular X and Y-axis.
02:54So as soon as I start manipulating this with the 3D tools, I've essentially put
02:59this movie clip into 3D mode, and then to adjust the X and Y, I need to do it
03:03here in the 3D Position and View section.
03:07Okay. So let me just undo these.
03:10So we can also manipulate movie clips and display objects in 3D
03:15using ActionScript.
03:16So what I can do here is I can give this clip an instance name.
03:20I'll give an instance name of Bea.
03:22That's the name of my cat, and I already have a locked actions layer down here
03:26that we can use for our ActionScript.
03:28I'll open up the Actions panel.
03:30So now you're probably familiar with manipulating a clip.
03:34Say, I want to move it on the X-axis to bea.x = 50.
03:42Now, if I test the movie, we can see it's moved over to an X position of 50.
03:46Well, it's just as easy now to manipulate this clip in 3D space.
03:52So if I come down here and I say bea.z, if I set it to 500, we can see it's
03:59moved away from the camera by 500 pixels, making it smaller.
04:05So if I were to give a positive number for Z, it's going to push it away from us,
04:09so it's going to get smaller.
04:10If I want to bring it closer, I can actually just give a negative value.
04:14So I could say -100.
04:15Now, you can see it's gotten closer.
04:19So that's how you adjust the positioning of this object, but what about the rotation?
04:26So ordinarily, in previous versions of Flash, if you wanted to adjust rotation,
04:31you would just say Rotation = 20.
04:33Now, you can see I've rotated that movie clip by 20 degrees.
04:39Well, in Flash Player 10, you can still use Rotation for the normal type of
04:44rotation that you're used to.
04:45But we also now have it broken out into the different axises.
04:50So I can say rotationY = 30.
04:56We can see it's actually rotated that clip in 3D space along the Y-axis.
05:02So again, I can also choose rotationX.
05:06We can see it's actually rotated it along the X-axis, and rotationZ.
05:13Now it's rotated on the Z-axis.
05:16So those are the main high-level properties that you can adjust, the Z position,
05:21and using the new 3D Rotation properties to manipulate your clip in 3D space.
05:28So that's the basic overview of the new 3D capabilities.
05:33In the rest of this chapter, we're going to be going more in-depth about some of
05:36the cool new stuff that you can do.
Collapse this transcript
Building 3D animation in Flash CS4
00:01So one of the most important things about the new 3D support in Flash Player 10
00:05is that it's easy to use, particularly when you're using Flash CS4.
00:10So designers can now take advantage of 3D without having to know any
00:15ActionScript coding.
00:17So in the last video, I actually showed you a couple of the 3D tools.
00:20In this video, I'm going to show you how you would do simple 3D animation
00:24inside of Flash CS4.
00:27So go ahead and open up the 3D_ animation.fla file, and this is just a simple movie.
00:33I have a movie clip of my cat Bea here on the stage and now we're just
00:38going to create some simple 3D animation.
00:40So I'm going to grab the 3D Translation tool and I'm just going to move this
00:46closer to us on the Z-axis like that.
00:51Now I'm going to get the 3D Rotation tool and I'll just manipulate this a
00:55little bit in 3D space, maybe something like that.
01:01Now, inside of Flash CS4, the whole way in which we do animation on the
01:04timeline has changed.
01:06All we have to do now is to right-click on an object and say Create Motion Tween.
01:11So this will actually put down a seconds worth of frames here in the timeline,
01:16and everything is automatically keyframed for us.
01:18So now at frame 30, I can start manipulating this.
01:22So I'm going to get the Translation tool again, and I'm going to push it away
01:26from us in 3D space, like that.
01:30Let me grab the 3D Rotation tool again.
01:34Just change some of these properties, again, just so you can see how you would
01:38actually animate in 3D.
01:39Now we're going to hit Enter, we can see that clip is now animating in 3D.
01:45Let's give it a little more rotation, so you can kind of see it better.
01:48We can see we have a nice, smooth effect.
01:53Now, this 3D support in Flash Player 10 has actually built natively inside
01:58of the Flash Player.
01:59So this isn't an ActionScript library, like you would use if you're
02:02using Papervision3D.
02:03This is actually written in C++ and is native inside of the Flash Player.
02:09So 3D animation is just that simple.
02:12It's just like doing 2D animation.
02:14You create keyframes by manipulating the object, and we can see we can easily animate.
02:20I'm going to undo just so we get back to our initial state of our clip here.
02:26So one thing that you may want to do is to actually create something where
02:30something rotates 360 degrees.
02:33Well, there are some important things you need to keep in mind if you want to
02:36create something like that in Flash CS4.
02:39So what I'm going to do is I'm going to create a motion tween again on this object.
02:43Now, let's say I want this to rotate 360 degrees.
02:48So I can get the Rotation tool on the Y- axis and I can just start moving it around.
02:54We can see there it is at 180.
02:56I'm going to keep going until it gets to 360.
03:02So now if I actually look at that animation, we can see it's barely moving at all.
03:09That's because Flash is actually trying to be a little too smart here.
03:13It's essentially saying Hey!
03:14You started at this position. Even though you went around 360 degrees, you end
03:19up at almost the same position.
03:21So all I'm going to do is move that little bit that's different.
03:24Well, that's obviously not what we want here.
03:27That's where using the Motion Editor actually comes into play.
03:31So all I'm going to do is to select this layer and open up the Motion Editor.
03:36Again, this allows you to have a lot more fine-tuned control over your animations.
03:42So I can increase the number of frames I can see here, because I want to see
03:45my entire animation.
03:47Here you can see the Rotation Y property.
03:50If I click on that, it actually expands it.
03:52We can see why we're not getting very much rotation at all.
03:55It's only going from 0 degrees to -2 degrees.
03:59So what we actually want to do is to just come in here and put 360 degrees
04:04directly into this text input.
04:07Now, you can see our animation is actually moving all the way around 360 degrees.
04:13So if I test that, we can see we now have a nice, smooth 3D rotation.
04:20So while the Motion Editor is a great tool for doing all types of animation
04:24inside of Flash CS4, it's particularly useful and required if we're going to
04:29be doing a lot of 3D animation.
04:32So that's the basics of how to do basic 3D animation in Flash CS4.
Collapse this transcript
Implementing z-sorting
00:00So there is a very important limitation of the new 3D support in Flash Player 10.
00:07That's that we don't do any Z-sorting for you.
00:10I'll show you what I mean by that in this example.
00:13So open up the zSort.fla file.
00:16Now, this file just simply contains two movie clips, each with a different photo in it.
00:21So here I have a photo of Ryan Stuart, one of my colleagues, and then a photo
00:26of these figurines.
00:27So I just have them brought out onto the stage here.
00:30So what I'm going to do is to turn both of these into a movie clip.
00:34So I'm going to wrap them into a single movie clip.
00:36I'm just going to select them both, right-click, choose Convert to Symbol, and
00:42I'm just going to call it Con for container.
00:45I'll make the registration point in the center and click OK.
00:50Then I'm going to go to the Properties panel and also give it an instance name of Con.
00:54So now, I'm going to double-click that movie clip to go into Edit Mode.
00:59Now what I'm going to do is to position these clips in 3D space.
01:04So the first thing I'm going to do is to select that photo in the background and
01:09I'm going to put it at Z of let's say 300.
01:14So again, that's pushing it away from the camera, away from us.
01:17So now, I'm going to click on this photo on the foreground and I'll just move
01:22it back a little bit to say 100 on the Z-axis.
01:26So now, if I go back out to the root timeline and I get the 3D Rotation tool,
01:33and if I start rotating this around, we can see that right here things are
01:38looking the way they should.
01:39That photo of the figurines is in front of the other photo.
01:44But as I bring this around past 180, you can see what happens.
01:49That photo of Ryan should actually have popped in front of the figurines.
01:54So Flash isn't doing that logic for you.
01:58It's essentially just going by the order of the display list.
02:02So best case scenario, we would actually say hey, this photo of Ryan should be
02:07in front, and we change the order of the display list.
02:10But that is not actually built into Flash Player 10.
02:14So there is a workaround for doing this, but it requires using some ActionScript code.
02:20Now, inside of the Exercise Files, inside of the same folder as this FLA file,
02:26we can see we have two ActionScript classes. One is called SimpleZSorter,
02:31the other is called SimpleZSortVO.
02:34Now it's not important that you necessarily understand what's inside of these
02:37ActionScript classes.
02:39You don't have to understand them in order to use them.
02:41These are actually written by Ralph Howard who is a member on the
02:45Papervision3D team.
02:46Basically, all you have to do is just to make sure these two classes are in the
02:50same directory as your FLA file.
02:53So now I'm going to go back to our FLA.
02:56I already have a locked Actions layer here for doing my ActionScript.
02:59I'm just going to create a simple 3D animation here.
03:04So I'm going to say addEventListener and I want to respond to
03:08Event.ENTER_FRAME and I'm going to have it call a function called loop.
03:15It's not returning anything, so we're going to say void.
03:18So all I'm going to do inside of here is just to rotate this container movie clip.
03:23So I'm going to say con.rotationY, and I'm just going to say += 3.
03:31So every time it comes through this function, it's going to add 3 to
03:35the rotationY property.
03:36So now if I test it, here you can see we have our rotation.
03:41What I'm going to do is I'm going to back it up on the Z-axis a little bit so we
03:45can see this better.
03:47So I'll get the Translation tool, just push it away from us in 3D space a little bit.
03:51So now you can see there is our rotation and it's very obvious what the problem is here.
03:58So we're going to use the SimpleZSorter class to actually fix this problem.
04:03So I'm going to come back to my ActionScript code.
04:07Now, all I have to do here is, in this on ENTER_FRAME loop, is I want to call
04:12the SimpleZSorter.sortClips.
04:17This is a static function inside of the SimpleZSorter class.
04:21All you do is to pass in your container movie clip.
04:25What it's going to do is actually go through and sort all of the objects inside
04:30of them, based on their Z positions.
04:33So all I have to do is say that and now if we test the movie, we can see it's
04:38fixed that display list problem.
04:42So a very easy fix and again, this isn't requiring you to know kind of advanced
04:47ActionScript or 3D fundamentals.
04:49If you want to actually see how this is done, I definitely recommend looking
04:53inside of that SimpleZSorter class, because it's actually not a lot of code.
04:57So it's important to note that this fix, there is no current fix available if
05:01you're simply doing timeline animation.
05:04If you're doing 3D animation on the timeline and you run into this problem,
05:09you're going to have to add a frame of ActionScript that will continually call
05:14the sortClips method as your animation is happening.
Collapse this transcript
Creating an interactive 3D cube
00:01So now that we've seen an overview of the new 3D capabilities in Flash Player 10,
00:05let's look at more of a real-world example and build an interactive 3D cube.
00:11So you can open up the interactiveCube.fla file and let's quickly just
00:15look over this movie.
00:16So I don't have anything here on the stage.
00:19I have two layers here. I have an Empty Images layer and I have a locked
00:23Actions layer where we're going to actually write our ActionScript code.
00:27Inside of the library, I have six movie clips.
00:30These are just some photos I took when I used to do snowboard photography and
00:34we're going to assemble these six clips into cube.
00:39So all I'm going to do is Shift+Click to select them all and I'm just going to
00:43drag them out onto the stage.
00:45Okay, so now at this point, I could go through and start giving each of these
00:50instance names, but we don't have to do that. In ActionScript 3, we can actually
00:54programmatically access the children of a container movie clip.
00:58So I'm not even going to give them instance names.
01:01What I do want to do however is to select them all and to wrap them inside of a
01:07container movie clip.
01:08So with them selected, I'm just going to right-click, Convert to Symbol. I'm just
01:13going to call it Con for container.
01:16Again, I want the Registration point to be in the center so that when I rotate
01:20this around, it's actually going to rotate from the center.
01:22I'll click OK and then now in the Properties panel, I want to give that
01:28container an instance name also of Con. Okay.
01:32So at this point they're all just flat, sitting on top of one another.
01:35We're actually going to position them using ActionScript and then we're going
01:39to do the rotation based on your mouse position.
01:43So now I'm going to go into the Actions panel.
01:46I'm going to highlight that first keyframe, and we can begin writing our ActionScript.
01:51So the way in which we access children of a display object is there are a few
01:57methods, but we're going to use the getChildAt method.
02:00This allows us to provide an index and we can actually reference a certain clip
02:05inside of that display object.
02:07So I'm going to say con.getChildAt and now we're going to start with the first
02:13item in the display list, which again is going to be at position zero.
02:19What we're going to do is to create the left side of our cube first.
02:22So I'm going to say rotationY = 90.
02:27So that's going to rotate at 90 degrees on the Y-axis.
02:29Then I need to move it to the left, so I'm going to say con.getChildAt, position 0,
02:37and now I'm going to set the X property equal to -100.
02:43Now all of these images actually have a width and a height of 200.
02:47So here I'm saying -100, so I want to move it to the left -100 pixels.
02:53Okay. So that rotates and positions the left side of the cube.
02:59So I'm just going to copy these two lines, just to save some time, paste this in.
03:04Now we're going to access the clip at position 1 in the display list.
03:09Now, here I'm going to create the right side of the cube.
03:12So again rotationY is going to be at 90 degrees.
03:15The X position this time is now going to be +100.
03:20So again, everything is centered on the origin. The left side goes to -100,
03:25the right side to +100.
03:26So now I'm going to paste that in again.
03:30Now to create the back of the cube, I don't need to rotate this.
03:35All I need to do is to position this on the Z-axis.
03:40So this is going to be position 2 and now, I'm going to push it back away from
03:45us on the Z-axis by 100.
03:48This is going to push it 100 pixels away from us, creating the back wall of our cube.
03:53So now I'm going to keep going through here.
03:57This is going to be the item at position 3 in the display list.
04:02Now, for this one, I'm going to create the bottom of the cube.
04:04So to create the bottom, I'm going to need to set the rotationX property and
04:09I'm going to want to keep that at 90.
04:11So to create the bottom, I'm rotating it 90 degrees along the X-axis.
04:16Now, I need to offset it on the Y- axis to push it down to the bottom.
04:21So for that, I'm just going to set its Y position equal to 100.
04:26That's going to create the bottom of our cube.
04:28So now again, I'm going to paste this in.
04:31Now, we're going to create the top of our cube.
04:35This is going to be similar to the bottom.
04:37I'm going to set the rotationX property to 90 degrees.
04:41But now I actually want to position it at -100 on the Y-axis.
04:46So this is going to push it up, creating the top of the cube.
04:50So now all I need to do is to create the front of the cube.
04:55So this is very easy.
04:56Let me get rid of this.
04:58Oh and I need to actually need to make sure that I set this properly.
05:01So that's the fourth or the fifth item rather in the display list,
05:06represented by number 4 here.
05:09For the front of the cube, I'm going to need to change this to 5, since this is
05:13the sixth item in the display list.
05:16All I need to do in this case is just to change its Z position to -100, because
05:23right now it's sitting at 0 on the z-axis.
05:26All we need to do is to pull it closer to us by 100 pixels, which I'm doing here.
05:31So now if we test the movie, we can see obviously we're not going to be able to
05:36tell if our work was successful or not really, because it's kind of hard to see
05:40a cube when you're looking at it, directly face on.
05:43So now what we want to do is to actually add the interactivity.
05:47So to do that, I'm going to create an event listener and we're going to respond
05:53to the event.ENTER_FRAME event.
05:55I'm going to have that call a function called Loop.
05:59Let's create that function now.
06:00We're not returning anything.
06:03So we're going to say void.
06:04So what we want to do inside of here is again, we want to adjust the rotation of
06:10that container, based on my mouse position.
06:13So we're going to rotate it on the Y-axis, based on the X position of our mouse.
06:19So let's say con.rotationY.
06:22And what we need to do here is every time we come into this event, we're going
06:26to add a value to its current rotationY.
06:30So we're going to say +=.
06:32Now, what I want to do is to find the distance between my mouse, my mouse's X
06:37position in the center of our movie.
06:40So I'm going to wrap that inside of parentheses here.
06:44So all I need to do is to say mouseX - 275.
06:47Now, I've hard-coded in the center of my stage.
06:53So you can see here it has a width of 550.
06:57You could also use stage.stage width divided by 2, but right here, we're just
07:02going to hard-code it.
07:02It just makes it easier.
07:04So this gives us the distance between my mouse position in the center of my movie.
07:09Well, this value, if we were to add this to the rotationY, it's too large of a value.
07:14So the thing would be rotating all over the place.
07:17You probably wouldn't even be able to see what was going on.
07:20So we need to take this value and actually make it smaller.
07:22So all I'm going to do is to multiply that value by 0.1.
07:27This is just going to make it a more usable number.
07:31So let's test the movie now and we can see what we have.
07:34So now, things are looking pretty good as far as the rotation, but we have that
07:39zSort problem that I talked about in the last movie.
07:43So obviously, one of the things we're going to need to do is to call that
07:47SimpleZSorter.sortClips method.
07:51So let's do this here.
07:53So SimpleZSorter.sortClips, and again, all we do is to pass in our container that
08:01contains our 3D objects and that is named Con.
08:04So now we can test it.
08:06Now you can see we have our clips sorting properly.
08:10But here, so we can see the front, the back, the left and the right are
08:15positioned properly.
08:16Let's actually rotate it on another axis as well so we can see the bottom and the top.
08:22So I'm just going to copy this line and paste it in.
08:26Now, I'm going to rotate on the X-axis.
08:30So I'm just going to change that to rotationX.
08:33I want the rotation on the X-axis to be controlled by my mouse's Y position.
08:38So all I have to do is to change that to mouseY.
08:42The height of my movie is actually 400.
08:44So half of that is actually going to be 200 and now if we test it, you can see
08:49now I actually have full control over my cube.
08:53I'm able to rotate it on the different axises and things are
08:57positioned properly.
08:59So you can see, it's very easy to create some kind of nice, interactive 3D effects.
09:04Now all of these clips are still fully interactive.
09:08So I could click on these and respond to mouse events.
09:11So it enables you to create some really kind of interesting site navigations, or
09:16just different interactive elements.
09:19So again, that's up the basics of creating a 3D cube. The one really important thing,
09:23if you want things to look correctly, is to use the SimpleZSorter class
09:28to actually sort your clips based on their Z position.
Collapse this transcript
Working with low-level 3D properties
00:01So in addition to the high-level APIs in Flash Player 10 for 3D, there are
00:06also some new lower-level classes that allows you to have lower-level access
00:11to the 3D engine itself.
00:13And in this tutorial I am going to show you an example of when you might use
00:17these lower-level classes.
00:19So you can open up the low_level.fla file. This is just a simple movie with
00:25a movie clip of a photo of my cat.
00:28It has an instance name of bea.
00:30And what we are going to use is the Vector3D and matrix3D classes and we are
00:36going to make this movie clip actually point to wherever my mouse is.
00:41So it's going to rotate itself in 3D space, so that it's always looking at my mouse position.
00:46So I am going to go ahead and highlight the first keyframe in the Actions layer
00:50and open up the Actions panel.
00:52So the first thing I am going to do is to set up the mouse move event for the stage.
00:56So this is going to fire an event any time I move my mouse on my Flash movie.
01:01So I am going to say stage. addEventListener and this is going to be of type
01:08MouseEvent.MOUSE_MOVE.
01:12Now I am going to have that call a function called onMove.
01:15So I am going to create that function now, onMove, and the event type is
01:23MouseEvent. We are not going to return anything, so I am going to say void.
01:28Okay so the first thing that I need to create inside of here is a new instance
01:32of the Vector3D class.
01:34The Vector3D class just represents a position in 3D space.
01:39So, any object that's positioned in 3D space is going to have three position
01:43properties, the x-axis, the y-axis and the z-axis.
01:48And all Vector3D does is it encapsulates those three values to represent a
01:54position in 3D space.
01:56So the first Vector3D that I need to create is the position of my mouse.
02:02So I'm going to call that target, since it's going to be the target that our movie clip
02:07is going to be looking at, and this is going to of type Vector3D = new Vector3D.
02:14Now here I need to put in the x, y, and z positions for my mouse cursor.
02:20Now obviously a mouse cursor doesn't have a z property, so we are just going put in 0 for that.
02:26But for the x and y, I obviously want to use mouseX which represents the
02:31x-position of my mouse, then mouseY, which represents the y position of my mouse
02:38and I am going to put in 0 for the z property, which is the default anyway,
02:42but it's helpful for us to actually visualize this here and I can close that.
02:47Now I am just going to copy this line and we're going to need to create two
02:52more Vector3D objects.
02:55So let me paste this in.
02:56Now we need to create another one and this represents where our actual movie
03:02clip is looking at or where it's facing.
03:05So I am going to call this 'at' for representing where is our movie clip
03:09actually looking at.
03:11So by default a movie clip is looking at an x-position of 0, a y-position of 0
03:20and a z-position of 1.
03:23But in this case, it's actually looking towards us, so it's going to be a
03:26z-position of -1 here.
03:30So again this vector is simply representing the direction in which our
03:33movie clip is looking.
03:35So it's looking towards us which is actually negative on the z-axis.
03:41So now I am going to come create another line here.
03:44Now the next Vector3D that I need to create is a simple Vector3D that represents
03:49which axis or which direction is considered up by the movie clip.
03:55So I am going to call this up and obviously the x-axis is not considered the up
04:01axis for our movie clip.
04:04The y-axis has a value of -1, so that essentially represents the direction that
04:11our movie clip considers up.
04:13So if we go negative on the y-axis that is actually the up position for our movie clip.
04:20So now you'll notice if you change some of these values, it's just going to
04:23change the rotation of your object.
04:25So if you have a simple movie clip like this, you are going to want to put the
04:29at with the z position of -1 and the up vector with a y position of -1.
04:36Okay so now I have my three Vector3Ds here.
04:40Next thing I want to do is to actually push my movie clip away from us in 3D
04:45space a little bit along the z-axis.
04:47So I am just going to say bea.z = 50.
04:53That's just going to push it a little farther away from us on the z-axis and
04:57I will explain why you need to do that in a second.
05:00So now we've created our Vector3Ds. Now we are ready to actually position our
05:04rotate that movie clip based on my mouse position.
05:08So to do that we need to say bea.transform, so now we are actually setting
05:13the transform property on that movie clip, and we are going to set the
05:18matrix3D property, because again these three vectors are going to combine to
05:24create a matrix3D class.
05:26Now this matrix3D has a method called pointAt and this method here we actually
05:34pass in these three vectors.
05:36First is the target that we actually want to point at, then what is the
05:40direction that our movie clip is looking at and then which direction is
05:44considered up by that movie clip.
05:46So here I just simply pass in target, at and up and that's all that I need to do here.
05:53Now anytime that you are using mouse events if you want to see good performance,
05:58you should always call the e.updateAfterEvent method.
06:04So again, e is my event object here.
06:07By calling this you just basically force Flash to do another render right after
06:13this event has been called.
06:14So now if I test the movie, we can see that as I move my mouse around, that clip
06:20is always adjusting itself to basically stare at my mouse position.
06:27So pretty cool stuff, pretty easy, even though these classes are a little more
06:31low level than some of the other ones we have looked at.
06:35Now the reason why we need to actually set this in z space, if I comment out
06:39this line, you could see that we get some runtime errors.
06:44So if I come in the Output panel here, it says cannot access a property or
06:48method of a null object reference.
06:50Okay so what does that mean?
06:51Well basically movie clips inside of Flash CS4, they have different modes.
06:57So if I haven't actually positioned this clip at all using 3D properties,
07:03it's still in 2D mode.
07:05So what I need to do is I need to get this thing to get into 3D mode and then it
07:09will actually have the z property that we can set.
07:13So to set something into 3D mode, we can set any of their properties, but here we
07:18can set the z property.
07:20So basically we needed to set this in order to set this movie clip into 3D
07:25mode, and when we do that, we can now adjust these properties because from Flash
07:31perspective this is now a 3D object and not a 2D object.
07:36So there are also other APIs, lower-level APIs. Definitely look in the
07:40documentation if you want to get more involved with these lower-level classes.
07:44Generally though, you can do everything you need to do just by using
07:48the z property and rotation y, rotation x and rotation z.
Collapse this transcript
What about Papervision3D?
00:00So one of the questions that I get the most regarding this new 3D support in
00:05Flash Player 10 is if people can forget about using open-source engines like
00:11Papervision3D now and that's definitely not the case.
00:15As I mentioned earlier this new 3D support is for simple effects and transitions.
00:21Now you're welcome to push the limits of this native 3D, but for doing certain
00:26types of projects you're still going to want to use a full-blown 3D engine like Papervision.
00:31So here is one of my favorite Papervision sites, the Whitevoid site, their portfolio.
00:38And here it's got really great navigation. If I click Open, all the sections
00:43of the site kind of pop out.
00:45I can click Open to go into other sections.
00:47It has a really nice clean 3D feel to it.
00:51So something like this, you could probably accomplish using the new native 3D support.
00:56So there are situations like this where it's kind of an edge case, where you
01:00could do it in Papervision and you could probably also do it using the native 3D.
01:05So some sites though are unquestionably better suited for using something like Papervision.
01:11So the Big & Small site, which is the BBC show, this is created by Plugin Media.
01:17This is actually a full- blown immersive environment.
01:20So if I click to enter this and this actually was created using 3D models.
01:26So I can come here and zoom into this and do this little finger painting thing.
01:32I can basically go all around this house and explore this house.
01:37Now something like this, you would never want to actually do this using the native 3D.
01:42It's just not in-depth enough.
01:44So if you want to do kind of these real, real 3D environments, where you are
01:49going to be importing 3D models, adding shaders and lights, you're still going
01:54to want to use things like Papervision for those things.
01:58So it's really a matter of what type of content do you have.
02:02And again one of the main purposes of this native 3D is that it's easy for
02:06designers to use, inside of Flash CS4.
02:09If you ask a designer to go and download Papervision and start using it,
02:14it's basically not going to happen.
02:15You pretty much have to be an ActionScript developer in order to use that library.
02:21So again, you definitely going to want to know how to use things like
02:26Papervision, if you want to create these full, immersive 3D environments.
Collapse this transcript
2. Text Layout Framework
Overview of the new text features
00:00So one of the areas that Flash has never really been good at is text rendering.
00:05People have always long complained that text inside of Flash never looked quite right.
00:10It was either blurry or it was misaligned.
00:13Well this has been addressed in a big way in Flash Player 10 with the
00:17introduction of a brand new text engine.
00:19Now this is a really low-level ActionScript 3 engine for creating text.
00:25Now if you happen to know a lot about text, you can actually use this low-level
00:29API, but for most of us we are going to use what's called the Text Layout
00:33Framework, which is a set of advanced components for doing text.
00:39So to get an overview of what's possible in this new framework, we are going to
00:43come to the Adobe Labs site, if you go to
00:45labs.adobe.com/technologies/textlayout/.
00:51Basically right now this is still in beta, so once it gets finally released,
00:56this may actually end up in a different location.
00:59But here on the homepage, here on the Labs site, there is a really nice tour that
01:03essentially takes you through a lot of the new features that are in this engine.
01:07So I am just going to click Next here, and one of the big things that's been
01:11improved upon is the rendering of foreign-language text.
01:16So if you've ever had to localize or internationalize your Flash content,
01:21you know how difficult it can be.
01:22So here in this example, we have some basic English text, but we can
01:28either through this map or through this combo box, we can change it to
01:31different languages.
01:33So I can change it to a right to left language, like Arabic and we can see
01:38not only is it rendering correctly, but it's also selecting the way that it should,
01:43right to left.
01:44Now if I get even more of a complex example here, if we change to Japanese,
01:49which is not only a right to left language, but also of vertical language and
01:53we can see that the Japanese characters are all rendering nicely.
01:57But most importantly when I select these characters, it's actually selecting it vertically.
02:02It's not doing the horizontal selection that you're used to.
02:06So again, really advanced stuff when it comes to localizing your Flash content.
02:12Another big feature is the ability to have linked containers.
02:16So in tools like Illustrator or InDesign, you can have two separate text fields
02:21that are actually linked together so that when you type in one, the overflow
02:25will go to that next linked container.
02:27So here, I can select this and copy it and then come up here and paste it in and
02:36we can see the text is nicely wrapping around this M right here.
02:40But if actually show the bounds of the containers, we can see that they're
02:44actually all individual text fields that have been linked together.
02:48So if I come in now and start typing, I can see that the overflow of text
02:53actually goes throughout the linked containers.
02:58So another thing that's been greatly improved is just the ability to format text.
03:02So here I have the ability to basically re-create what I see here.
03:08So I can change the Orientation of the text of Vertical and then I can rotate
03:13this text around to 270 so that it's a nice vertical layout, and I can
03:18increase the tracking and again when I increase the tracking, it's increasing
03:22it vertically the way it should, because I've set this text field to have a Vertical layout.
03:30Another really helpful thing is multicolumn text.
03:33So this is the ability to have a single text field that's broken into multiple columns.
03:39So you can see here when I select it's actually selecting one column at a time,
03:44the way you would expect it to.
03:45And I can actually change this at runtime.
03:48So I can change the number of columns to 4, to 3, to 2, to 1, and again this is
03:54a single text field that's allowing me to do this.
03:56I can also change the way we actually display numbers.
04:01So we have the ability to change the digit case.
04:04So I can change this to old style and it essentially gives me this kind of where
04:09the 6 is a little bit higher than the 3 and the 5 and I can change this to
04:14different fonts here and you can see we have just different options for how
04:18numbers are displayed inside of your Flash movie.
04:22Now another thing that can be really important for designers are ligatures.
04:27So ligatures are essentially fancy ways of connecting certain letters together.
04:32So let me change this to Hypatia Sans Pro, so you can kind of see this better
04:38and here you can see that these two Fs and the L, they're actually connected to one another.
04:44So here are the two Fs that use a single crossbar and that second F actually
04:49turns into that L and we can see the same thing here between the C and T.
04:55So if your fonts have these kind of ligatures, you are going to be able to display
04:59them properly inside of Flash.
05:02We've always had the ability to embed images into our text in Flash, but now
05:07we have much greater control over it.
05:09So here we can see I have different images that are being dropped in here.
05:13I can change this at runtime and not only do we have the abilities do inline
05:18images but we can also do inline SWF files.
05:21So let's say I had something that was actually animated, I could put a SWF file
05:25inline here in my text content.
05:28And we also have the ability to basically change things like blend modes.
05:32I can add filters to this.
05:35Basically just like any display object I am able to fully control the look and feel.
05:40So that's an overview of what's capable with the Text Layout Framework.
05:43Now let's actually look into how we can create this inside of Flash.
Collapse this transcript
Installing the TLF library
00:00So, the first thing that you need to do in order to use the Text Layout
00:03Framework is to actually download and install it.
00:06Now, what you actually download is depending on which tool you're actually using to develop.
00:12If you're using Flex Builder to do your development, you don't want it to
00:16download the actual open source Text Layout Framework.
00:20And when you click that, it brings you to the opensource.adobe.com website.
00:25This is essentially the site we use for all of our open source technologies.
00:29So, here you can actually download the classes that you need to include in
00:33your Flex application.
00:35Now, if you happen to be using the Flex 4 beta, code named Gumbo,
00:40the Text Layout Framework is actually automatically included in the Gumbo SDK, so you
00:45don't need to download anything.
00:47But in our case, we are going to be using Flash CS4.
00:50So what we need to do is to download the extension for Flash CS4 and we can see it
00:56here in the Download pod, when I click here, it's going to ask me to
01:00agree to some terms of use, so I will check that off.
01:04And now you can see that we have the Text Layout component for Adobe Flash CS4.
01:10So, all I am going to do is just to right-click and I am just going to save
01:14this to my Desktop and click Save, and let's go the Desktop now and let me just unzip that.
01:24And if we look inside of the folder, now we can see that we have this MXP file.
01:29An MXP file is essentially just a Flash extension or component.
01:34So what you will want to do is to actually double-click that and this is now
01:38going to open the Adobe Extension Manager and this allows you to manage all of
01:43your extensions, not just for Flash but also the other Creative Suite products.
01:48So now again, it's asking me to accept the terms.
01:50I am going to click OK and now it has actually installed the Text Layout
01:55component inside of Flash.
01:57Now, it has also installed the actual ActionScript classes if you don't want to
02:01use a component and you want to do it from ActionScript and we will be taking a
02:04look at that in a little bit.
02:05So, I can close the Extension Manager now and let's go ahead and open up Flash CS4.
02:10Now, if you already had it open previously, you are going to want to restart it
02:14in order to be able to see this component inside of Flash.
02:17So, I am just going to create a new ActionScript 3 document here and I am going
02:22to Window > Components and now we can see under Standard Components, we have the
02:29Text Layout component.
02:31So, that is what you need to be able to see to know that you've actually
02:34installed it correctly.
Collapse this transcript
Using the TLF component in Flash CS4
00:00So, in the last video I showed you how to download and install the Text Layout
00:04component for Flash CS4.
00:07So, now let's take a look at how you would actually use this inside of Flash to
00:10take advantage of some of these new text features.
00:13So, I am going to create a new blank ActionScript 3 document.
00:16Now, you need to use ActionScript 3 in order to access the Text Layout Framework.
00:21So, if you're still using ActionScript 2, this is yet another reason for you to
00:26transition over to the new version of ActionScript.
00:29So, to use the component, I need to open the Components panel.
00:32So, I am just going to go to Window > Components and then under the Standard
00:36Component section, we can see the Text Layout component.
00:39So, all I have to do is to drag that onto the stage. Now this is going to create
00:44a text container that's exactly the same width and height as my stage.
00:47So, I am just going to align that component to the top and to the left, just so
00:53it fits nicely here.
00:54So, now in order to edit the properties and the text of this component, I'm going
01:00to go into Window > Other Panels and choose the Text Layout panel.
01:05So this panel allows me to essentially changed the text that's in this
01:10component and it also allows me to kind of modify the properties of how this component looks.
01:16So, if I double-click the component, we can see I am now in Edit Mode for the component.
01:21Now, I already have some Lorem Ipsum text on the clipboard that I am going to use.
01:26I am just going to paste that in.
01:27So, now I see the text inside of the Editor, but in order to see those changes
01:31on the stage, I need to click the Send to Stage button and now you can see the
01:36text has been updated here on the stage.
01:39And this component already has things like a built-in scrollbar if your text
01:42exceeds the dimensions of the component.
01:45So, now at this point I can start adjusting some of the properties.
01:50So, I can select all of the text here and let's just change the font. I will
01:54change it to a Trebuchet and again, if I want to see that, I need to click Send
01:59to Stage in order to see that text.
02:01So, now I can start using some of the new features in the Text Layout Framework.
02:06If I go through the Stack panel and if I come down to Container, here you can
02:11see I can adjust the number of columns that are in this text field.
02:14So right now, it's set to Auto, but I can change this to a certain count and
02:20let's say I change this to 2 and you can see automatically the text field has
02:25been broken into two columns.
02:28So, I will send that to the stage.
02:30Now, if I test my movie, one of the things with the Text Layout component,
02:33it takes a little while to compile, so just be aware of that.
02:37Now from here, we can see it's in two columns and but as I select,
02:41it's selecting properly.
02:42It's going one column at a time.
02:45So, all of that is built-in for you.
02:48Now, when we come back I can start fine-tuning this.
02:50So, I have my two columns, but there's no gap in between.
02:54So, you can see these essentially are butted right up against one another.
02:57So, I can come in here and adjust the spacing in between the columns and I can
03:02also choose to instead of setting a certain number, I can say make Auto columns
03:10and then it's going to be dependent on the width that I set.
03:13So let's say I want to set it to 200 pixels.
03:17It's only get a break to another column if my actual size is greater than 200.
03:22And we can see if we go through some of these other things, I could change the
03:25Orientation of this text to Vertical.
03:29So now for English language text, this is a little strange, but when we look at
03:33Japanese text in a little bit, this will obviously make a lot more sense, but
03:37we can see that the selection is happening vertically as well, which is really important.
03:42And again, I can come through, I can change Left to Right to Right to Left.
03:46Again, if you are dealing with things like Arabic or right-to-left languages.
03:50So, going through here you can see all of the different properties that are
03:54available to you with this new component.
03:58Now, this component that we are looking at right now is a very early beta build.
04:01The next version of Flash, Flash CS5, is going to have all of this stuff built into it.
04:07So, you are not going to have to download a separate component.
04:10If you want to start using it now in Flash CS4, you have to use this component
04:14or you have to do it from ActionScript which is what we are going to talk about next.
Collapse this transcript
Adding basic text
00:00So, now that you have seen how to use the Text Layout component for Flash CS4,
00:04let's look at how you would use these new text features from ActionScript,
00:09because you are going to have the most control if you use ActionScript to use
00:13this new text engine.
00:14So, to create some basic text,
00:16again, I am going to create a blank ActionScript 3 document and we are going to
00:20do everything here using ActionScript.
00:22So, we are not going to do anything on the stage here.
00:24So, I am just going to create a locked Actions layer and we will open the Actions panel.
00:29So, the first thing we need to do in order to use the classes in the Text Layout
00:34Framework is we need to actually add the component to our project.
00:39So, I am going to open up the Library here and then now I need to go to my
00:43Components panel, so I will open that up and the easiest way to do it is to
00:48simply take the Text Layout Component and drag it into the Library.
00:52Now you could drag it out onto the stage and then delete it, but it's just
00:56easier to just drag it directly into your Library panel.
01:00So, just by doing this, I now have access to all of the ActionScript 3 APIs for
01:05the new text engine.
01:07So, just like any other ActionScript libraries that you use, we first need to
01:12import the classes that we are going to use into our project.
01:15So, I am going to say Import.
01:18Now all of the Text Layout Framework is in the flashx.textLayout package.
01:25Now, the first package I need to import is the container package.
01:29I am just going to import the entire package and this package has the different
01:34types of containers that can hold your text content.
01:36So, I am just going to copy this to save time and paste it in.
01:40Now, the next package is the elements package and this contains the different
01:46elements that can hold text in the text engine.
01:50The next package is the formats package and this contains different classes that
01:56essentially handle how you are going to format your text fields.
02:00So, it includes things like character format, paragraph format.
02:04The next package we need to include is the edit package.
02:08So, the edit package has classes like SelectionManager and EditManager and
02:13this essentially sets up the different levels of interactivity that you want
02:17to have in your text field.
02:19So the last package we need to import is the actual text engine itself and
02:25that's under flash.text.engine and we are going to import all of that package
02:32just with the .* syntax.
02:35So, in order to do just basic text fields you are going to need to import at
02:39least these five packages.
02:41Now, as we go through and create this basic Hello World for the text engine,
02:46you are going to notice that this is a lot of code in order to do something very simple.
02:50Well, in this example we are going to do something simple, but you're really
02:53going to see the benefits in the later videos when we start looking at some of
02:57these more advanced features.
02:59So, the first thing I need to do here is to create a new instance of the
03:02configuration class.
03:03So, the configuration class is exactly what it sounds like.
03:07It's essentially an object that contains configuration details for your text component.
03:12So, I am going to say var. I am going to call it config.
03:15It's an instance of Configuration.
03:18Now, one thing you are going to note here is that we're not getting any code
03:22hinting for this Text Layout engine.
03:25So, inside of Flash CS4 for right now anyway, we are not going to get any code
03:30hinting for this. = new Configuration.
03:35Now, the next thing we need to create is an instance of the CharacterFormat
03:39class and this essentially sets up all the properties for how you want your text to look.
03:44Things like Color, Font Family, Kerning, all of those things.
03:49So, I am going to name this charFormat: CharacterFormat = new CharacterFormat and
04:02very much similar to CharacterFormat is the ParagraphFormat class.
04:06That sets up how you want your paragraph to look and behave.
04:10So, I am going to create one of those and I am going to call it
04:13parFormat:ParagraphFormat = new ParagraphFormat.
04:25Now, the next thing we need to do is to create an instance of the
04:28SelectionManager class.
04:30So, by default if when you create text with the Text Layout Framework, you can't
04:35select the text or edit it.
04:37So, if we want to make the text selectable, we need to create an instance of the
04:42SelectionManager class.
04:43So, I am going to do that.
04:44I'm going to call it sm for Selection Manager.
04:49 = new SelectionManager.
04:55Okay, so now that we've created kind of our configuration and our formatting classes,
04:59now we can actually start going through and use these classes to set up
05:03how we want our text field to look and behave.
05:06So, let's start with the CharacterFormat.
05:09So, I call that charFormat and what we want to do is let's first set the color
05:14and we are just going to use again the standard hexadecimal color format that
05:18ActionScript uses. So we will say 0x and then the hex color.
05:22So let's just make it red and the next thing I want to set is the Font Family.
05:30So CharacterFormat.fontFamily.
05:35And here I would just provide a string name for which font I want to use.
05:38I am going to keep it really simple right now.
05:40I am just going to use Aerial, but just like in HTML, I could say Aerial,
05:44Verdana, Helvetica and things like that, but we will just keep it simple.
05:48The next thing I want to do is to actually set the Font Size.
05:52So charFormat.fontSize, let's make it a size of 30.
05:58Now, I can adjust things like Kerning.
06:01So again, Kerning is the spacing in between individual letters.
06:05I want to say charFormat.kerning = and then we would use a constant from the Kerning class.
06:14So, we say Kerning, here we are getting a little code hinting, so you can either
06:18have it On, Off or Auto.
06:20I am just going to turn it on.
06:22Again, I'm not setting all of the properties that you have available to you;
06:25just setting a few so you can see what it looks like.
06:28And now we can set the font style as well.
06:31So charFormat.fontStyle.
06:36In order to set Italics, you would want to go to the FontPosture class and here
06:41I can set either Italic or Normal. We will just set Italic.
06:45So, now we've set up how the actual characters are going to look in this text field.
06:50Now, the next thing I can set up is by setting properties of the ParagraphFormat
06:55class and remember I created an instance of that.
06:58I called it paraFormat and what I am going to do is set the alignment.
07:02So, textAlign = TextAlign, and then now essentially I have to choose a constant
07:11from the TextAlign class and they are pretty obvious.
07:14So Left is if you want it left, Center or Right, you definitely want to look in
07:19the documentation for the Text Layout Framework if you want all the
07:23nitty-gritty details.
07:24But just to do basic left aligned text here, I am just going to
07:27say TextAlign.LEFT.
07:28Okay, so now we've set some properties first on the CharacterFormat and then on
07:33the ParagraphFormat.
07:35So, now what we I need to do is I need to tell this configuration object that I created,
07:40to use this CharacterFormat and this ParagraphFormat instance.
07:45So, to do that we come down and I call that Configuration object config and now
07:52in order to set the CharacterFormat for that,
07:54I'd say textFlowInitialCharacterFormat.
08:00So, it's probably the longest property name you ever going to have to deal with.
08:04So, essentially this is telling the configuration which CharacterFormat instance
08:09to use and I want to use that charFormat class that I created.
08:15Just so I don't have to type all of that again, I am going to copy that line
08:18and paste it in and now all I have to do is to change this to Paragraph and
08:25change this to para.
08:27So, now I have told that Configuration object which CharacterFormat and which
08:30ParagraphFormat class to use.
08:32So, now the object that we need to create that's actually going to hold our
08:36text is an instance of the TextFlow class and the TextFlow class literally just
08:42contains some text in order to display.
08:45So, I am going to come down and let's say var and I will just call it
08:50textFlow:TextFlow = new TextFlow and to the constructor of this, we actually
09:00send in that configuration object.
09:03So, it's telling that TextFlow how to configure itself.
09:07So, I send that in like that.
09:09Okay, so now that we have this, we are still not done. We can't just add this textFlow
09:14to the display list.
09:16Now, we have to actually set up the internals of this textFlow of what text we
09:20are actually going to display in there.
09:22So, inside of a textFlow object you can have paragraph elements.
09:27So a paragraph element is literally just a paragraph of text.
09:31So, I am going to create that.
09:33I am going to say var p:ParagraphElement = new ParagraphElement and now inside
09:45of a paragraph element, you can have instances of the span element.
09:50Now the span element is the element that's actually going to contain your text.
09:55So, I need to create that though.
09:56So, I am going to call it span and this is going to be span:SpanElement = new SpanElement.
10:07Now this is where I can actually set the text.
10:10So, in order to do that I would just say span.text = whatever string I want to
10:16put in the text field.
10:18So, here I am just going to put Hello World!
10:21Okay, so now I have the span and I have this paragraph.
10:24Well, now since the paragraph is made up of multiple spans, now I just need to
10:29add this span to that paragraph element and to do that I would just say
10:33p.addChild(span) and now since a textFlow can contain multiple paragraph
10:41elements, I now just need to add that paragraph element to my textFlow.
10:47So textFlow.addChild and I am going to add that paragraph.
10:53Now again, if I had multiple paragraphs I could continue adding children to the
10:57textFlow, but right now I only have one.
11:00Okay, so now I have set up everything about my component.
11:04I've set up the way the characters look, the way the paragraph looks and
11:07behaves, I have created my configuration object, I have created my actual
11:12textFlow passing in that configuration object.
11:15Now, I have created a paragraph with a single span inside of it that says Hello World!
11:20And I've added them as children to the textFlow.
11:23So, now we are ready to finally think about displaying this inside of our Flash movie.
11:27So, to do that we need to add this to some type of display object.
11:33So, I am just going to create a sprite here to display this.
11:36I will just call it sp:Sprite = new Sprite() and I am just going to set it's x
11:44and y a little bit, so it's not right up against the side of the stage.
11:47I will just set it to 200 and I will set the y also equal to 200 and now I will
11:54add this sprite to the stage using addChild.
11:58Okay, so now here is my display object that is going to hold that text.
12:02So, now in order to get that text flow into this sprite now I need to actually
12:07set a couple of other things here.
12:09So, the first thing that we need to do in order to make this text selectable and
12:13remember we created this instance of the SelectionManager class here.
12:19So, what I need to do is to actually tell the textFlow to use
12:22that SelectionManager.
12:23So, I say textFlow.interactionManager = sm.
12:31So, this is essentially saying use that SelectionManager as the interactive
12:35manager for the textFlow.
12:37So, now I want to tell the textFlow which display object to be put into.
12:42So, for that I say textFlow and then we use the FlowComposer property and
12:48this property deals with how to actually send your text out to the display world.
12:53And now I'm going to say addController.
12:57So, this is essentially where we are telling the text flow which display object to go into.
13:01Now inside of here, we create a new instance of the
13:05DisplayObjectContainerController and now into this constructor we put the
13:14display object we want to put this text into and that's the sp Sprite that I
13:19just created a minute ago.
13:20And now we can give it the width and height that we want this text field to be.
13:24I am just going to 500x200.
13:28I can close that DisplayObjectContainerController and close the
13:32addController method here. Okay.
13:35So, now at this point I have my text field added to the display list.
13:39Now, I just want to tell the text flow to update all the various containers.
13:45So, any time you make a change to this you need to update all of the containers,
13:49because this one text flow could actually be displayed in multiple display
13:53objects throughout your movie.
13:54So, I am going to say textFlow.flowComposer and then just call the
14:00updateAllContainers method.
14:04Okay, so you can see 39 lines of code just to display a text field that says Hello World!
14:10So, now obviously if you wanted to do something this simple, you would never use
14:13the Text Layout Framework.
14:15But this is kind of the basic template you need in order to get some basic text out.
14:20So, now if we test this, you can see it's going to take a second and we have our
14:25text displayed here.
14:27And it's selectable because we have that SelectionManager.
14:30Now, let's say we wanted to actually be able to edit this text, so that's
14:35really simple to do.
14:36All we have to do is instead of using a SelectionManager, we can actually use an EditManager.
14:42Now obviously an EditManager has all the capabilities of the SelectionManager
14:48but you have the ability to actually edit the text as well.
14:51So, now inside of here you can see I can actually edit the text and now it's an
14:56editable text field.
14:57So again, this is a lot of code to do something really simple but in the next videos
15:01we will look at how to take this code and take advantage of some of the
15:05more advanced features of the Text Layout Framework.
Collapse this transcript
Vertical and RTL international text
00:00So in the last video I showed you how you can create simple Hello World text
00:05field using the Text Layout Framework.
00:07Now this was a lot of code to write just to do some simple text display.
00:12Well, now let's look at how we can expand on that to look at some of the more
00:15advanced features in the framework.
00:17So we are going to start with the same file that we finished with in the
00:21last tutorial, and I already have that for you in the Exercise Files called basicText.fla.
00:27So you want to open that up.
00:28If we look in here, it's the same exact code that we did in the last tutorial.
00:33So let's just take a look at what that looks like.
00:35So when it exports, we just simply have an editable text field here with
00:40the text Hello World.
00:41So now we are going to look at how we can actually display languages like
00:45Japanese that are right to left languages in addition to being vertical.
00:50So they are actually displayed in vertical columns rather than in
00:53horizontal columns.
00:56So let's come into our code here.
00:58Now the first thing we need to do is we're going to need to use a font that
01:01actually has the Japanese characters in it.
01:04Now you could use any font you want here, but a font that everybody has on
01:08their system is Arial Unicode MS and this font contains all of the glyphs
01:15needed to display Japanese.
01:18So let's change some of these properties.
01:20I am going to change this to Black.
01:22I am going to reduce the font size a little bit.
01:25We're going to remove Italics.
01:26I don't want this to be Italics text.
01:29And now what we need to do is we need to start to configure this text flow so
01:34that it will properly display the Japanese characters.
01:37So under my charFormat here, what I am going to do is to come under here and now
01:43I need to create a new instance of the container format class.
01:47So very much similar to the character format and paragraph format.
01:51The container format class allows me to format how my container is going to look and behave.
01:56So I am going to say var, I am just going to call it contFormat, and that's of
02:02type ContainerFormat = new Container Format.
02:09Now, to the constructor here we need to pass in the current container format for our textFlow.
02:15Well, in the last example we didn't create our text Flow until we were down here.
02:20So what I am going to do is I am going to move these lines up, like that, just
02:25above the declaration for this container format.
02:28So that way our textFlow already have been configured. Okay.
02:31So now to pass in to the constructor of this container format I am simply going
02:36to say textFlow.container format.
02:42Again that's passing in whatever the current container format is for my textFlow.
02:47So now we can come down here and we can see where I am setting the properties of
02:51my paragraph format.
02:52We have paraFormat.textAlign, TextAlign.LEFT, we can leave that.
02:57But now we want to add some more properties. So paraFormat.
03:02Now we want to set the Direction property, and for the Direction property we are
03:07going to say Direction.LTR.
03:12Now another paragraph format property we are going to need to set is
03:16paraFormat.justificationRule.
03:21So this controls how our text is actually justified.
03:24Now the default actually uses the standard justification for Latin languages.
03:29We need to give the justification rule for East Asian languages since we are
03:34dealing with Japanese.
03:35So I am going to say justificationRule, and we want to choose EAST_ASIAN.
03:43Now it's telling it to use the proper type of justification for East Asian languages.
03:49One of the things actually now that I look back we should have changed,
03:51this text align shouldn't actually be TextAlign.LEFT.
03:55This should be TextAlign.JUSTIFY because we want the text to be justified,
04:01not left aligned here.
04:02Now what we want to do is set the text align last property.
04:07So again this is going to be paraFormat.textAlignLast, and now this is
04:14essentially going to be the actual last line, how is it going to be aligned.
04:18And for this we want to say TextAlign.START.
04:24It's going to align it to the start.
04:25Okay, so now what we need to do is we need to set the block progression property
04:32of our container format and this is going to basically control how columns of
04:37text are going to be laid out.
04:39So the normal way in which we display Latin columns is obviously left to right,
04:44but this is a vertical language.
04:45So it's actually going to be right to left.
04:47So I am going to come here and we are going to say contFormat and then we want
04:53to set the blockProgression property = BlockProgression.RL.
05:03Now since we've manipulated this contFormat, I simply need to now apply that to my text flow.
05:09So textFlow.containerFormat = contFormat.
05:17And now here we create our paragraph element and our span element.
05:21Now we need to put in some actual Japanese characters.
05:23So I actually have some Japanese characters on the clipboard, so I am just
05:27going to paste those in, and you could also put in Unicode characters here if you wanted.
05:34But now I have basically some Japanese text that's going to go into that text field.
05:38Okay, so now if we actually test it, we can see how this is going to look.
05:43Once it launches up, we can see I need to do a little adjustment to how my
05:47actual sprite here is positioned.
05:50So I am not going to move it on the x-axis and I'll just move this over by 30 on the y-axis.
05:57For the actual size of my container, I am just going to make it 375 wide by 350 tall.
06:06Now we can test it and we should see our Japanese text displaying properly.
06:10So now you can see we have it displaying vertically.
06:13When I select it's actually selecting vertically, the way it should, and things
06:18looking pretty good.
06:19So still little bit cut off here, so let me set the X property to set it to 100
06:25so we can see it better.
06:27So now remember this is an actual editable text field as well.
06:30So it's selecting the way it should vertically, but I can come in here and as I
06:34start typing, we can see that it's typing vertically and everything is flowing
06:39over to the next column vertically, and you can see what's happening to the
06:43regular Latin text. It's displaying sideways.
06:46So obviously you could do this if you wanted to do some kind of funky text
06:49fields in English text, but generally speaking if you want to do kind of a
06:53vertical right to left languages, this is the way you do it.
06:56And again doing this in previous versions of Flash took an immense amount of
07:01custom ActionScript code in order to accomplish.
Collapse this transcript
Advanced ligature support
00:01So one area of the Text Layout Framework that's really going to make designers
00:04happy is the support for advanced ligatures.
00:08And again ligatures are just special ways in which certain letters are
00:13connected in the font.
00:14So when a type designer creates a font, sometimes he'll create a special
00:18character for when two characters are next to one another.
00:23So again I am going to be starting with that basicText.fla file from the
00:27Exercise Files, and again this is just the basic Hello World example that I'll
00:32run here and it just says Hello World! in red text.
00:36So I am going to change a couple of things here.
00:38I am just going to change that to black text.
00:42I am going to make the text quite a bit larger.
00:44So I'll make it 60. I'll get rid of the Italics.
00:49So now in order to see these advanced ligatures, you need to make sure you are
00:54using a font that actually has these ligatures in them.
00:57Well, one of the fonts that actually comes with Creative Suite is called Adobe
01:01Caslon Pro and it has a lot of nice ligatures in them.
01:05So for Font Family, I am going to change this to Adobe Caslon Pro.
01:10And now if I want to enable these kind of fancy ligatures, it's just another
01:15property I need to set on the character format class.
01:18So I am going to say charFormat, and the property is called ligatureLevel, and
01:25now you need to set that equal to a constant from the ligatureLevel class.
01:30So ligatureLevel and you can choose to not display ligatures, None, Minimum,
01:40Uncommon, or Exotic.
01:43Now you're going to need to actually look at the glyphs and your different fonts
01:47to choose which level you want to use.
01:49I am going to choose Exotic just because it has some really kind of dramatic
01:53ligatures that you can really tell.
01:55So here now I've set this ligature level.
01:58Now in the actual text field, I need to pick a couple of letters that actually
02:03have ligatures connecting them.
02:05So one of them that is always usually in fonts is FFL.
02:10So anytime you have the characters FFL together, I mean in a lot of these fonts,
02:14there is kind of fancy ways in which to draw those three characters.
02:18So I am just going to write, 'I like waffles', just because it actually has an FF and L in it.
02:27Let's go ahead and test that.
02:30We should see that this is actually using an exotic ligature.
02:35So this is kind of drawn as a single character, where there is a single
02:39crossbar for both the Fs.
02:41The top of this first F connects with the second F, which connects with the L character.
02:47Now another thing we can do is since this is an editable text field, I can
02:51just type right in here.
02:53So also when you connect a C and a T together, so let's say I type 'fact.'
02:58You can see as soon as I type that, we now have this fancy way of connecting the C and the T.
03:04Here's the normal C, which if I just type characters you see there, but as soon
03:08as I type the T, Flash has recognized there is an exotic ligature for connecting
03:14the C and the T and it's displayed here.
03:18So we can look at some of the different ligature levels.
03:20So let's say a Minimum.
03:23We can see what that is going to look like.
03:25Again, different fonts are going to have different kind of levels of ligatures.
03:29So here you can see it's a lot less dramatic effect.
03:33This first F is separate.
03:34It's just connecting the second F with the L. And when I do CT now, it's
03:41not showing anything, because again this is just kind of a minimum level of ligatures.
03:46So it's important if you want to use these ligatures to actually look through
03:50the glyphs, and whatever font you are going to use to determine which
03:53ligature level to select.
Collapse this transcript
Multicolumn text
00:01So another advanced feature of the Text Layout Framework is the ability to
00:04easily create multicolumn text in your text fields and this is really important
00:10if you have a lot of text, you are trying to reproduce more of a newspaper or
00:15the feel of a magazine.
00:16Well it's really easy to add that into your text fields using the framework.
00:22So again, we are going to be starting with that basicText.fla file.
00:26Let's go ahead and open up that ActionScript.
00:29Again, we've used this a few times now. It basically just adds a text field
00:33that says Hello World!
00:34So now we are going to make some modifications to this.
00:38So first, I actually have some text that I just copied out of the Flash Help files.
00:42I am just going to paste that in just so we have some text that we can work with here.
00:47So now I am going to come up to the charFormat class.
00:49I am just going to change that text to Black.
00:53I can leave the font at Arial. That's fine.
00:56I am going to make the font a little bit smaller.
00:59So let's say maybe 18.
01:01I want to get rid of the Italics.
01:04Okay, so now, what I want to do is since I have a lot of text, I want to
01:07increase the size of my text component.
01:09So all I am going to do for the container Sprite, I am just going to offset it
01:13by 10 pixels on that X and 10 pixels on the Y and now I am going to make my text
01:19component basically fill up the rest of my stage.
01:23So my stage is 550. So -20 from that.
01:27So I am going to make it 530 and here, the height of my stage is actually 400.
01:34So I am just going to subtract 20 from that and I am just going to make it 380.
01:38Okay, so now let's test it just so we can see what it looks like with all that text.
01:46Here you can see the text in a single column.
01:49So now we want to break this up into multiple columns.
01:53So first, let me go through.
01:55That font size is a little bit big.
01:57Let's change it to 14.
01:59So now what I want to do is come down here after where I add my paragraph to
02:05the textFlow and what I want to do is to set the columnCount property of my textFlow.
02:11So all I have to do is say textFlow. columnCount and this just expects a number
02:18for how many columns I want to display.
02:21So I can say 2 and we'll test it and now we should have our text content broken
02:26into two columns and you can see it's selecting properly down the first column first,
02:31and then up to the second column.
02:33So really, it's just that simple once you have the basic template to
02:38create multicolumn text.
02:40Now there was no space in between those columns.
02:43So what I can do now is to come down and let's come under here and we can set
02:49textFlow.columnGap and this is essentially the gap in between the columns.
02:57So let's say I make that 15.
02:59We should now see a 15-pixel gap in between those two columns.
03:04Again, I can keep going through here. I can adjust the column gap.
03:08Let's say I wanted to turn this into four columns. I could do that.
03:13You can also again at runtime, if you respond to the stage resize event, you can
03:19adjust any of these runtime as somebody is using your application.
03:24So once you have the initial code here from our basicText.fla, it's really easy
03:30to go ahead now and to start breaking it up into different columns to adjust
03:34the layout of your text.
Collapse this transcript
3. Pixel Bender
Overview of Pixel Bender
00:00So when we've released Flash 8, Adobe included some basic filters and effects.
00:05So these were things like Blurs, Drop Shadows and Bevels.
00:09But with Flash Player 10, we've introduced a brand-new technology called Pixel Bender.
00:14Now this is a combination between a new programming language, the Pixel Bender
00:18programming language, and a new IDE for creating pixel bender filters.
00:23And what you do is once you create your filters, you can actually use them
00:27inside of Flash just like you use things like Drop Shadow, Bevel and Blur.
00:32So here I am in just a simple Pixel Bender viewer just to help visualize some of
00:37the things that you can do with Pixel Bender.
00:39So here I have just a simple image and I can choose from some of these basic filters.
00:44So I am going to choose this Crystallize filter.
00:47You can see I have a parameter here called size and when I adjust this slider,
00:52you can see that it's actually crystallizing that image.
00:55The further I go with the slider the bigger the crystals actually are.
00:59So this was actually written in Pixel Bender and incorporated into Flash.
01:04So this enables you to do all types of different bitmap effects. You can
01:09generate purely generative artwork using Pixel Bender, and the range of things
01:15that are possible are really amazing.
01:17So let me show you a couple more of these. Here is a Spherize one, that
01:21essentially creates a bulge.
01:24So I can adjust some of these parameters.
01:27When you're in Pixel Bender, you can set certain properties to be external
01:31parameters, so that when you're inside of your Flash movie at runtime, you can
01:36manipulate these and they get some pretty crazy effects.
01:40Here is this Tube View that if I center it, basically it creates this tunnel
01:44effect, drop the radius down a little bit, and you can see all of these things
01:49can be animated at runtime to create some really cool effects.
01:52So I can come and adjust the turbulence, which is essentially how much twist is
01:57actually in this effect.
01:59Now the really cool thing is that since we can apply Pixel Bender filters to
02:04any display objects, we can also apply them to vector animations. So here is a
02:10vector animation with that filter applied, and of course, we can also apply it to video.
02:16So here is actual video file with this filter running on and you can see it's
02:21just as easy to apply these effects to video as it is to any other display
02:26object in your Flash movie.
02:29So again, the main thing you're going to need to download, I talked about this
02:33earlier, is the Pixel Bender Toolkit.
02:36And once you have that installed, the place to get that is on the Adobe Labs site.
02:41So if you go to labs.adobe.com/ technologies/pixelbender and then come down in
02:48the Download pod and it says get the Pixel Bender Toolkit, and from there you
02:52just download either to the Mac version or the Windows version,= and install it.
02:57So once you have that set up, in the next video, we'll look at how to create a
03:01very simple Pixel Bender filter using the Pixel Bender Toolkit.
Collapse this transcript
Creating your first filter
00:00So now that you've downloaded and installed the Pixel Bender Toolkit, let's look
00:04at how you can create the simplest possible Pixel Bender filter.
00:08So when you launch the tool, this is what you'll see.
00:11So now this tool, again, it's still on the Adobe Labs site.
00:14So it's still being worked on, but essentially, we can take a quick tour of the UI.
00:18This blank section up here is essentially where you're going to import an image,
00:23so that as you're writing your filter, you can see how it affects this image.
00:27The actual code editor is down here under that.
00:30Now in the right-hand side, this panel here is used for a couple of different things.
00:34First, if you create any parameters in your Pixel Bender filter, you'll actually
00:39see a UI develop here.
00:41So you'll actually see a slider that allows you to manipulate that parameter.
00:46If you have any errors in your code, you'll also see that printed out here in this panel.
00:52Now, many people when they start developing for Pixel Bender have a hard time
00:56kind of finding the help and documentation.
00:58Well, it's actually located right here in the Help menu, and there is two PDFs.
01:03One is the Language Specification and one is a Developer Guide and this
01:07is essentially the best place for you to come to get documentation about Pixel Bender.
01:12So the first you're going to want to do when you're creating a filter is you
01:16want to load an image in here so as you're writing it, you can actually see how
01:20this Pixel Bender filter is affecting it.
01:22So I am going to go to File and then choose Load Image 1.
01:27Now when you install Pixel Bender, it installs a bunch of sample images for you
01:31that you can use.
01:32So I am just going to choose this YellowFlowers.png file.
01:37So now I have an image here inside of the Toolkit.
01:40Now I need to create a new filter.
01:42Inside of Pixel Bender, these are actually known as kernels.
01:46So you just basically exchange the word kernel for filter while you're
01:50inside of the Toolkit.
01:51So we can see here 'Create a new kernel,' so I am going to click that and
01:55basically what it's done is it's put in essentially what is the simplest
02:00possible Pixel Bender filter there is and it basically has no effect on the image at all.
02:06One of things to know when you start getting into this is this is
02:09not ActionScript 3.
02:11This is using the Pixel Bender language.
02:14So this is based off of other pixel shader languages that are out there.
02:18So if you have experience with writing pixel shaders, this is going to look
02:22very familiar to you.
02:23If you've only done ActionScript before, this is going to be considerably
02:26different than doing ActionScript code.
02:29So the text editor in here is pretty bare bones.
02:32You don't really have code hinting.
02:34We do have color coding in here, we can adjust things, if we go into the Preferences.
02:39I can go into Editor, and I can change the font.
02:43So maybe I want to bump that font up a little bit.
02:46You can add in your vendor, your namespace.
02:49So here is essentially the simplest filter and if we come down here, we can see
02:55that there is an input and then there is an output.
02:58So the input is whatever image you want to manipulate.
03:02So here, we have this image called YellowFlowers.png. That's the input to this filter.
03:08So the way a Pixel Bender filter works is it goes through every pixel in the
03:13image one-by-one and for each of those pixels, it calls this
03:17evaluatePixel() function.
03:19Now this function does exactly what it says you need to evaluate that current pixel
03:24and just determine a new output value for that pixel.
03:28Now how you come up with the new output value, that's where all the
03:33creativity comes in.
03:34But essentially for every pixel in this images, it's going to call
03:37evaluatePixel() and ask me to provide a new value for that pixel, and that new
03:43value is put into this output variable which is called dst for destination.
03:50So we're going to create a very simple filter that's going take an image and
03:53basically make a grayscale version of it.
03:56So with the top, we have the languageVersion, this is just the version of the
04:00Pixel Bender language that we're using.
04:02The kernel here, this is where we give it the name.
04:05So I am just going to call it Grayscale and then we see a section of metadata.
04:10So this is essentially where you can put, if you have a lot of filters and you
04:14need namespaces, you can put it a namespace, vendor.
04:18I could put in Adobe here, description, turns an image into grayscale.
04:23I am just going to leave everything at the default, but this is essentially just
04:25metadata for your Pixel Bender filter.
04:28So again, here are the two variables that are defined:
04:32the input, which is of type image4 which means it's an image that has four
04:36channels, alpha, red, green, and blue, and then the output is a pixel4.
04:42So a single pixel that has four channels:
04:45alpha, red, green and blue.
04:47So now inside of this evaluatePixel(), we can see that we're setting the
04:52destination or the output value for that pixel equal to the result of this
04:57sampleNearest function.
04:59So what the sampleNearest function does is you provide first which image do you
05:05want to sample from, and then the coordinate of what pixel you want to sample.
05:11So this coordinate needs to be two values, one for X and one for Y.
05:16Now if you want to get the X and Y position of the current pixel that
05:21we are dealing with in the evaluatePixel() function, you can use this
05:24outCoord() function.
05:26So all this is essentially saying, this line, is whatever the value of the input
05:31pixel is, just send that directly out to the destination without modifying it.
05:36So now, if we want to test this Pixel Bender filter, I can just click Run
05:41and it's now running.
05:42So you can see it says "The filter is running." I didn't get any errors up here.
05:46But of course, nothing is actually changed in this image because I haven't done
05:50anything different to the pixel.
05:53So now what I want to do is I want to start adjusting the channels of that pixel.
06:00So grayscale image is an image where each of the channels is the same value.
06:05So you have a single number for the red, green, and blue channels.
06:10So this dst, after this line here contains the current value for the pixel.
06:15Now I can just start manipulating it.
06:17So I can say dst.r, which gives me the r channel for that pixel, is equal to
06:25dst.g is equal to dst.b and now we can set them all equal to the same value.
06:35And so what I can do is I can set them all equal to say the red channel.
06:40So all of those are equal to dst.r and now when we run it, we can see all of the
06:47channels inside of that pixel now have the same value and the value is the value
06:52that was in the red channel.
06:53So now I could change this to g, and we can see we have a different look to
06:57that grayscale image.
06:59I can change this to b to see what the blue channel would look like but
07:03ordinarily, if you want to do just a standard grayscale, you want to take an
07:07average of all three pixels and use that for each of the channel values.
07:12So to do that, all I have to do is to set these three equal to, then in
07:17parenthesis, I am going to say dst.r plus dst.g plus dst.b and when I add those
07:28altogether, now I want to divide that by 3.
07:32Now this is going to give me an error but I just want to-- I'll put in some
07:37spaces so it's easier to see here.
07:40So now I am dividing those by 3, but now if I run it, we can see I get an error
07:45and that's because inside of Pixel Bender, we're dealing with float values.
07:50So floats are essentially floating point numbers, numbers that can have decimal
07:55point with a certain number of precision numbers after that.
07:59So right here, a pixel4 value is made up of four floats.
08:04What's happened is I have these values here and I am dividing by 3.
08:08So to Pixel Bender, 3 is not a float.
08:113 is just an integer.
08:13So in order to make that float, I need to actually put on the .0.
08:18So Pixel Bender is not going to be smart enough to know, okay, 3 is actually
08:233.0 so it is a float.
08:25I need to explicitly put in that .0.
08:28And now when we run this, we can see we now have a traditional grayscale image
08:32where each value in the pixel is an average of all 3.
08:38So now I can come through and let's say I wanted to say dst.r. Let's do times
08:44equal 2.0 and run this.
08:49We can see now we're actually doubling the red channel inside of here.
08:53We are doubling the value because we multiplied it by 2.
08:56But basically, this is the simplest type of filter you can create.
08:59You take the current value of the pixel and manipulate it in some way to create
09:05a new output value for that pixel.
09:07In the next tutorial, we'll look at creating a more complex filter that actually
09:10has some settable parameters.
Collapse this transcript
Creating a waterfall filter
00:00So, now that you have seen how to create a really simple filter in Pixel Bender,
00:04let's take a look at a little more in-depth example.
00:07I am going to start the same way.
00:08I am going to first load in an image and I am going to choose that
00:11YellowFlowers.png file again.
00:13Then we'll go ahead and create a new kernel.
00:16So what we are going to create in this example is kind of a classic effect
00:21called Waterfall and essentially it's going to streak the pixels along the
00:27Y-axis based on the amount of a parameter that we are to create.
00:33So for the name of the filter, I am just going to call it waterfall.
00:37Again I am going to leave the metadata just at the default values here and then
00:42come down to our evaluatePixel function.
00:45So what I first want to do is I want to store the coordinates of whatever
00:50current pixel that we are dealing with.
00:52So I am going to get rid of this.
00:53I am going to create a float2 variable called pos for position.
00:59So remember, position has two values.
01:02It has an x and a y, so we need to store it in a float2 data type.
01:06So I am going to set that equal to that outCoord function and again the
01:11outCoord function returns to us the x and y value of the current pixel that we are working with.
01:17So now that I have the position, what I need to do now is I want to test if the
01:23current position is greater than a certain value on the Y-axis.
01:28So I am going to say if pos.y is greater than and for right now, I am just
01:36going to hard code a number in here. I am going to say 200.0 and remember we
01:41have to put in that 0.0, so we tell Pixel Bender that this is actually a
01:45floating point value.
01:48So, if the y position is greater than 200, we are going to set the destination
01:54or the output value equal to and again we are going to use the sampleNearest
02:00function and the first parameter is which image we want to use, obviously we
02:05want to use the source image.
02:08Now we want to provide an x and y position which pixel we want to sample.
02:13So I am going to create a float2 here and for the x position, I want to always
02:19keep the x position of the current pixel.
02:22So I am just going to say pos.x. Now for the y position, if the y position is
02:29greater than 200, I just want to use the pixel value
02:34that's at 200 and that's essentially going to cause a streak vertically.
02:38Now I am going to say 200.0 and now I can close that.
02:43So, now we need to create the else block, so I am just going to copy the if,
02:48paste it in and I just have to change this to else and now for the else block,
02:54I don't want to do anything special.
02:55I just want to do the normal thing where I just pass out the input pixel value.
03:00So I can just pass in pos because that has the current coordinates for this pixel.
03:05So now if we run this, we can see that on the Y-axis, it's now actually
03:12streaking after it gets to 200.
03:15So while this might be kind of a cool effect, obviously we want to be able to
03:19make it so that we can adjust that value.
03:22We don't always want it to be hard coded at 200 because then we are not going to
03:27be able to adjust it. We are not going to be able to animate it.
03:29So here is where creating parameters comes in.
03:31So I am going to come up here under these two variable declarations and
03:36I'm going to create a new parameter.
03:40So I say parameter and then I need to give the type that this parameter is going
03:44to be, this is going to be of type float, and I am going to call it amount,
03:48because it's going to hold the amount that we want to streak.
03:52So we use a special syntax for this.
03:55We open with angle brackets and close and use a semicolon.
04:00Now inside of here we provide three properties: a min value, a max value and a default value.
04:08So I say min value and then I give what I want the minimum value of this to be.
04:14So I am going to say 0.0 and for max value I just want to use the height of the
04:22image which we can see up here is 375.
04:26So 375.0 and for default value, I am just going to make the default be at 0.0.
04:35So, now I have created this parameter. If we run this now, we can see what's
04:41happened when I run it.
04:42It's actually created a slider for me that's set up to go from 0 to 375.
04:48so this is going to allow me to actually test this inside of the Toolkit.
04:53So now all we need to do is take this parameter value and replace this 200 with
04:59that value, called amount.
05:05Now when we run it,
05:06you can see when I start at 0, this is essentially nothing. We are sampling a pixel at 0.
05:11But as I move this now, you can see that it's kind of streaking down and
05:17this could be kind of good for doing transitions between different things.
05:20We can imagine an image viewer that transition using this waterfall filter.
05:25But this just shows you how you can externalize certain values and then once we
05:30get over to Flash, we are actually going to be able to at runtime adjust the
05:34amount property to create animations.
05:38So this is an example of a slightly more complex filter.
05:42In the next tutorial, I am going to show you how you can actually take this
05:45filter now and export it for use in the Flash Player.
05:49But first go ahead and save this.
05:51So we are going to choose Save Filter As and I am just going to save this to the
05:55desktop as waterfall.pbk.
06:00So pbk is the actual source file for your Pixel Bender filters.
06:05In the next tutorial we are actually going to export a pbj file, which is
06:09the binary format that Flash expects when you want to incorporate them into the Flash Player.
06:15So, I am just going to save that and in the next tutorial, we will
06:18incorporate this into Flash.
Collapse this transcript
Exporting and using filters in Flash
00:00So, in the last tutorial we created this simple Waterfall filter here in the
00:04Pixel Bender Toolkit where we essentially can adjust this parameter to cause
00:10this streaking effect in the photo and we export it or saved this filter just
00:16to the desktop as waterfall.pbk.
00:19Again the pbk format is your source format where you actually will be
00:24storing your source code.
00:25So now what we need to do if we want to use this inside of the Flash Player is
00:29we need to export it as a pbj file and that is the byte code file that Flash can actually read.
00:36So to do that I am going to go to File and then Export Filter for Flash Player.
00:42So when I do that it's asking me where I want to save it.
00:45I am going to save it also to the desktop, and you can see it's going to save it
00:49as a Pixel Bender Byte Code file.
00:52So it's important to know that not all of the features in Pixel Bender are
00:56supported by the Flash Player.
00:58One of the things that's not supported is loops, so I couldn't come down here
01:03and create a For loop inside of here.
01:05If I did that it would actually give me a warning when I try to export
01:09the filter for Flash.
01:10Now remember, Pixel Bender filters can also be used in Photoshop and After Effects.
01:16Now, in those tools you have the full capabilities of the Pixel Bender
01:20language available to you.
01:21So now if we look on the desktop we have our pbk which is our source file and
01:26the pbj which is the file that we are going to incorporate into Flash.
01:30So I am going to go on to Flash CS4 and you are going to want to open up the
01:34waterTest.fla file and what I am going to do is I am going to save this to the
01:40desktop, just so that it makes it easy for me, because I want it to be in the
01:44same directory as my Pixel Bender file.
01:46We will just take a real quick look at this.
01:50This is basically just a movie clip of an image.
01:53Again this is the same image that we were using in the Pixel Bender Toolkit and
01:57this has an instance name of image here.
01:59So now what we are going to do is using ActionScript we are going to import that
02:05pbj file and actually apply it to this image.
02:08So now it's important to note that Pixel Bender Filters are not available via
02:14the Filters panel here.
02:15So if you wanted to add a standard Flash filter like a Bevel or Glow, we can do
02:20it here using this UI.
02:22Pixel Bender filters need to actually be embedded using ActionScript.
02:26So I am going to highlight the first keyframe of the Actions layer and open
02:30up the Actions panel.
02:31So now there is a couple of different things you can do here.
02:35You can actually load in Pixel Bender files at runtime using the URLLoader class.
02:41But most of the time you are going to want to actually embed the Pixel
02:45Bender filter into your SWF file, and to do that we use the Flex Metadata tag to do that.
02:52We will use the embed tag that actually comes from the Flex framework.
02:56So this is a new feature in Flash CS4 that allows you to take advantage of some
03:01of the Flex framework features and actually compile using the Flex SDK.
03:06So the syntax for that embed tag is you start with a square bracket and then we
03:12say embed and then in parenthesis, we put source =, and now the path to our
03:20actual pbj file, which is in the same directory and it's just waterfall.pbj.
03:26The next thing we have to set is the mimeType. Essentially we need to explicitly
03:32set the mimeType to an octet stream, which is essentially just a binary stream.
03:38So to do that, I am going to say mimeType="application/octet-stream". Now I can
03:54close the parenthesis and close the square brackets.
03:57So now this will actually embed the pbj file into my SWF, but I need to provide
04:02a class that will actually hold that.
04:05So, if I want to use this pbj file, I need to assign a class to it.
04:09So to do that right under here, I am going to give it a class. I am just going
04:13to call this pbj and it needs to be of type class.
04:18So again all this is doing is doing is it's taking that pbj file, embedding it
04:22into my SWF and giving it a name of pbj.
04:25Now if I want to use that filter, I just use the name pbj.
04:29Okay so in order to use this what I first now need to do is to create an
04:33instance of the Shader class.
04:35So I am going to save var and I am going to call it shader and I want to data
04:41type it to Shader, is equal to new Shader and now inside of here you can see it's actually
04:48expecting a ByteArray.
04:50So, that pbj file that we embedded is actually a ByteArray.
04:54So all I have to say is new pbj, so I am creating a new instance of that pbj
05:00class which holds my external file.
05:02Now I just need to cast this to a ByteArray, so I'm going to say as ByteArray.
05:07So now I have my Shader object created.
05:12Now what I can do is I can start to adjust the value of that amount parameter
05:17that we created in the Pixel Bender Toolkit.
05:20So to do that we say Shader and now we want to go to the data property, which
05:26holds all of my parameters. I only had one in that file and that was called
05:30amount and then I want to set its value =, and I will just hard code for right now, to 100.
05:38So when you're setting values on a parameter you always need to pass it in as an array.
05:44So even though I have one value here, I still need to pass it in square
05:48brackets as an array.
05:50Now this is of course because a parameter can have multiple values. If I were to
05:54set a float2, I would actually send in two values to this.
05:58Okay, so now that I've created my Shader and have adjusted the value of the parameter,
06:03now I want to apply it to my image as a filter.
06:08So to do that I need to create a new Shader filter based off of that Shader.
06:12So I am going to say var filter: ShaderFilter = new ShaderFilter and now I will
06:24simply just pass in that shader object.
06:26So now the shaderFilter can be treated just like Blurs, Drop Shadows and Bevels.
06:33So that image on the stage has an instance name of image, so I just set the
06:38filters property equal to an array of the filters that I want to set and I just
06:43want to set this filter to my filters array.
06:48So if we test this now, we can see that it's now working. So it's actually going
06:52to streak that value starting at a hundred pixels.
06:57So what if we wanted to make this a little more interactive?
06:59Well actually I can make this follow my mouse position.
07:03So to do that I'm going to create an event listener on my image.
07:08So image.addEventListener and I want to listen for MouseEvent.Mouse_Move.
07:18So anytime I move my mouse I want to adjust the amount parameter in that shader.
07:23So let me create this now, function onMove, event type is MouseEvent and
07:31not returning anything.
07:34So this line now could be moved into the onMove event and now what I need to do
07:39is every time I move my mouse I want to a just this value.
07:44So let me bring this now down here.
07:48So what I want to set the value of this too is the Y position of my mouse.
07:55So I want to say image.mouseY.
07:57Since this is a mouse event in order to get a good response of action, I am
08:05going to say e.updateAfterEvent.
08:10So let's test this now and now you can see we have a nice action on here
08:16and actually let me change this to just regular mouseY. There we go.
08:23So now it's actually following my mouse.
08:25So, we can see now we have a Pixel Bender filter, we have it imported and
08:29we have it applied to our image and I can animate it or interact with it,
08:34the same exact way that I do with filters, Blurs, Drop Shadows and all those
08:38standard Flash effects.
Collapse this transcript
Creating blend modes
00:00So not only can you create new filters for Flash using Pixel Bender, but you can
00:05also create new blend modes.
00:07I am going to show you how to do that in this tutorial.
00:10So from the Pixel Bender Toolkit, we want to do the same thing we did last time.
00:14We want to load in our image so I am going to choose this YellowFlowers.png.
00:19But now since this is the blend mode, we also want to bring in another image so
00:24that I can see how the blend mode looks when that has something underneath it,
00:29because that's essentially what blend modes are.
00:31It determines how something is going to blend into its background.
00:34So now I am going to load an Image 2 and now I can choose a different image to import.
00:41I am just going to choose his Canyonlands.png and now I basically have
00:46this image in the front and then I have the yellow flower behind that.
00:50So I am going to go ahead and create a new kernel and I am just going to
00:55call this BlendMode.
00:57Now you can see here currently in the default, we only have one input, while in
01:02this case we actually have two inputs.
01:04So first I am going to call this first input back, so it's essentially the photo
01:10that's in the back and now I'm going to create another input. This is also going
01:15to be of type image4 and we are going to call this front for the front image.
01:19So now, down in my actual evaluatePixel function what I want to do is just
01:25create a simple blend mode effect.
01:28All I am going to do is I'm going to take whatever value the current pixel is in
01:33this front image, but I'm to change the red channel to use the red channel from
01:38the image that's underneath.
01:40So here I am setting just the output equal to the input.
01:44So I am going to say dst.r = then I am going to use this sampleNearest function,
01:53and one of the things I have to change is since I changed the name from source
01:57to back and front, I need to change that here.
02:01So the main image I'm dealing with is the front.
02:04So here I want to calculate the incoming pixel color value from the front image.
02:09But now I want to change the red channel equal to the red channel in the back image.
02:16So I am going to say back and now just to get to the red channel all I could do
02:21is to say .r. So now I am essentially swapping the red channel from the front to
02:27the one that's in the back image.
02:30So now if I run this, you can see that it's working.
02:33One of the things that you will notice here though is the image in front was
02:36actually larger than the image underneath.
02:38So you can see here now this piece here that isn't over the image is basically
02:43lost its red channel altogether.
02:46So we get a simple way around that.
02:48We can just say if and then I can grab this.
02:54What I am going to do is I am going to check the alpha of the pixel underneath.
03:00So I am going to say if the alpha is greater than 0.0 then go ahead and sample this.
03:08So what that's going to do is if there is no image underneath this front image
03:12we are not going to do anything to the red channel.
03:14So now if we run it, we can see it's only done that blend mode effect when there
03:20is actually something underneath it here.
03:22So this is obviously kind of a crazy blend mode, but it's just an easy one to
03:26give you an understanding of how you would create it.
03:29So now to use this in Flash, we are going to do the same thing we did with the
03:33Waterfall filter. I need to export this filter for Flash Player and I am just
03:37going to save this to the Desktop. I am just going to call it blend.
03:42So it will be blend.pbj.
03:43So I am now going to go over to Flash CS4. Now here I'm going to use that same
03:48waterTest.fla file that we used in the last video.
03:53So now one of the things that I need to do in order to test the blend mode here
03:57is I need to bring in or put something else underneath this image, so that I
04:02can see how it looks.
04:03So I am just going to move that out of the way for a second and I am just going
04:06to draw a rectangle in here with this kind of multicolored gradient selected.
04:12So I am going to just draw that and that's just so that we can have something
04:17underneath this image.
04:19So we can see how the blend mode actually looks.
04:22Again this has an instance name of image. So let's highlight the first keyframe
04:26of the Actions layer.
04:27Open up the Actions panel and now we can start writing our ActionScript.
04:31So it's going to be the same thing we did last time, so I need to create an embed tag.
04:35The source is equal to blend.pbj and we can set the mimeType="application-octet" and we'll close that.
04:50And now we need to create a class that's going to hold that filter.
04:55So again I'll just call it pbj and much like we did for the Waterfall, we need
04:59to create a new instance of the shader class. So var shader:
05:04subtype Shader = new Shader and then we pass in a new instance of that pbj class
05:13and we need to cast it to a ByteArray.
05:19So now at this point when we've dealt with the filter, we actually had to
05:22create a Shader filter.
05:24So we don't have to do that if we were going to be using a blend mode.
05:28What we have to do for a blend mode is we need to set the shader property of our image.
05:36So this is essentially going to tell it when we use a blend mode created from a
05:41shader which shader to actually use.
05:43So to do that we are going to say image, which again is the instance name of that
05:47movie clip on the stage, and I am going to set the blendShader property and now
05:54we actually tell it which shader we are going to use for the Shader blend mode.
05:58So obviously we would want to use that shader we just created.
06:01So now to actually set this blend mode, all I have to do is, just like setting
06:06any other blend mode here, I can say image.blendMode and then we use a constant
06:13from the blendMode class. So blendMode.
06:17and here are all the blend modes we can choose.
06:20If we come down we can see we have this shader option, so we are using
06:24the Shader blend mode.
06:26And now I can test this and I have an error here. See what the problem is, oh!
06:36we need to put octet stream.
06:38So yeah this is not correct. This should be application/octet-stream and now let's test it.
06:47Now you can see here is our image with that blend mode applied.
06:51So again, this is not a blend mode I think you be using very much but this just
06:55shows how the workflow actually works.
06:58So inside of Pixel Bender you are going to be dealing with two inputs instead of one,
07:01and then when you get over to Flash, you basically embed your Pixel Bender
07:07blend mode, create a Shader object, set the blendShader property of your display
07:12object to that shader and then simply set the blendMode to blendMode.Shader.
07:17So that's the basics of creating a new blend mode for Flash using Pixel Bender.
Collapse this transcript
Pixel Bender strokes and fills
00:00So we looked at a couple of different ways that you could take a Pixel Bender
00:03filter and apply it to a display object, very much like Blurs, Bevels, and Drop Shadows.
00:10Well, we can also use Pixel Bender filters to fill objects created with the
00:15drawing API, so we can either use it as a fill or actually as a stroke.
00:19So if you open up the stripes.pbk file from the Exercise Files, this is an
00:25example of a filter that's purely generating artwork.
00:29So this does have an input image, but essentially we are disregarding the actual
00:34values that are coming in from that image.
00:36All I am doing here is essentially using the Modulus function and I am testing
00:40whether the X position divided by 10, the remainder, is it greater than one and
00:47is it less than five?
00:49So the Modulus function essentially just takes two numbers, divides them
00:53together, and returns the remainder.
00:56So essentially I am just testing that if the remainder is between one and five.
01:00If it is, then I am going to output a yellow color.
01:03If not, I am going to output a black color.
01:06So it creates this black and yellow stripe effect.
01:09So now what I want to do is I want to export this for use inside of Flash.
01:14So I am going to go to File > Export Filter for Flash Player, and I am going to
01:18save it into that same directory in the Exercise Files.
01:22So we now have our PBJ file there.
01:25So now if we go over to Flash CS4. If you open up the stripes.fla file,
01:31that's also in that directory, this is just a regular blank FLA file.
01:34I will rename the first layer to Actions and lock it and open up the Actions panel.
01:42So now from here it's going to be a similar workflow.
01:45So we need to create our Embed tag.
01:48So the source is in the same directory as this FLA. It's stripes.pbj.
01:57Then the mimeType.
01:59Again, it's going to be application /octet-stream. We can close that.
02:08Now I need to create a class to hold it.
02:11I am going to call it pbj again of type Class.
02:15Now I need to create my shader object.
02:17I am going to call it Shader=new Shader.
02:22Created a new instance of pbj as a ByteArray.
02:28Okay. So now if I actually want to use the Shader as a fill, I can just create a fill
02:38using the new features of the Drawing API.
02:40So what I am going to do is I am going to first just create a shortcut to the
02:45Graphics property of the stage.
02:48So to get that, all I have to do is create a variable.
02:51I am just going to call it g. This is going to be of type Graphics, is equal to this.graphics.
03:00This is just a shortcut, so I don't have to keep writing this.graphics.
03:05Another little side benefit is if I type this.graphics, I don't get any code hinting.
03:10So by creating this little alias, it makes it easy to get code hinting.
03:14So now I am just going to say g and now in order to set up that Pixel Bender
03:19Filter as a fill, I am just going to choose beginShaderFill.
03:24Now it's asking me to provide which shader I want to use.
03:28So obviously I want to use that shader that I created.
03:32And now I can just start drawing like I normally do with the Drawing API.
03:36So let's say g. Let me go ahead and choose drawCircle and I will put it at let's say 200.
03:47200. I will just give it a Radius of 100.
03:50So now if we test that, sometimes when you are using this Flex metadata,
03:57this will actually pop-up, and it's essentially just asking you to update the library
04:01path to the Flex SDK.
04:03If you ever see this message, all you have to do is click Update library path
04:08and then relaunch your SWF file.
04:09So now you can see I have my circle and its being filled with that Pixel Bender filter.
04:16So now if I want to use an actual stroke that's based on my Pixel Bender filter,
04:22what I have to do here is first, I need to set up the line style, so
04:26g.lineStyle, like we normally have to do.
04:31I am just going to give it a thickness of let's say 10 and under that then
04:37we need to call the lineShaderStyle method and pass in our shader.
04:44Now, it's important that you actually set the lineStyle first and then
04:48the lineShaderStyle.
04:49If you don't do this first, you are essentially not going to have any stroke
04:53whatsoever on your object.
04:56So now what I want to do is I am going to say g.drawCircle.
05:01We will just do the same thing, 200, 200 for the Position, and 100 for the Radius,
05:08and now you can see the actual stroke of that circle is being filled by Pixel Bender.
05:14So this is just an alternate use of Pixel Bender.
05:17So not only can you use it to apply filters to display objects, but we can also
05:22use it for fills and strokes that we create with the Drawing API.
Collapse this transcript
Using filters in Photoshop and After Effects
00:00So when you create a Pixel Bender filter, you can also use it not only in Flash,
00:05but also inside of Photoshop CS4 and After Effects CS4.
00:10So the Pixel Bender support inside of After Effects CS4 comes built-in with the product.
00:16For Photoshop CS4, you are going to need to download the Pixel Bender
00:19plug-in for Photoshop CS4.
00:22So here we are back on the Pixel Bender homepage, on the Adobe Labs site, and
00:26you want to again go to that Download pod and click on this link.
00:30You will see down here you can download the Pixel Bender plug-in for Photoshop CS4.
00:36So there is a 32-bit version for Mac and Windows and also a 64-bit version for Windows.
00:41So now I have already downloaded this to my Desktop and this is just like the
00:46Text Layout Framework.
00:48So I am going to double-click this and now I can install the extension.
00:52Now, I already have it installed, so I am just going to Decline here.
00:55What this now enables you to do is to put your Pixel Bender filters so that they
01:00show up inside of Photoshop and After Effects.
01:03So I have already copied that waterfall. pbk file into the Directories, but let
01:09me actually show you.
01:10For After Effects CS4, you are going to want to go to, on Mac, [00:01:1420] into Applications, to the After Effects CS4 folder.
01:18If you are on Windows, you are going to go into Program Files and then After Effects CS4.
01:22Then you will see a Plug-ins folder and inside of that you will see an Effects folder.
01:28This is where all the different effects are for After Effects.
01:31So if we scroll down, here you can see that PBK file, that waterfall.pbk
01:36file that we created.
01:37Now, it's important to note that the PBJ format, that's specific for Flash.
01:43So when you are actually using Pixel Bender filters in After Effects and
01:46Photoshop, you simply use the PBK format, which is that source format that
01:51we created directly in the Toolkit.
01:54So that's where you put it for After Effects.
01:56For Photoshop, it's going to be similar.
01:58So you are going to go to Applications/Photoshop CS4.
02:01If you are on Windows, Program Files/Photoshop CS4.
02:05Here we can see there's actually a Pixel Bender Files folder right in the top
02:10level directory here, and inside of there the Photoshop plug-in actually comes
02:15with a bunch of Pixel Bender Filters with it.
02:18I have just added the Waterfall filter to the rest of them.
02:22So now let's look at how we actually use these Pixel Bender filters in each of these tools.
02:27So let's start in Photoshop.
02:29So I have imported just a photo of my cat and now I am going to go to Filter.
02:35Then you can see we have a Pixel Bender entry here and I can launch the
02:39Pixel Bender Gallery.
02:40So this is an actual separate window that's going to pop-up that's going to
02:44allow me to preview my image with the different filters.
02:48So here is a CircleSplash filter that I could use to create some kind of crazy effects.
02:53Definitely some cool ones in here.
02:56Kind of a 3D effect, the Fisheye effect.
02:59Kaleidoscope, which actually creates a kaleidoscope of the different things
03:04sampling from my image.
03:06But if we go down to the bottom here, we can see my Waterfall filter that I created.
03:10So now I can come through here and actually adjust it, because remember,
03:14I created that parameter.
03:17Let's say I wanted it like this.
03:18I am going to click OK, and now we have been able to use that Pixel Bender
03:22filter to manipulate our images in Photoshop, very similar to other filters that
03:28you find in Photoshop.
03:29So now inside of After Effects, I have created just a very simple comp here and
03:35now just so we have some type of video footage on here. I am going into the
03:39Animation Presets, into Backgrounds.
03:42I am just going to drag out one of these stock background effects.
03:45If I do a RAM preview, we can see that's the basic Circuit effect.
03:50So now to actually use my Pixel Bender filter, I do it just like I do with other
03:55effects in After Effects.
03:56I go to the Effect menu and then you can see there is a Pixel Bender entry and
04:01there is my Waterfall filter.
04:02When I select it, we can see it's automatically being applied here.
04:07If I come to my Effects window, let me just collapse some of these, this is for
04:12the background, and now I can adjust this so I get that Waterfall effect.
04:17Now, since I am inside of After Effects, this can easily be animated as well.
04:22So I can keyframe this Amount parameter.
04:26Now, let's say I go to 5 seconds and make it go all the way to the bottom and
04:32now I do a RAM preview, and now you can see it's actually animating that Pixel
04:37Bender filter here inside of After Effects, to create kind of a streak effect.
04:43There we can see it kind of playing in real time.
04:46So again, once you have the Pixel Bender filter, applying them to either your
04:50Photoshop or After Effects content is really no more difficult than using the
04:54regular effects and filters that come with those tools.
Collapse this transcript
4. New Sound APIs
Overview of the new sound APIs
00:00So with the release of Flash Player 10, you've seen some amazing new sound
00:04features being put into the player.
00:07Now these features allow you to do things like generate sound entirely from code,
00:11 as well as extracting the bytes of an external audio file and
00:16manipulating the bytes before they reach the sound card.
00:18So I am actually going to show you a couple of examples of this.
00:21If you go to hobnox.com, this is a general portal site, but one of the
00:27features is this Audio tool, and it just simply known as the Hobnox AudioTool,
00:32and this is created by Andre Michelle and Joa Ebert who are Flash developers from Germany.
00:37Essentially this application is a complete electronic music studio that has
00:42been created in Flash, and all the sound that you hear in this tool is actually
00:46purely generated from code. It's not actually playing external samples or
00:51anything like that.
00:52So from here I can basically choose a preset to start with.
00:56So I am just going to choose this Tone Matrix preset.
00:58And now it's creating my project and not only is this just an awesome example of
01:03these new sound features, but just this application in general is just an
01:06amazing piece of Flash work, all the design.
01:09It's just really beautiful.
01:10So essentially from here I can zoom out a little bit so I can see my workspace.
01:15Now I can also add other instruments and effects, so I can pull out this little
01:20panel here, and I can drag out different pedals.
01:24Let's say I wanted a bass machine here.
01:27Now I am by no means a music expert, so I wouldn't know what to do with most of these things.
01:32But the sound that's actually played again is purely generated from code and
01:36it's really quite amazing.
01:37So if I just play the standard track here.
01:40(Music Playing.)
01:46So all of that is using the new sound APIs in Flash 10.
01:50Now with this ToneMatrix, essentially I can click in here to create tones
01:54anywhere on this grid.
01:56So I can just lay down some tones like that.
01:58(Music Playing.)
02:02And actually as it's going I can be adding sound.
02:05(Music Playing.)
02:09So this is probably the ultimate use of this dynamic sound generation in Flash Player 10.
02:15Another example, and this was also created by Andre Michelle on his blog,
02:19essentially showcases the ability to play an external MP3 file and actually
02:25extract the bytes as they come into the Flash Player and manipulate them before
02:29you actually hear them.
02:31So in this example he's allowing the user to actually slow down or speed up an
02:36MP3 file based on a slider.
02:39So here is a slider. Once the music starts playing, I'll be able to adjust the
02:44speed and the pitch of the sound.
02:46(Music Playing.)
02:52So you can see I can completely slow down this sound, which is of course also
02:56adjusting the pitch of the sound and I can also go up.
03:03You can see as I can move the slider very quickly, it's very responsive and
03:07the quality is really good.
03:08And he also has the source code for this available here.
03:12So again these new sound features allow you to basically do whatever you want
03:17now with sound inside of the Flash Player and in this chapter we'll look at just
03:20a few other things that we are able to do with it.
Collapse this transcript
Generating dynamic sound
00:00So one of the key new sound features in Flash Player 10 is the ability to
00:04generate sound dynamically using nothing more than code and I am going to show
00:08you how to do that in this video.
00:10So I am just going to create a blank ActionScript 3 document here and again
00:14everything we are going to do in this tutorial is going to be in the Actions panel
00:17because we are going to be using all code.
00:19So I'll just rename that layer to Actions and highlight the first keyframe and
00:25open up the Actions panel.
00:27So the first thing we do is we create a sound object.
00:30So I am just going to create a sound object called S = new Sound.
00:35Now here typically if you're playing an external MP3 file, you would now put in
00:39a new URLRequest object with the URL to your MP3.
00:43Well, in this case we are going to create just an empty sound object because
00:47we're going to be providing Flash with the actual sound data ourselves.
00:51So I am just going to go ahead and create an empty sound object.
00:55Now we need to respond to an event called SampleData and this event is
00:59essentially, if we start playing an empty sound, Flash is going to fire this
01:04event and say hey, I need some sound data for this sound object which you can then provide.
01:09And this SampleDataEvent will be called continuously whenever this sound object
01:14needs new sound data.
01:16I am going to say s.addEventListener and the event is of type
01:21SampleDataEvent.sample_Data.
01:26And I am going to have this call a function called SampleData.
01:30So I will create that function now.
01:34Now the event object type is going to be SampleDataEvent and we are
01:40not returning anything.
01:41So we are going to put void.
01:44So what we need to do inside of this SampleData is we need to create a whole
01:49bunch of sound samples.
01:51Now, the amount of sound samples that you create is you basically have a range
01:56which you can choose from.
01:57So the smallest amount you can create is somewhere around 2500 and basically
02:03the more samples you have, the higher quality the sound will be.
02:07But the more resources it's actually going to take up in order to play that sound.
02:12So we are going to create these samples inside of a for loop.
02:15So I am going to say var i, data type it to :int=0.
02:19And then I am going to do i is less than 2500.
02:23Again, you can experiment here.
02:25If you put a really high number of samples again you are going to get a
02:27higher-quality audio, but it's going to take up considerably more processor and RAM.
02:32So we will just increment i. So again, inside of here now, we are coming in here
02:38and we are going to create 2500 samples to send back to the sound card.
02:43So one other thing we need to do is to increment the current position.
02:49So when this event calls, part of this event object is actually the position of
02:54where we are in the sound.
02:56And what we need to do is increment that for each sample.
03:00So I am just going to create a variable here.
03:02I'll call it Position, and this is just going to be a number, and I am going
03:07to say i + e.position.
03:11So again, the e.position is going to basically tell us what position we are
03:16in this sound data.
03:17So when the SampleDataEvent fires, this e.position is going to be greater each time.
03:23But for each sample, we also need to increment the position.
03:26So now that we have that variable, now we actually need to calculate the sample.
03:33So the actual value that we are going to provide to the empty sound object.
03:38So I am going to create a variable. I am going to call it Sample.
03:42Again, this is going to be a number.
03:44So now for this sample, what we need to actually do is to create a wave.
03:48So all sound is made up of oscillating waves, typically a sin wave.
03:53So in order to create that wave effect, we need to actually use the Math.sin
03:59function and now inside of the sin function, we want to put in this position
04:04variable that we have up here.
04:06Again, this is incremented for every sample.
04:08So I am going to put that in.
04:11Now remember that the Math.sin function actually expects a value in radians.
04:16So what we need to do is now convert this into radians.
04:20The way we do that is to divide that by Math.PI, divided by 2.
04:26So now we've taken that position variable and we have converted it into radians.
04:30Now if we were to just now play this resulting value, the sound would be way
04:36too loud. The amplitude.
04:38That's another thing to know, when you are playing with these audio APIs,
04:41definitely don't start out your experimentation by turning your speakers all the
04:45way up with your headphones on because you can generate some pretty loud and
04:49obnoxious sounds as I'm about to demonstrate.
04:52So now from here we want to essentially bring down the amplitude of this sound,
04:55so it's not quite so loud.
04:56So I am just going to multiply that by 0.25, just so that it's more of
05:01a comfortable volume.
05:02But it is important to note that this is how you could adjust the amplitude by
05:06just multiplying it either by a greater or a smaller number.
05:09So now we have this sample calculated, now we are ready to actually send this
05:14back to the sound object to play.
05:16Now, we need to actually write two samples, one for the left channel and one
05:20for the right channel.
05:21So if you wanted to create sounds that had different things going on in each
05:25channel, you could do that.
05:26But we are simply going to write the same sample to both channels.
05:30So we actually use this event object to write the data back.
05:34So we say e.data.writeFloat because this again is a floating-point number.
05:41So now we are simply going to write that sample value into the left channel.
05:47Now, all I have to do is to copy this and paste that in for the right channel,
05:52and that's all that it takes.
05:53So essentially all the logic is right here and by changing some of these values,
05:58you can create some wildly different sound effects.
06:01So we have created our sound object. We have set up the SampleDataEvent.
06:05Now all there is left to do is to simply play this sound.
06:09So all I have to do is say s.play.
06:12And when we test it, we should hear some audio.
06:14(Beeeeep.)
06:17So you can hear that steady tone.
06:19Again, that steady tone is created by the oscillating effect created by using
06:23the Math.sin function.
06:26So now let's say we wanted to change some properties of this to make it a
06:30higher or a lower tone.
06:33So what I can do is I can wrap this position in radians here in parentheses and
06:38now I can just multiply this by let's say 0.2.
06:43(Beeeep.)
06:44Now, you can see I have a lower tone.
06:45If I multiply it by let's say 1.2,
06:49(Beeeep.)
06:50we have a higher tone.
06:52So again, adjusting this value that's inside of this Math.sin function will give
06:57you different tones and effects.
06:59Now what you can also do is, let me just back that up, you can also get
07:03different effects by choosing different functions here.
07:06So let's say I did the Math.tan function.
07:08(Nreeee. High pitched beep.)
07:09Now, we are getting to the obnoxious stage.
07:11But by adjusting these values, manipulating the different functions that you are
07:16using to call, you can create all types of different effects using these new
07:20features in Flash Player 10.
Collapse this transcript
Extracting bytes from external sounds
00:00So in addition to being able to generate sounds dynamically at runtime, we also
00:05now have the ability to extract the bytes of an external sound file and
00:11manipulate those bytes and send them to the sound card.
00:14So we can create things like real-time audio effects.
00:16Well, in this tutorial, I am going to show you the basics of how to extract the
00:20bytes from an external sound and pass them to the sound card.
00:24So you can open up the extraction.fla file from the Exercise Files. Essentially
00:29this is just a blank Flash document with a locked Actions layer.
00:33So I am going to highlight that first keyframe and open up the Actions panel.
00:37So what I first need to do here is to create a new sound object that's going to
00:41start loading in that external sound.
00:44So I am just going to say var and I am going to call it external and it's going
00:49to be of type Sound = new Sound.
00:53And again, since I am playing an external sound file, I need to create a
00:56new URLRequest here.
00:59I am going to be using a sound file with the name of april20.mp3.
01:04This is some music created by Trioptic from hiphopproduction.com.
01:10So I am just going to put that in there and you could use any mp3 file you
01:13have in your system.
01:15So now what I need to do is this line is essentially going to start loading
01:19in this audio file.
01:20What I need to know is when that sound file has been completely loaded in.
01:25It's important to note that you can only extract the bytes of the file once it's
01:29actually loaded in, and the reality is we are not actually extracting bytes per se
01:34but we are extracting samples from the audio file.
01:37So what I need to do is to respond to an event and that event is Event.COMPLETE,
01:47and this is going to fire as soon as that loading operation has finished.
01:51And I am going to have that call a function called onLoaded.
01:54Okay, so now what I also need is an empty sound object.
01:59So in the last tutorial I showed you how we create an empty sound object,
02:03we respond to the SampleDataEvent in which we need to provide Flash with some sound data.
02:08Well, we are going to be doing the same thing here except we are going to be
02:11providing the data from that external sound. We are not gong to be coming up
02:14with it from scratch.
02:15So I am going to do the same thing, I am going to call this var Empty, and
02:20this is going to be my empty Sound object = new Sound.
02:24And just like the last tutorial, I am going to need to respond to the
02:28SampleDataEvent.SAMPLE_DATA.
02:35I am going to have that call a function called SampleData.
02:37So now I need to create this event listener here, so I need to create
02:41that onLoaded function.
02:43So function onLoaded. I am not going to be returning anything.
02:51So all that I need to do in this onLoaded function is to simply start playing
02:56the sound, which will then trigger the calls to the SampleDataEvent.
03:00So the reason why I have to wait in order to do that is like I mentioned before,
03:04we have to wait until this file is completely loaded in before we start
03:07extracting samples from it.
03:10So inside of here, all I have to do is simply say empty.play.
03:13So now we need to create that sampleData event handler.
03:18So function sampleData and again this is going to be of type SampleDataEvent.
03:23We're not going to be returning anything.
03:29So the first thing I need to do inside of here is to create a new byte array instance.
03:34This byte array is essentially going to hold whatever samples that I extract.
03:38So I am just going to call it BA for byte array.
03:41It's going to be of type ByteArray = new ByteArray.
03:46So now, I'm ready to actually extract some samples from that external file.
03:52The way in which we do that is by using the extract method of the sound class.
03:57So my external file is called external, and I want to call the extract method.
04:03Now, you will notice the code hinting in here.
04:06That's just Flash CS4 for you.
04:07Sometimes it works correctly, sometimes it doesn't.
04:10But you want to call the extract method here and you can see the first thing I
04:13need to pass in is which byte array do I want to store these samples in?
04:17Well, I want to store it in the byte array that I just created, so BA.
04:22The next thing I need to do is I need to basically say how many samples do I
04:26want to extract from that sound file?
04:29So kind of the magic number for this is 4096.
04:34Now, you can extract more than that but that's pretty much the minimum number
04:38of samples to extract, and in most examples you are going to see most people use 4096.
04:42So it's essentially going to, every time it comes in here, extract 4096 samples
04:49from that external sound file.
04:52So now that I have those samples stored in this ByteArray object, now all I
04:55need to do is to simply write these bites to that empty sound object, so they can be played.
05:01So we did that in the last tutorial, but it's just e.data.writeBytes, and now we
05:08need to provide which bytes do we actually want to write and we just want to
05:11write that byte array.
05:12So now again when we load this Flash movie, it's going to load in this MP3 file.
05:19As soon as it's done loading completely, it's going to call this onLoaded function.
05:23Then we know that file is fully loaded in.
05:26Then we can start playing the empty sound object.
05:29When that happens, the SampleDataEvent gets called and now we are actually
05:33extracting a certain number of samples from that external file and providing it
05:38to the empty sound object. So let's test it.
05:41(Music Playing.)
05:46So you can see that's now playing.
05:48Now in this example, obviously we haven't done anything to the bytes.
05:53All we're doing is simply extracting the bytes and passing them to the empty
05:57sound object unchanged.
05:59So there would be no reason to actually do all of this work if you didn't want
06:02to manipulate the bytes in some way.
06:05But this is essentially the workflow for extracting the bytes, passing them to
06:09an empty sound object, and then playing them.
06:11Now in the next tutorial, we are actually going to do something with the bytes
06:14and manipulate them to create kind of real-time audio effects.
Collapse this transcript
Creating real-time audio effects
00:00So, in the last tutorial I showed you how you can extract the bytes of an
00:04external MP3 file and pass those bytes to an empty sound object to play them back.
00:10Well, in this tutorial I will show you a real world case for why you might
00:13actually want to do that and that's to manipulate the bytes before you actually
00:17send them to the empty sound object.
00:19So you open up the effects.fla file from the Exercise Files and this is
00:24essentially the finished product from the last tutorial.
00:28Here I've created an external sound object, I am playing in that music into
00:32this empty sound object.
00:35Again, we haven't manipulated the bytes whatsoever here. So if I test this.
00:39(Music playing.)
00:41It's just playing the music exactly as it came into the Flash Player.
00:45So now let's look at how we can manipulate these bytes.
00:48So down here we have this function where we are writing the bytes to that empty
00:53sound object to be played back.
00:55What we can do is to before we actually send this ByteArray to the empty sound
01:01object, we can manipulate it.
01:03So let's create a function, and I am going to call this function, upOctave, and
01:07it's essentially going to bump up the sound in that file by an octave.
01:12I am going to make it essentially higher pitched.
01:14This function will actually be called before it's actually sent to the sound card.
01:18So I am going to create that function now. It's upOctave.
01:25Now to this function we are actually sending this byte array, so I need to have
01:29a byte array instance here to catch that.
01:31And I will just call it bytes and this is going to be of type ByteArray.
01:36Now when we're done with this function we are actually going to be returning a
01:39byte array back to the writeBytes method.
01:42So I need to specify a return type also of ByteArray.
01:45Okay, so the first thing I need to do is to create a new ByteArray instance
01:52that I'm going to use to send back to the writeBytes method here.
01:56So I am just going to do that and I'm going to call this returnBytes:ByteArray = new ByteArray.
02:08Okay, now what I want to do is this incoming ByteArray, I want to make sure the
02:11position in that byte array is actually set to 0, so we are starting at the
02:15beginning of the byte array.
02:17To do that all I have to do is to say bytes.position = 0.
02:23So again, as we deal with byte arrays, as we go through it, there is essentially
02:27a pointer that will be there, so we know where we left off the last time we
02:31dealt with it and setting the position property essentially to 0 will reset that
02:35pointer back to the beginning of the file.
02:37Okay, so now I want to iterate over the bytes that were sent in to this function.
02:42To do that, I am going to use a While loop.
02:44So I am going to say while(bytes.bytesAvailable > 0).
02:54This essentially means so long as there are more bytes to deal with in this file.
02:58Then inside of here I am going to create a block.
03:01Now what we want do is to read two float values from the incoming byte array and
03:07write them to this returnBytes byte array.
03:10Again, we are reading two floats, one for the left channel, one for the right channel.
03:14So to do that I just say returnBytes. writeFloat, and we are going to write
03:22essentially the values that we read from the incoming byte array.
03:26So to get those we just simply say bytes.readFloat.
03:31So again, here I'm reading in a float value from the incoming byte array and
03:38I'm simply writing it to the returnBytes byte array that I am going to be
03:42sending back up here.
03:44Now again, we need to do this for both channels, so I am just going to put this
03:48in here again for the right channel.
03:51Now here's the part where we are actually going to skip 8 samples so that
03:55basically we are going to make the sound go up an octave.
03:58So the way we do that is we can say if(bytes.bytesAvailable > 0).
04:08So again, we are doing the same thing we did here.
04:10Since, we are going to be reading two float values here, we still need to make
04:13sure that there are actual bytes still available.
04:17If that is the case then we want to move the pointer in this byte array
04:22eight places forward.
04:24So essentially we are skipping over an octave.
04:27So, bytes.position += 8.
04:33So here we retrieved the two floats and then basically we are skipping over eight
04:37samples before we start going and read some more.
04:41And the act of skipping over those eight samples is going to raise the pitch of
04:44the sound by an octave.
04:46Now it will also increase the speed of the sound obviously.
04:50Now if you wanted to increase the pitch of a sound without increasing the speed
04:53of the sound, that's a lot more of a complicated process.
04:57So now that I have done this, now all I simply need to do is just to return the returnBytes.
05:05Again, when I say return returnBytes it's essentially going to now pass
05:09the manipulated bytes back here and that will then get sent to that empty sound object.
05:15So you can test it now.
05:16(Music playing.)
05:19So we can see it's a much higher pitched sound and it's a lot faster as well.
05:23So the act of skipping over those eight samples not only has the effect of
05:28raising it by an octave, but also speeds it up.
05:30Now again, adjusting the number of samples that you skip over, you can create
05:34all kinds of different effects.
05:36You can make it go a lot faster.
05:37You can make it go a lot slower.
05:39You can also by manipulating the bytes in this way easily do things like make a rewind.
05:44You could play in reverse, and fast reverse.
05:46So there are definitely some very good uses of this technology.
05:50So that's the main method of extracting an external sound file, manipulating the bytes,
05:55and then sending it out to the sound card.
Collapse this transcript
5. Reading and Writing Local Files
Loading a local file into the player
00:00So there has long been a security restriction in Flash that didn't allow you to
00:05read and write local files directly from the user's machine.
00:09Now of course, this sounds like it would be a security issue.
00:13Well, in Flash Player 10 we now have the ability to actually load in local files
00:18as well as save local files directly from the Flash Player.
00:22And the reason why this isn't a security concern is that the user actually
00:26always has to initiate one of these actions via either a click or a key press.
00:32The other thing is that they're always going to see their operating system
00:35dialog window asking them to either open or save a file.
00:40So there's no way to programmatically in ActionScript just start deleting or
00:44loading files on the user's machine.
00:47So I am going to show you in this example how you would load in an image file
00:50directly from the user's local machine.
00:53In previous versions of Flash, if you would wanted to do this, you would
00:56actually have to upload the image to your web server, then download it from the
01:00web server into your Flash movie.
01:02And these new enhanced features actually eliminate that step.
01:05So go ahead and open up the load_file.fla file.
01:10And this is just a simple application here.
01:12I have a single button component on the stage with an instance name of loader.
01:17And then I have a locked actions layer.
01:19So I am going to highlight the first keyframe in the actions layer and open
01:22up the Actions panel.
01:24Okay, so the first thing I need to do is to set up the click event for
01:28that button component.
01:29So again, it has an instance name of loader, so I am going to say
01:32addEventListener and I want to respond to MouseEvent.CLICK
01:39and I'm going to have that call a function called onClick.
01:43I am going go ahead and just stub out that function really quick.
01:46So, onClick(e.MouseEvent) and we are not returning anything here.
01:55So when we want to deal with the user's actual local file system, we use an
02:00instance of the FileReference class and that hasn't changed in Flash Player 10.
02:04So the first thing I am going to do here is to create a new instance of the
02:07FileReference class.
02:08So I am going to say var fr: FileReference = new FileReference.
02:18So now that I have this new FileReference object, I can now start interacting
02:23with the user's local file system.
02:26So inside of this onClick what I want to happen when I click on this button is I
02:30want a operating system browser window to pop-up, so that the user can choose
02:35what file on their local system they want to load into the Flash Player.
02:39So to do that I need to add an event listener to the FileReference. I need to
02:44listen for the Event.SELECT event and that's going to fire as soon as the user
02:49actually selects the file to import in.
02:52It's going to trigger the Event.SELECT event.
02:56So what I am going to do is say fr.addEventListener(Event.SELECT).
03:06Now when this event fires, all I am going to do is I am going to tell the
03:09FileReference to go ahead and start loading that file into the Flash Player.
03:14So since, I only have one basic command that I need to run, I am just going
03:18to put an anonymous function inside of here instead of creating an additional function.
03:22So I am just going to say function, catch the event object with e, fr.load, and actually that's a method call.
03:35And that's all there is inside of this function.
03:37It's just easier to do an anonymous function here.
03:41The other event I need to listen for is the Event.COMPLETE event and this event
03:46is going to fire as soon as the file that the user selected has finished loading
03:51into the Flash Player.
03:52And then I can actually get the raw bytes that were loaded in and do
03:56something with them.
03:58So again I am going to say fr. addEventListener and I'll use Event.COMPLETE.
04:03And for this one I'm going to have it call a function called onComplete.
04:09Okay, so now what I need to do is I actually need to trigger that Browse window
04:13to pop-up so the user can select their file.
04:16To do that, it's very simple.
04:17I just say fr.browse.
04:20Now I can restrict the file types that I want the user to select by passing in
04:25an array of file types.
04:26But in this example I am just going to leave at the default.
04:28Okay, so this will launch the browse window and have my event set up. Now I just
04:33need to go ahead and complete this event handler here.
04:37Now remember it calls a function called onComplete.
04:39I just need to create that, onComplete, and I am not going to return anything,
04:47so I am going to put void.
04:50So now what I need to do is I want to create a new loader object.
04:53Now the loader class is essentially also a display object, so once I can
04:58basically get the bytes that came in from that external file and load it into
05:02this loader class, which I can then put on the display list so the user can see it.
05:07So I am just going to create var l:Loader = new Loader.
05:15And now in order to get the bytes from the FileReference into the Loader, I just
05:20have to say l.loadBytes.
05:23And now it's asking me for a byte array.
05:25Well, that data that came in through the FileReference actually is a byte array.
05:29So in order to get that, all I need to say is e.target.data.
05:36So this will get to the actual byte array data that came in when I did
05:40this FileReference load.
05:42So now I have those bytes inside of my loader, now all I have to do is just
05:47add the loader to the display list.
05:49So just addChild(l).
05:52And now let's test it.
05:53So now I have my button component here.
05:55Let me pull this out.
05:57So I have my button component and when I click on this, you can see it's now
06:02prompting me to actually load in a file.
06:04So what I am going to do is go into the Exercise Files and inside of here I
06:10have an image, a JPEG image, of Bea.
06:12And I am just going to click Select, and we can now see it's loaded that file
06:16through the FileReference directly and I've got access to those bytes, put it
06:21into a loader and then added it to the display list.
06:24So again, doing this with previous versions of Flash would have required me to
06:27upload this image to my web server and back down into the Flash movie.
06:31So if you need in your application for the user to load in their own local files,
06:36this new feature, the FileReference class, is going to come in really handy.
Collapse this transcript
Saving a file to the user's machine
00:00So in the last tutorial we looked at how we could load a file directly from
00:04the user's hard drive into the Flash Player.
00:07Well now I am going to show how you can go the other way.
00:09So this is taking something from your Flash movie and saving it directly to
00:13the user's hard drive.
00:16So go ahead and open the save.fla file from the Exercise Files and I've already
00:20create just a simple Flash movie here.
00:23I have a UI button here called Save with an instance name of saver, and in the
00:29Actions panel I've created what basically amounts to a simple drawing program.
00:34So I'm basically creating an alias to the graphics object.
00:37I'm setting a lineStyle of five.
00:39I have set up the onMove event, the Mouse_Move event, and when I move the mouse
00:45I'm just simply drawing a line to wherever my mouse is.
00:47I've also set up the click event for that Save button.
00:53So if test this now, you can see it's drawing to wherever my mouse position is.
00:58So the idea of this is that when I'm finished drawing, I can click on the Save
01:03button and it's going to take a snapshot of whatever I've drawn and save it out
01:07to the user's hard drive.
01:09So to accomplish this, we need to use a class out of the AS3 core lib library.
01:15I've already put that in the Exercise Files.
01:18So if we look in here, we can see inside of here, we have a com folder, an adobe
01:24folder and then all the APIs that come with the Core Lib libraries.
01:27Well inside of here is a folder called images and we can see we have a
01:32JPEGEncoder and we have a PNGEncoder.
01:35So this allows you to pass some bitmap data to one of these classes and it will
01:40actually generate either a JPEG or PNG file.
01:44So the first thing we've to do in our ActionScript code is we need to import
01:48the PNGEncoder class.
01:50So we're actually going to encode to PNG.
01:52So I am just going to say import and then com.adobe.images and PNGEncoder.
02:02So now I've imported that class that I can use it.
02:04You see in the onClick function-- remember this is going to be fired when the
02:09user clicks on that Save button.
02:11The first I have to do is I need to create a new file reference object, so much
02:16like I did in the last tutorial.
02:17Anytime you want to interact with the user's file system you need to do it
02:21through the FileReference class.
02:23We want to go into the onClick function, var fr, data type to FileReference =
02:32new FileReference and now what I need to do is to create a new BitmapData
02:38object, and this is going to store whatever is out on the stage when I click the Save button.
02:43So I am going to say var, I am going to called bmd for BitmapData.
02:49It's equal to new BitmapData.
02:51Now here I am going to have to actually pass in the width and the height that I
02:54want this BitmapData to be.
02:56I am going to make it the same size as the stage. So 550x400.
03:02So now to take a snapshot of whatever is actually present on the stage, all I have
03:06to do is called the bmd.draw method.
03:10I need to pass in which display object I actually want to take a snapshot of.
03:15I just want to take a snapshot of the stage, so I am just going to pass in this.
03:19Okay, so now we have the bitmap data. Now we actually need to encode it into
03:24an actual PNG file.
03:26So for this we need to create a ByteArray.
03:27So I am going to say var ba for ByteArray.
03:30It's going to be of type ByteArray and now what we want to do is we need to use
03:36the static encode function of the PNGEncoder class.
03:41So PNGEncoder.encode and to this function, we simply pass in which bitmap data
03:50do we want to turn into a PNG file, so bmd.
03:54And now this is essentially going to create a PNG and stored into this byte array.
03:59So now here comes the new stuff for Flash Player 10 is how do we actually save
04:03this file directly to the user's machine?
04:05Well, this couldn't be any easier.
04:07All we've to say is fr.save and then essentially which data do we want to save.
04:13What we want to save that ByteArray, which is actually in the PNG format.
04:18So we just say ba and then close this.
04:22So now again, when we say fr.save, it's not going to save it without the user
04:26actually knowing about it, because it's going to pop up some things.
04:29It's going to allow them to choose the file name and the location of where to save this.
04:34So let's test the movie and now I can start drawing my masterpiece here, little
04:40house and something like that.
04:43It almost looks like a face at this point, but let's say I am really happy with that.
04:47I click on Save and now you can see it's launched the Save dialog.
04:51So there is no way to avoid launching that and that's the difference between
04:54Flash Player and technologies like Adobe AIR, which does allow you to read and
04:59write files programmatically.
05:00But remember AIR applications are real desktop application, so there's a
05:05looser security context.
05:07So what I am going to do is I am going to save this to the desktop.
05:10I'll just call it masterpiece.png and save it.
05:16And now if we go to the desktop we can see here is the PNG file and when I
05:21launch it up, you can see it's encoded that now to a PNG file and it's actually
05:25even included the Save button here, because I literally just took a bitmap data
05:29shot of the entire stage.
05:31But essentially this new workflow with the FileReference class makes things a
05:35lot easier when you want the user to interact with your Flash movie using their own files.
05:41And in the next tutorial, I'll show you kind of a full example of creating a
05:45simple photo editor using these new file reference features.
Collapse this transcript
Creating a simple photo editor
00:00So in the last two tutorials I showed you both how to load in files directly
00:04from the user's machine as well as how to save content from your Flash movie
00:10directly to people's hard drives.
00:12So now I am going to put the two together and create just a simple photo editor.
00:16So I already have built a simple UI here and I am in the photoEditor.fla file
00:22and I do have some UI components here out on the stage.
00:26I have a Slider component with an instance name of slyda, and I have a Loader
00:31button and a Saver button.
00:33So what we're going to do is we're going to load in an image file directly and
00:38then we're going to apply that waterfall Pixel Bender filter that we created in
00:43the Pixel Bender chapter and this essentially creates a waterfall effect.
00:47Now I am going to be able to control the amount of that effect based on the
00:50value of this slider, and then what we're going to be able to do is once we have
00:54the effect we want, we can click the Save button and it's going to go ahead and
00:58generate a PNG file of that modified image.
01:02So if we look in the Actions, I've set up quite a bit of this already.
01:05So here we're embedding the Pixel Bender Filter.
01:09Again, if you need to brush up on this, you can look back in the Pixel Bender chapter.
01:13I have it stored in a class called pbj.
01:15I am creating a new shader based off of that pbj class and then creating the
01:20shader filter based on that shader.
01:23And then here are my event listeners for my three UI components.
01:27Here is a slyda change event and this is going to fire any time the slider is
01:31moved or anytime the value changes on the slider.
01:35And then I have two click events, one for each of the buttons.
01:38And then in the onChange event for the slider, all I am doing is changing that
01:43amount parameter that was set in Pixel Bender based on the value that the slider is set to.
01:49So now what I want to do is to load in that image whenever this Load button is clicked.
01:56So I want to go into the loaderClick function and what I first need to do is to
02:00create a FileReference instance.
02:04So = new FileReference and much like we did before, we need to set up the Event Listener.
02:14So fr.addEventListener and now I want to respond to the SELECT event and again,
02:23I am going to put in an anonymous function here, that basically all it does is
02:28just start the load operation for the File Reference. So fr.load.
02:34I can close that anonymous function and close the event listener and just
02:39going to copy this.
02:40Again, we need to do Event.COMPLETE this time.
02:43This is going to fire as soon as the Load operation is complete and I'm going to
02:48have it call a function called onComplete.
02:53Okay, so now I am going to come on to here.
02:54I'll create that function onComplete.
03:02And in this onComplete function, this is where I would create my loader.
03:07But since I'm going to need to be able to access this loader from outside of
03:12this event handler, I am just going to go ahead and create it outside of this function.
03:16So it's available anywhere on this timeline.
03:19So I am going to say var l is equal to Loader.
03:22Okay so now in the onComplete, I've already created the loader here.
03:28So now I can just do what we did in the earlier tutorial, which is to call
03:32loadBytes, and then get e.target.data and add that loader to the display list.
03:41So we could test it to make sure it's working here.
03:46So now when I click Load, oh, and the one thing that I did forget is I need to
03:50call fr.browse in here, which is very important or you are not going to see the
03:56Browse dialog window.
03:57Let's try that again and click Load and now I've actually put an image in here,
04:04of course, of my cat.
04:05It's a JPEG file, so I'll just select that and now it's actually this in.
04:09Now you can tell that it's actually covering up my UI components, so that's not going to work.
04:14So I need to actually just move this a little bit.
04:16So before I add it to the display list, I'll just say l.x and maybe we'll move it
04:22over 50 pixels on the x. l.y. Let's move it 100 on the y and then it should be out of the way.
04:30So I'll select that again and probably moved a little too much.
04:33Let's back that off a little bit.
04:35So we'll say 25 and 50, and we load that in.
04:43That looks about right now.
04:44Okay, so now I have the image inside of here. Now when I adjust this slider,
04:48I need to apply that Shader filter to this image.
04:52So inside of the onChange event, again, this is fired anytime the slider is changed.
04:57I am going to come down here and I am going to set l.filters is equal to filter.
05:07That's essentially going to set to shader filter to be the filter for my loader.
05:12I am going to try that now and let me load in the image and now as I change it,
05:20you can now see I can apply that waterfall filter to this image.
05:24Okay so now the last step is let's say I get the effect I'm looking for,
05:29maybe just ears and now I want to be able to actually save this to the user's hard drive.
05:35Again, this is going to be a similar process to what we did in the last tutorial.
05:39So now I want to come into the saverClick function and now inside of here like
05:45we did in the last one, we're going to use the PNGEncoder class.
05:48So I am going to need to import that.
05:50So we're going to come up to the top here and say import com.adobe.images and
05:57I'll just import all the classes in there, just to save time.
06:01And when I come down here, I am essentially going to follow that same thing.
06:05I am going to create another FileReference = new FileReference.
06:14Now I need to create a BitmapData.
06:16So var bmd for BitmapData is equal to new BitmapData and now I want this to
06:24be the same width and height as my image.
06:27So for right now I'm just going to figure out what it is instead of
06:31actually trying to read it. So it's 500x334.
06:34Okay now I actually want to draw the contents of that loader.
06:43So I am going to say bmd.draw and I want to draw l. So now what I want to do is
06:53I want to create a Byte Array, so ba for ByteArray = PNGEncoder.encode and pass
07:05in that bmd BitmapData.
07:08Lastly, I just want to say fr.save to initiate the Save action and I want to
07:13save that ByteArray.
07:15Okay so let's test it now.
07:17So I am first going to load in my image and I am going to manipulate it the
07:22way I want it, so maybe just so the nose streaks like that and then I want to save this file.
07:29So I'll just save it to the desktop as bea.png and click Save.
07:36So now when I go out to the desktop and we could see a PNG file has been
07:42generated and we have our manipulated image.
07:46So essentially this whole workflow of taking the image locally from the user's
07:50hard drive, manipulating it and saving it back out, is now very easy to do.
07:55Again, there are no real security implications to this because as you can see
08:00for both the Load operation and the Save operation I was prompted to choose a
08:05file to load and then prompted for a file name and location in which to save my file.
08:11But these new features of the FileReference class make it much, much easier for
08:15you to deal with your user's local files.
Collapse this transcript
6. New Drawing APIs
Copying graphic objects
00:00So one of the areas in Flash Player 10 has been changed pretty dramatically
00:04is the drawing API.
00:06Now there has been a host of new APIs that have been added as well as the
00:11performance of the API has also greatly been increased.
00:15So in this tutorial, I am going to show you one of the new features and that's
00:18the ability to copy graphical objects from one display object to another, which
00:25can be really helpful so you don't have to repetitively write drawing API code.
00:30So I am just going to create a blank ActionScript 3 document here.
00:34Now everything we're going to be doing in this is going to be in the Actions panel.
00:38So I'll just create a locked actions layer, like I always do for it to hold the
00:41ActionScript and I'll open up the Actions panel.
00:44So what I am going to first is I am just going to create a just a random kind of
00:49shape with the drawing API.
00:51Now a little known thing that people don't seem to use that often is when they
00:55wanted to draw things using the drawing API they will usually create a sprite.
01:00Well, a sprite is good but if you just want to draw a graphic the best thing to
01:05use is the shape class.
01:07The shape class is essentially just that.
01:09You can just draw into it, but you can't add event listeners to it.
01:14You know it's not interactive, but if you just need to draw graphics
01:18actually there is a lot less overhead than using a sprite.
01:21So that's all I am going to do here in this is create a new shape and now I am
01:29going to set up the graphics object.
01:31So I am going to s.graphics and I'll set the lineStyle and I am just going to
01:37set it to a thickness of five.
01:39I'll leave everything else at the default.
01:41So now I am just going to create a curve here.
01:44So I am going to s.graphics.curveTo and to this function we need to pass in two
01:52control points, and pretty much it's just going to be a random shape here.
01:57So I am going to put in 200, 50 for the control points and then for the anchor
02:01points I am going to put in 150, 120.
02:05Now this could be anything.
02:06It's really not the purpose of this tutorial to draw some masterpiece.
02:11So now what I want to do is actually position that shape object in the center of the stage.
02:15So I am just going to s.x and since I know the width and height of my stage,
02:22I am just going to split them in half.
02:23So I am going to put 275 for the x and for the y, I am going to put 200.
02:31Lastly I am going to add that to the display list.
02:35So if we test it now,
02:37we can see I've this kind of random curve here added to the display list.
02:43Well let me actually put a button in here.
02:46So I am going to go on to Components panel and I am just going to go into
02:50User Interface and just drag a Button out.
02:54And I need to actually create a layer for this.
02:55This will make it easier for you to see.
02:58So I am going to drag that button now and we'll give this an instance name.
03:03I'll just call it copy and I'll just change the label on this to Copy.
03:13So now every time I click on this Button, we're going to copy that shape or the
03:17graphics that are in that shape and we're going to rotate it to create kind of a
03:21circular effect here.
03:22So let me go back to the actions and now I am going to set up an event
03:27handler on the button.
03:28So it has an instance name of copy.
03:30So addEventListener and I want to respond to MouseEvent.CLICK and I am going to
03:41make the function name be onClick. [00:03:44.00 So let's create that function and the event type is going to be MouseEvent.
03:49Not going to be returning anything here.
03:54So every time I click on this button, I essentially want to create a new shape
03:58and I want to copy the graphics object from this shape into this new shape.
04:03So I am going to create a new shape. I'll call it ns for new shape.
04:07It's going to be of type Shape = new Shape.
04:12So now in order to copy the graphics from this shape into my new shape all I have
04:17to use is the copyFrom method of the graphics object.
04:21So I can say ns.graphics.copyFrom and now I pass in the graphics object that I
04:30want to copy from and that is s.graphics.
04:33Now what I want to do is actually each time I click or create a new one
04:37I actually want to rotate that shape a little bit.
04:41So what I am going to is come out here and just create a variable called count,
04:46just make it of int, and every time I create a new shape, I am going to
04:51increment this value, so that I know how much to rotate the new shape by.
04:55So every time I come in, I am going to say count += 10.
05:01So it's essentially every new shape is going to be rotated 10 degrees more than the last shape.
05:06So to rotate it that's easy.
05:07I can just say ns.rotation = count.
05:12Okay so now again, just like I did with this shape, I want to put it in the
05:16center of the stage.
05:17So ns.x = 275, ns.y = 200 and now I just need to add it. addChild(ns).
05:31So now let's test this and here we can see I've my single shape and when I click
05:36on the Copy button, it's creating a new version of that shape.
05:40Copying the graphics from the original shape and rotating it.
05:44So it kind of creates this pinwheel effect.
05:48So again, the main benefit of this copyFrom method is that, let's say I drew
05:52something that actually was really complex in shape and I didn't want to have
05:57to redraw everything again when I created another shape.
06:02So I can quickly just copy the graphics object from one display object to another.
Collapse this transcript
Creating bitmap strokes
00:00So Flash Player 10 also brings with it the ability to enhance the way in
00:05which we draw strokes.
00:07So we can now do bitmap and gradient strokes using the Drawing API.
00:12So in this tutorial I am going to show you how we can do bitmap strokes.
00:15So you can open up the bitmap_strokes. fla file from the Exercise Files, and
00:22essentially this is just a blank ActionScript 3 document, but you can see in the
00:26library I have this bitmap here.
00:29And if I go to Properties and we can see it's just a bitmap with
00:33horizontal black stripes.
00:35And it's at 1000x1000 here, and also if we go into to the Properties and
00:41if we come into Advanced, I have also set it to Export for ActionScript with a
00:46class name of lines.
00:48So we are actually going to attach this at runtime.
00:51Okay so now I have a locked actions layer.
00:54So I am going to highlight that first keyframe in the actions layer and open
00:57up the Actions panel.
00:59Now like I did in the last tutorial we are actually going to create a new shape
01:02object in which to draw to, and as I mentioned before this has less overhead
01:07than using a sprite or a movie clip.
01:09So I am going to say var s, it's going to be of type shape is equal to new shape,
01:16and one of the really important things you are going to use in bitmap line
01:20styles is that you first need to set the thickness of the line using the
01:25regular lineStyle method.
01:27So I need to s.graphics.lineStyle and I am going to give it a thickness of 10.
01:33So again you need to set that first or else when you set the bitmap style
01:39for the line, if we didn't set the actual line style first, you wouldn't have
01:43any stroke whatsoever.
01:44So now I am ready to actually setup the bitmap style for the line.
01:50So again I am going to say s.graphics and now
01:53I'm going to call the lineBitmapStyle method.
01:58Now to this we actually pass in a bitmap data instance.
02:03Now that line's image that I have in the library actually contains bitmap data.
02:08So all I need to do to pass into this is say create a new lines object.
02:13Now to the bitmap data I need to pass in a width and height.
02:17It doesn't really matter in this particular situation.
02:20So I can just pass in one and one.
02:22It doesn't really make a difference here.
02:24So now I have passed that in to the lineBitmapStyle method.
02:29And now finally I just need to add this shape to the stage to the display list using addChild.
02:35So I am going to create just a very simple drawing application where wherever I
02:40move my mouse on the stage I'm going to draw a new line to.
02:44So I am just going to say stage. addEventListener and I want to respond to
02:51the MOUSE_MOVE event, so MOUSE_MOVE, and I am going to have that call a
02:58function called onMove.
02:59So anytime I move my mouse on the stage it's going to call this onMove function.
03:05So let's create that now, onMove, the event object is of type mouse event and
03:11we're not returning anything.
03:12So all I need to do in here is just the typical drawing API code.
03:17So I am going to say s.graphics. lineTo and I am going to draw a line to
03:22wherever my mouse is.
03:24So mouseX and mouseY.
03:28And again any time you using the mouse move event, you always want to call
03:32updateAfterEvent on your event object here.
03:35So e.updateAfterEvent.
03:41So now we can test this and you can see now wherever I move mouse it's actually
03:47drawing the stroke using that bitmap that I have in the library.
03:53Now it's important that your bitmap actually be large enough.
03:56So if my bitmap was only say this wide,
04:00I would actually see a break here, so it wouldn't look exactly seamless
04:04like you're seeing here.
04:05So I need to make sure your bitmap is large enough to cover whatever area
04:10you're actually going be drawing, but that's the basics of creating a bitmap
04:15stroke in Flash Player 10.
Collapse this transcript
Drawing paths
00:01So the traditional way of using the Drawing API inside the Flash Player is that
00:05you draw things one at a time.
00:07So, typically you would do things like move to, line to, line to, line to, where
00:13essentially you're drawing each segment of a shape separately.
00:17Well, in Flash Player 10 we now have the ability to also do object based drawing.
00:23So this is the ability to essentially create an array of points and then we can
00:29draw them all at the same time as a path.
00:32I am going to show you how to do that in this tutorial.
00:35So I am just going to create a blank ActionScript 3.0 document and I will just
00:40again like always, I'll rename this to actions and lock it.
00:45So what I am going to do here is just open up the Actions panel. Everything
00:48we're going to be doing is going to happen inside the Actions panel here.
00:52Now what you need to do in order to create paths in Flash Player 10, you need
00:56to actually use a new class or a new data type that's been introduced which is called vector.
01:02Now I also have a tutorial later in this title which will go into a little more
01:06detail about the vector class and data type, but essentially a vector is just an
01:11array that can only hold a single type of data.
01:15So in the regular array in ActionScript it can hold strings, number, movie
01:21clips, all in a single array, while a vector is just literally an array that can
01:27only hold a single type of data that you tell it.
01:31The benefits are pretty great when it comes to performance, because Flash
01:35doesn't have to worry about testing what's inside of that array to see what type it is.
01:41It knows what type it is when it's inside of a vector.
01:44So the way in which you draw paths is you need to create two vectors. One holds
01:49the actual commands that you want to use and this is common commands that you
01:53use to like move to, line to, curve to and then you need to create a second vector
02:00which is essentially the actual data for those commands.
02:04So for move to and line to, it's going to be a sequence of X and Y positions.
02:10Then when you have those two vectors, you then pass that to the drawPath method.
02:14So let's go ahead and get started.
02:16So I'm going to first create the vector that contains the commands.
02:20So I will just call it commands.
02:22Now this is going to be of type vector.
02:25Now here's where the syntax is different than an array.
02:28So we don't just need to data type it to a vector; we also need to tell it what
02:32type of object is going to be held inside of that vector.
02:35And to do that we put a period and then an open angle bracket and then we put in the data type.
02:42So the commands are just going to be integers, so I am going to put an int.
02:46Then I can close that angle bracket and then I need to say = new Vector and
02:53again put a period, angle bracket, the datatype, close the angle bracket and
02:58then close the vector.
02:59So now I am just going to copy this line and paste it underneath, and now I need
03:05to create second vector that's going to hold the actual data for the path.
03:09So I am going to rename this one to pathData and this is actually going to hold numbers.
03:17So this could potentially be floating point numbers here.
03:20So let me change that to Number.
03:22So, now I have created my two vector objects. Now I need to fill it with the
03:27actual information for my path.
03:29So I am going to draw just a simple triangle.
03:33So the vector has all the same methods that you used to with an array.
03:38So once you create a vector, you can basically use it just like you use the array class.
03:42So I am going to say commands.push, which is going to push some values into that vector.
03:50So now for the actual commands we want to use constants from the
03:55GraphicsPathCommand class.
03:57So GraphicsPathCommand and then inside of here, you can see constants for all
04:04the main Drawing API features that you're used to.
04:06So first let's do a Move_To command which is going to move us towards the
04:11center of our movie.
04:13Now essentially we just can copy this and just put in the other commands that I am going to use.
04:19So graphics command and I am going to do three Line_Tos.
04:24So I will paste that in, paste another one in and paste that last one in.
04:30So now, I have essentially put in the commands that I am going to use to
04:35draw this triangle.
04:36So now I need to do a similar thing for the actual path data.
04:40So I am going to say pathData.push and now here we are going to pass in
04:47obviously the X and Y positions for each of these calls.
04:51So first the Move_To, I am going to put it into the center of my Flash movie,
04:55which is 275x200, and now I just need to provide the X and Y coordinates for
05:01these Line_To calls.
05:03So I am going to go to (175, 100), then I am going to go to (370, 100) and then
05:12finally to (275, 200), which is going to bring me back to the center of my movie.
05:19So now at this point you may be asking, well, why would I do this?
05:22Why wouldn't I just create actual Move_To and Line_Tos using the typical Drawing API?
05:29Well, the performance is actually a lot greater when you use this method.
05:33So essentially you're creating all of these values for the shape, but you are
05:38only ever calling the Drawing API one time and that's what I am going to show
05:42you in a second, but this has much better performance than repetitively drawing
05:47each segment of a path separately.
05:50So now I have this data here. Now I need to just create a shape that I can draw into.
05:54So I am going to say var s: Shape = new Shape.
06:01Now I am going to set the line style of this.
06:05So s.graphics.lineStyle and I will just give it a line thickness of 5.
06:13Now I want to fill this just so we can see it.
06:15So I am going to say s.graphics beginFill and I will just give it a color of red.
06:21So I am ready to actually draw this path using these two vectors that I created.
06:28So to do that, it's simple.
06:30All I have to do say s.graphics.drawPath.
06:35Now it's asking me to pass in the commands and the actual data.
06:38So I will pass in that commands vector and then the pathData.
06:44Now finally all I need to do is to add this shape to the display list.
06:48So I will just say addChild(s).
06:51Now if I test it, you can see there's my red triangle on the stage.
06:57So now let's say this was a really complex object or drawing.
07:01So I wanted to actually change some of this data.
07:05Well, let me just create a simple mouse move event here on the stage.
07:09So stage addEventListener and I want respond to mouse event, the Mouse_Move event,
07:16and I am going to have this called a function called onMove.
07:19I will create that function really quick.
07:23The event object is going to be of type mouseEvent and we are not
07:28returning anything.
07:30So what I want to do is each time I come into the Mouse_Move event, I want to
07:33clear whatever graphics are currently inside of this shape.
07:37So to do that, it's simple.
07:39I will just say s.graphics.clear, and this actually hasn't been
07:44changed in Flash Player 10.
07:46It's still the way in which you clear graphic objects.
07:49But when I clear a graphic object, remember that it also clears the formatting.
07:53So I need to repeat these two lines, so that I can reset the line style and the fill style.
08:02So now what I want to do is to actually change some of the points inside of this
08:07pathData vector, so that it actually changes the shape.
08:10So here is where I can just manipulate this vector and all I am going to do is I
08:15am going to change this point to be my mouse X and Y instead of being hardcoded.
08:22So again I can access vectors just like I do arrays.
08:25So just say pathData, then I want to go to the first element in that array which
08:30is always represented by zero and I want to set that equal to mouseX.
08:37Then pathData, the second element.
08:40I want that to be mouseY.
08:41So now I've manipulated that vector and now all I have to do is just
08:46simply redraw that path.
08:50Again since I'm using a Mouse_Move event, you always want to call
08:55updateAfterEvent just so you have a good performance here.
08:57So it forces a refresh.
08:59Now if I test it, you can see that as I move around it's actually, that
09:04particular piece of pathData is actually being controlled by my mouse position.
09:08And again I didn't have to repetitively again call Line_To, Line_To, Move_To.
09:13But the main benefit of doing this again is performance, because while we are
09:17creating all these Line_Tos a Move_Tos here, we are only ever calling the actual
09:22Drawing API a single time and it has a lot better performance than doing
09:27multiple calls to the Drawing API.
Collapse this transcript
Drawing triangles
00:00So, one of the most important enhancements to the Drawing API in Flash Player 10
00:05is the new API that allows you to draw triangles.
00:08So if you've done 3D work before, you know that 3D objects, when you boil them
00:13down are nothing more than triangles.
00:16So this API is one that most people are probably not going to use on a daily basis.
00:21It's more of an advanced API, but if you're creating maybe some complex 3D stuff
00:26or you're writing a 3D engine, this API is going to come in tremendously handy for you.
00:32So I want to create a new blank ActionScript 3.0 document.
00:35I will just rename this layer to Actions and lock it.
00:39We're going to be doing everything inside of the Actions panel in this tutorial.
00:43So the first thing I want to do like I have done in previous tutorials in this
00:47chapter is just create a shape in which to draw my graphics into.
00:51So I am going to create a new shape called S. Now I'm just going to
00:56position this a little bit.
00:57So I am just going to say s.x = 125 just to move it on the X-axis a little bit.
01:03s.y = 50 just to push it down and finally I need to add this to the display list.
01:11So I am going to say addChild(s).
01:15In the last tutorial where we were actually drawing a path, we had to create two vectors.
01:19Well, when you draw triangles, it's a very similar thing. You need to create two vectors.
01:25I'll show you in the next tutorial when you actually want to map textures onto
01:29these triangles, you actually create a third vector.
01:32But for right now we need to create two vectors, one contains the actual
01:36points for where I want to draw the triangle and then the second is what's
01:41known as indices and it basically says for a certain triangle, which data
01:47points do I want to use.
01:49So, I am going to first create a vector called Points and again this is going
01:54to be of type vector and then I need to data type the type that's going to be
01:58inside the vector and that's going to be of type Number = new Vector, and again
02:04I need to do the same thing here.
02:06It's going to be of type Number and now I am just going to copy this and paste it in.
02:13This one is actually going to be the indices.
02:16So I will rename it to indices and this can just be an int data type, since
02:23these aren't going to be floating point values.
02:25So now I have created the two vectors.
02:27Now I actually need to populate it with the data for these triangles.
02:31So I am going to draw two triangles that are essentially going to make up a square.
02:37So what I want first to do is deal with the points vector.
02:39So I am going to push a set of values into the points vector.
02:43Now these values are going to be the actual points that make up the triangles.
02:49So I'm going to start at 0.00 and again this is the location inside of my shape.
02:56So I am going to a start at the upper left-hand corner at 00, then I am going to
03:00go over to (300, 0).
03:05So I am going to make a triangle that's 300 pixels wide.
03:07So now I am along the top of the triangle.
03:11Now I am actually going to go to (0, 300).
03:15So now this is bringing it down to the bottom left, so you can kind of visualize
03:20the triangle that I am creating here.
03:22Now what I want to do is for the second triangle,
03:27all I need to do is to provide one point and that's because the second triangle
03:32can actually share some of the other points that I've created for this first
03:37triangle and this is where the indices actually come in.
03:40So the only point that I need to create for the second triangle is the
03:46bottom right-hand corner, because I can use the existing points from that first triangle.
03:52When we actually test this, I'll be able to explain it a little bit better.
03:55So all I need to do is to put in a single point for that second triangle which
03:59is the bottom right-hand corner.
04:00So now I need to put in the values for the indices, so again indices.push.
04:08Now what I'm saying is for each point in the triangle, I want to provide a
04:14number that references which point in the points vector I actually want to use.
04:20So for the first triangle I want to use 0, 1, and 2.
04:25So, again this is the first point which is referenced by 0, here is the
04:31second one which is referenced by 1, and here is the third one which is referenced by 2.
04:36So this is essentially just saying for each point in the triangle which data
04:40point up here do I want use?
04:43Now for the second triangle, again I want to reuse some of these data points.
04:48So what I am going to do is put in 1, so I want to start with this one
04:53right here, 2 and then 3.
04:57So for this second triangle, I'm reusing two of the points up here.
05:02The only one I'm adding is that third one which basically creates the
05:06bottom right-hand corner.
05:07But let's finish this up so we can actually see it, so I can explain it better.
05:11So now before we actually draw this triangle, I need to set up the graphics
05:15object like we've done before.
05:18So I am going to say beginFill. I am going to give it a red fill.
05:22Now I am going to give it a stroke just so we can visualize the actual triangles.
05:27So I am going to say lineStyle and I will just give it a thickness of 1.
05:33And now we are ready to actually draw these triangles.
05:35So I am going to say s.graphics and now I just use the drawTriangles method.
05:42And into this I need to pass in those two vectors that I created, first the
05:46points and then the indices.
05:49So let's test this now.
05:51Now you can see here is my two triangles and we can tell because of the stroke
05:56how these are setup.
05:57So when we actually look at the data points now, here's this first point which
06:03is at (0,0), then I go over to (300, 0) which brings me here.
06:08Then I go to (0, 300) which brings me down to here.
06:13So that essentially finishes this one triangle here.
06:17Now the second triangle, I didn't have to put in these two points here, because
06:21I already have them.
06:23So the second triangle can share the points with this first triangle.
06:27The only point I needed to add for the second triangle is this one down here.
06:32So this method of sharing points between different triangles greatly
06:37decreases the amount of overhead and you could continue now building an
06:42entire mesh in this fashion.
06:44So the indices are essentially saying for this triangle I want to use this
06:49point, this point, and this point.
06:53Then for the second triangle, I want to use this point, this point, and this point.
06:59Then we simply pass these two vectors to the drawTriangles method to draw them.
07:05So this was drawing triangles without any textures on them, but the real power
07:09comes in when you want to apply a bitmap texture to your triangles and that's
07:14what I am going to show you in the next tutorial.
Collapse this transcript
UV texture mapping
00:01So in the last tutorial I should you how to used the new drawTriangles method to
00:05actually draw some triangles made up of two vectors.
00:10Well, in this tutorial we are going to expand on that and actually map a bitmap
00:14texture to those triangles, and that's really where the power of this new
00:17triangle API comes in.
00:19So you're going to open up the uv.fla file from the Exercise Files and this is
00:25essentially the exact thing that we created in the last movie.
00:29So we have our shape, we have our points and indices, then we simply draw the triangles.
00:35Now I've also included an image of my cat and it's in the library here.
00:40If we go to Properties, we can see it's set to Export for ActionScript with
00:45a class name of bea.
00:48So let's go back to the ActionScript.
00:51So what am I going to do first of all is we need to create like I mentioned
00:55before another vector which contains be uv texture points.
01:01I will explain what that is in the second, but first let's just create that.
01:05So I am just going to copy this vector and paste it in and I am just going to call it uv.
01:12Now the type that it's going to hold is a number, because these can actually be
01:18floating point numbers rather than integers.
01:21Now here where I push the actual points of the triangle on to the indices I want
01:26to do the same thing for the uv points.
01:29So I am going to say uv.push.
01:33So the way in which uvs work is I have a bitmap which is that images that's in the library.
01:39Now for each of the points that are inside of this vector, I need to tell Flash
01:44which parts of that image that's in the library map to each of these points, and
01:50the way in which we do that is providing a number between zero and one.
01:54So let's take the X for example. 0 would be the left side of the image,
01:591 would be the right edge of the image and I could map to smaller points, if I
02:05just provide a decimal like 0.5 would actually be the center of that image
02:10that's in the library.
02:11So for this first point, remember that's the upper left-hand corner of the
02:16first triangle, that maps to the upper left- hand corner of the image that's in the library.
02:22The second point, which is (300, 0), that's the top right-hand corner of my square,
02:28which is made up of the two triangles, that's going to be the right edge
02:34on the X-axis and 0 on the Y-axis.
02:37So it's going to be the upper right-hand corner of the image that's in library here.
02:42Now for the third point that's (0, 300) and now the uv points for that are
02:49going to be (0, 1).
02:52So this is an immediate bottom left- hand corner of the image in the library.
02:58Now the last point which is (300, 300), well, that's going to be obviously at
03:03(1, 1) which is the bottom right- hand corner of the image in the library.
03:08So again we are just telling it, each of these points, where it is actually mapped to in
03:13the bitmap that we are going to texture this with. Okay.
03:15So now if I come down, here where I'm setting up the graphics object I am
03:21creating a beginFill.
03:23So this is a solid color fill.
03:24What I need to do is I need to change that to beginBitmapFill.
03:31And now I need to give some bitmap data of what I want to fill it with.
03:35So I have that image in the library with an export name of bea.
03:38So I am going to say new bea and I am going to give the width and height of 300,
03:44because that's the width and height of the actual square that I'm creating out
03:48of those two triangles.
03:49So I can close this now and I leave the lineStyle at 1.
03:54Now here under drawTriangles before I only passed in the points in the
03:59indices. Well, now we actually have uv texture coordinates, so I just need to
04:03also pass in that uv vector.
04:06So let's go ahead and test this now and we can see that image has now been
04:11textured to those two triangles.
04:13Well, we can visualize this a little bit better if we actually manipulate the
04:18points of that triangle.
04:21So what I am going to do is to create an event listener on the stage.
04:26So addEventListener.
04:27I am going to respond to the Mouse_Move event, call a function called onMove
04:32and I can create that function now.
04:35The event object is going to be of type mouseEvent.
04:41So all I want to do inside of here is much like we did when I showed you how to
04:45draw paths, we are just simply going to first clear the graphics object.
04:51So graphics.clear and then since it removes the formatting, we just need to
04:57reapply this and now inside of here we basically want to change two of the
05:04points in these triangles.
05:06I am going to change the fourth and the fifth point, which is the
05:08bottom left-hand corner.
05:11So all I have to do to do that is to say points and it's actually the fifth and
05:16sixth point, but it's represented by four and five.
05:18I am going to say s.mouseX.
05:23Then point,s the sixth element is equal to s.mouseY.
05:29Now all I have to do is just to call that drawTriangles method again.
05:33Now let's test that and now you can see what's happening.
05:38I have the image that's actually mapped into these two triangles, but because I
05:43have those uv texture coordinates as they move this lower left-hand corner of
05:47this point, the texture is always kind of contorting itself to fit within this
05:53square, even when I go outside of here, you can get some kind of funky effects.
05:56But this is how you can see how an actual 3D engine works.
06:00If I wanted to rotate this on the Y- axis, well, I could manipulate this point
06:05and the upper left-hand corner point, continuously animate those to create some
06:10animation, but again once you set up a texture coordinates, any adjustments that
06:15you make to the actual triangle points, that texture will always adjust itself
06:20to fill in between those triangles.
Collapse this transcript
7. Additional Features
The new Vector data type
00:00So if you watched the chapter on the changes to the drawing API, you'll have
00:04seen the use of vectors come up often.
00:07So we wanted to talk a little bit more about this new vector data type.
00:11So vectors are essentially like the regular arrays that you have in ActionScript
00:153.0 except that they can only contain a single type of data.
00:19So in a regular array I could have string, an integer, a movie clip. Inside of a vector
00:25I can only have a single type.
00:27The benefits of this are essentially two things. The first is type safety.
00:32So if you want to make sure you only have a single type of data, using a vector
00:36is a way to do it, because it will actually give you errors if there are
00:39multiple types of data in it.
00:41The other big benefit is performance. Since you are telling a vector that you're
00:46only to put a single type of data into it, Flash doesn't have to do as much work
00:51when it comes to dealing with it.
00:52It doesn't have to test the contents to see what type of data it is and that can
00:56greatly increase performance.
00:58So I am just going to create a blank ActionScript 3.0 document and just open
01:01up the Actions panel.
01:03The syntax for creating a vector is a little bit strange.
01:07It looks a little different than anything you've seen before in ActionScript 3.0.
01:11So I will just create it, I will call is v. The first part is simple.
01:15I data type it to vector.
01:17That's data typing the actual v variable here.
01:20But I also need to specify data type for the type that's going to be inside the
01:24vector and for that I hit a period and an open angle bracket.
01:29Now for this I can put in any data type, but let's say I put in integer.
01:33So now I've created a variable called v which is of type Vector and I've also
01:38said that inside of that vector can only have integers.
01:42So again I create it with a new keyword.
01:44So I just say = new Vector, and again I use the .< to tell it that that's an integer.
01:52So now I can use this vector data type pretty much the same exact way that I
01:58deal with regular arrays.
02:00So I can say v, go to that first element in the array, put in 200, because again
02:06it's expecting an integer, v, I will put in the second element, then put in 50,
02:12and now I can trace out this vector.
02:14You can see down here in Output panel 200, 52.
02:19So very similar to using a regular array.
02:22Now let's say I came in here and I changed that second element to a "Hello," a string.
02:28Now test it and you can see I've got a compile error down here and implicit
02:34coercion of a value of type String to an unrelated type int.
02:38So here it's not allow me to compile, because they're two different types of
02:43content now inside of this vector.
02:45So if change that back to 50, I am now complying with essentially the definition
02:49of what a vector is.
02:51So now there are a couple of parameters I can actually send to the
02:54constructor for the vector.
02:56The first is if I want to have a predefined number of elements in the vector and
03:02I don't want to go over that.
03:04So say I only want to have two elements in this vector, I can put in a 2 there
03:09and I can say whether this is a fixed number or not.
03:13If I say true for that second parameter here, I'm not going to be able to add
03:18more than two items to this vector.
03:21So if I test this, we can see this works, because I only have two elements.
03:25If I come down here and add another element, let's say 30,
03:30we can see here now I get a runtime error that says the index 2 is out of range 2.
03:36So it's essentially trying to go to the third element, but I told this vector
03:40that it could only hold two elements here, not three.
03:44So those are just some of the things to look out for when you're dealing with vectors.
03:48Let me get this back to the start here.
03:51Now another thing that's important to note is let's say I do something like this.
03:55Say for the type I want to say DisplayObject.
04:00Now remember DisplayObjects are things like movie clips, sprites.
04:03So let's say I put inside of here Sprite.
04:07We can see I get another runtime error that basically is saying that it can't do that.
04:12So even though Sprite is a subclass of DisplayObject, I can't actually put that in here.
04:18So whatever value I put here needs to actually be put here.
04:22So these need to be identical.
04:24So it doesn't care that Sprite is a subclass, because it needs to be exactly the
04:29same when I do that.
04:31So again that's the basics of working with the Vector class.
04:33It's not really much different at all from the Array class, but anytime you have
04:38an array and it's only going to hold a single type of data, you should always use vector,
04:43because it's always going to run faster and be more performing.
Collapse this transcript
Device font animation
00:00So another new feature in Flash Player 10 that's sure to make every Flash
00:03developer happy is that now device fonts can do all of the same things that
00:08embedded fonts can do.
00:10So whether that be changing the opacity or animating them.
00:14In previous versions of the Flash Player, essentially, you couldn't do any of that
00:18and it was pretty frustrating to deal with and it led to a lot of times
00:21where you embedded fonts, simply because you needed to animate them.
00:25So I am going to create a blank ActionScript 3 document here and I'll just get
00:29the Text tool and I will put in some text, I will just put Hi there, and let me
00:36make this a Dynamic Text field.
00:39So it already is here, Dynamic text, and I am using just a device font.
00:44So I am just going to use the Sans device font.
00:46And I have a pretty large size here just so we can see it.
00:51So now, what I want to do is first let's change the Publish Settings to Flash
00:55Player 9, so we can kind of see how it was before.
00:57So we go into the Profile, changing the player to Flash Player 9 and click OK.
01:02So, now I am going to take this text field, I am going to give an instance
01:06name of dt, so I can reference it from ActionScript and I will just open up the Actions panel.
01:11So now, I am just going to create an event listener.
01:14I am going to create an enter frame event, so event.ENTER_FRAME.
01:18I have it call a function called loop.
01:20I will create that now.
01:28Okay so inside of here, all I want to do is to fade out that dynamic text field.
01:33So I am going to say dt.alpha and every time I come into the Enter frame,
01:39I am going to subtract a certain amount and I am going to subtract 0.01.
01:44Remember in ActionScript 3 alpha values go from 0 to 1, not 0 to 100.
01:48Okay, so now that I have this, let's go ahead and test the movie and we can see
01:53it's not fading at all, and here is the problem again with Flash Player 9.
01:57It's that it can't do that with device fonts.
02:01So, now let's go ahead and let's change the Publish Settings back to Flash
02:05Player 10, click OK and now test the movie and now you can see our device font
02:12is actually fading out the way that it should.
02:15So again, just a small feature but it's one of those things that developers and
02:19designers have wanted for a long time and it's finally here in Flash Player 10.
Collapse this transcript
Enhanced hardware acceleration
00:00So, one of the things that the Flash Player team is always trying to do is to
00:04offload as much of the processing as possible to the user's graphics hardware.
00:10Now this is particularly challenging because Flash Player has to be so cross-platform.
00:14I mean it can't really be seen to have any difference among the
00:17different platforms.
00:19But in Flash Player 10 there are some new features as relate to hardware
00:22acceleration that I want to talk about.
00:25So, essentially we have two new Wmodes.
00:27Now WModes are things that you put in your HTML embed code.
00:32Now in Flash CS4 in your Publish Settings, you also have a UI to select one
00:37of these new WModes.
00:38So the two modes are GPU and Direct and I'll talk in a second about kind of what
00:44the differences are between those.
00:47So, again the primary use of these two new WModes is to try to take advantage of
00:51the user's graphics processor and of course that frees up more resources for you
00:56to do cool stuff in your Flash projects.
00:59So, there's always a software rendering fallback.
01:02So, if you enable one of these WModes and the user doesn't have graphics
01:06hardware that's capable of supporting it, it's always going to go back to the
01:10traditional software rendering that the Flash Player does.
01:13Now one of the things to note is it's not always faster.
01:17In fact in many, many cases it will actually cause your content to run slower.
01:23So, these two new WModes, you don't just want to enable them all the time
01:27thinking your stuff is going to run faster. You need to be careful about the
01:30situations in which you use them.
01:32So let's now take a look at WMode = Direct. So the Direct WMode essentially
01:38tries to use the fastest rendering path to the screen that there is possible.
01:43Now, when it does this, it actually bypasses the browser rendering.
01:48So any additional things where the browser kind of interacts with the Flash Player
01:52and these are things like compositing HTML menus over your Flash content,
01:58things like that will actually be ignored by the Flash Player.
02:01So, the main use for WMode = Direct is for basic video playback.
02:06So if you are playing back say some HD video, there's not a lot of other things
02:10going on in your Flash movie, you are going to see some enhanced performance if
02:14you use WMode = Direct.
02:16But primarily this is only good for displaying video.
02:20And again, just keep in mind that you are going to lose some features like HTML
02:24menus and things like that.
02:25Wmode = GPU, in this Wmode, it tries to do all of the compositing using the
02:32user's graphics card.
02:34Whenever possible any video is actually scaled with the GPU.
02:39On Windows, the technology it uses to do this hardware acceleration is Direct 3D
02:44and on OS X and Linux it uses OpenGL.
02:48So, this is again a good step forward in hardware acceleration for the Flash Player,
02:53but this definitely is not an enhancement that is necessarily going to
02:57make your content run faster.
02:59In certain cases, it definitely will, but you definitely need to be careful
03:03and just like always, you want to test your content when you use one of these
03:07new WModes just to make sure you actually are seeing a performance increase
03:11rather than a decrease.
Collapse this transcript
New cursor features
00:00So Flash Player 10 also includes some enhancements to the mouse class and
00:05specifically when you're dealing with cursors.
00:08So we can now at runtime programmatically change the cursor type.
00:12Now I will show you how to do that in this tutorial.
00:14So I am going to create just a blank ActionScript 3 project and I am just going
00:18to open up the Actions panel.
00:20We will do everything here in the Actions panel and what I am going to do is
00:24just create a simple application that's going to just basically cycle through
00:28the different cursors.
00:30So I am going to create a timer.
00:32So var t = Timer, and to the constructor I need to pass in how often I want
00:39this timer to fire.
00:40I will just put in 100 milliseconds, so 10 times a second.
00:44Then I need to add an event listener of TimerEvent.TIMER.
00:50I'll have it call a function called onTimer and then I'll just start that timer going.
00:55So let's create that function onTimer, and I am not going to be
01:02returning anything.
01:04I want to actually cycle through the different cursor types.
01:07So to do that, I am going to create an array down here.
01:10I'll just call it C and datatype it to an array, and now I will just pass in the
01:16different cursor types.
01:17So the different cursor types are in a class called MouseCursor, dot, and then we can
01:22see the different cursor types that we can choose.
01:25So I am going to have MouseCursor. ARROW, MouseCursor.BUTTON, which is
01:32essentially just the hand cursor, and then we will do one more MouseCursor.IBEAM,
01:39which is the text editing cursor.
01:41So I am going to close that array, and now every time we come into this timer,
01:45I am going to change the actual cursor that the user sees and this is the new
01:50feature that's in Flash Player 10.
01:51So to do that, all I have to do is to say Mouse and then I want to set the
01:56cursor property of the mouse.
01:59So what I need to do is to pick a random element from this array.
02:04So let's do that really quick.
02:06So I am going to say Math.random()* 3.
02:10That will give me a random number between 0 and 3.
02:14Now, in order to make this be a random integer between 0 and 2, which is what I
02:19need for an array, I am just going to wrap that in a Math.floor call.
02:25Then now I just want to say C and I want to go that random element in that array.
02:31So if I test this now, you can see that as I hold my mouse there, it's actually
02:36creating a random cursor or switching to a random cursor 10 times a second.
02:41So this could be really good if you want to confuse your users as to what's going on.
02:45You could be just randomly swapping out the cursor type as they were trying to
02:49interact with your application.
02:51But again the main purpose of this is let's say you wanted the text editing
02:55I-beam cursor when you went over a button for some reason.
02:59You could now do that pretty easily.
03:01So I could even make this faster, and you can see this thing is flickering on
03:05and off pretty quickly here.
03:06So again, that's just a simple new feature in Flash Player 10, but it could come
03:10in handy if you want to dictate a specific cursor.
Collapse this transcript
Speex audio codec
00:00So Flash Player 10 also brings with it a new microphone codec that you can use
00:05which is called Speex.
00:06Now the old microphone codec, which is Nellymoser, that is still in the Flash Player.
00:12So this is an additional codec that you can choose.
00:15So the benefits of Speex, and you can tell by the name that it's specifically
00:20geared for speaking.
00:21And it does things like detect when there is no speaking going on and will
00:26actually reduce the bandwidth because there is nothing that actually needs to be
00:29sent if the person is not speaking.
00:31So it's a better quality codec to use if you're just doing voice, which you
00:37traditionally are when you're dealing with the microphone.
00:39But again, it has some nice kind of advanced features specifically for speaking.
00:44So I will just quickly show you how you would enable that.
00:46So I just created a blank ActionScript 3.0 document.
00:49I am just going into the Actions panel and traditionally when you're setting up
00:52a microphone in Flash, you just create a variable of type Microphone.
00:57And then you call the Microphone. getMicrophone static function and you could
01:03pass in an index if you have multiple microphones, but to get the default you
01:06just pass in nothing.
01:08So this is still the way you set up a microphone.
01:10So the new step in which you could do is you can actually say Microphone.codec =
01:21SoundCodec, and here you can choose between Nellymoser and Speex.
01:26Now Nellymoser is the default so there's really no need to set that unless
01:31you've previously set it to Speex and now you want to change it back.
01:34But to set up the Speex codec that's all you do.
01:36So essentially you just set the codec static property of the Microphone class
01:40equal to a constant from the SoundCodec class. In this case it's Speex.
01:45So again, you always want to when you are trying different codecs test it out
01:49with whatever application you're using it for.
01:51But again, if you're doing just a lot of speaking stuff, you will find that the
01:55bandwidth can be greatly reduced if you use the new Speex codec.
Collapse this transcript
Partial full-screen keyboard support
00:00So one of the major limitations of previous versions of the Flash Player were
00:04that when you were in the browser and you went into Full Screen mode,
00:08you couldn't accept any keyboard input.
00:11This basically was there for security reasons because theoretically somebody
00:16could launch a full screen Flash application that looked like the user's
00:20browser, and then direct them to enter in their personal details and
00:25basically things like that.
00:26Well, in Flash Player 10 that restriction has been lessened a little bit, and
00:31we can now actually accept non- printing keys into our Flash application.
00:36So these include the Spacebar and the arrow keys.
00:39So now it's much more possible to create a full screen game in the browser
00:44using Flash Player 10.
00:46So go ahead and open up the fullscreen.fla file from the Exercise Files.
00:51This is a really simple application. We just have a single movie clip with an
00:55instance name of guy, and it's just this little binary guy down here.
01:00If I open up the actions in the Actions panel, essentially what this application
01:04does is the main part of it just listens for the left and the right arrow key,
01:10and depending on which it moves the little guy on the X-axis.
01:14So if I test this, you can see as I hold down the right arrow key,
01:18it's moving on the right.
01:19The left Arrow key, it's moving on the left.
01:21So basically, the start of a game here, pretty lame game nonetheless.
01:26So now what I've also added here is when you click on the stage, I'm actually
01:31making this application go into Full Screen mode.
01:34Now, when you're testing it inside of Flash, that's not going to work.
01:37So you actually need to test the SWF in order to see that.
01:41So I'm going to go into the Exercise Files where this FLA is.
01:46I'll open up the SWF file, and here you can see again I'm able to hold down the
01:51arrow keys in order to move this little guy.
01:54If I click on the stage, now I'm actually in Full Screen mode.
01:57Of course, I can still accept keyboard input.
02:01Now the area in which you couldn't do this was inside of the browser.
02:05So let's look to see how that's changed now.
02:07So I'm going to go to File > Publish Settings, and basically I'm going to
02:13publish the HTML version of this.
02:15So I'm just going to click Publish and click OK.
02:19Now we'll look inside of this folder, and it's generated the HTML file for me.
02:24So I'm going to go ahead and just open this up.
02:27I'm going to open it up in BBEdit.
02:28You can open it up in any text editor that you want.
02:31So, now this is the normal source that's generated by Flash.
02:35So what I'm going to do is I'm going to strip this down quite a bit, so I'm
02:37going to get rid of this noscript tag and just use this from my embed code and
02:43I'll get rid of all of this.
02:44You should be using SWFObject anyway to embed your Flash. Don't rely on the
02:49code that Flash generates.
02:50So here is just the kind of classic Flash embed code.
02:54So now one of the things you're going to need to do is you're going to need to
02:56enable Full Screen in your actual embed code.
03:00So you can see here this parameter allowFullScreen, it's set to false.
03:04So what I need to do is actually set that to true.
03:08I also need to set it, if we come here in the embed tag, allowFullScreen, again
03:13it's set to false, so I'm going to set that to true.
03:16Okay, so I'm going to save this now, and let's go ahead and launch this in the browser.
03:23So when I launch this up, here we can see our little guy.
03:27Actually, before I go into to Full Screen mode, I'll show you.
03:29So here again, I can hold the Arrow keys down to move this little guy along the X-axis.
03:34If I click to go into Full Screen mode, you can see I can now also move it along the X-axis.
03:40This was something that wasn't allowed in previous versions of the Flash Player.
03:44Now one thing, which is kind of a bug it appears, is that I can't hold down the
03:49arrow key in order to repetitively fire that key down event, like I can just in
03:54the regular Flash Player.
03:55So I have to repetitively hit the arrow key, so just be wary of that limitation
04:01when you go Full Screen in Flash Player 10.
04:03Where here I can hold it down, when I go into Full Screen I have to repetitively
04:08hit that arrow key in order to trigger the key down event.
04:12So with this loosening of the security restrictions surrounding full screen
04:16keyboard input, it's now much more likely that you're going to be able to create
04:20more interactive full screen experiences.
04:22Particularly, for things like games, where if you're limited to only using the mouse,
04:27there is only so many games you can create that only use the mouse.
04:31Again, this is not really creating kind of a security problem because people are
04:35not going to be able to input their passwords and things like that, since we
04:39only are accepting non-printing keys.
Collapse this transcript
Larger bitmap support
00:00So many times in Flash applications there is the need to use large bitmap files.
00:05Now there are many different reasons why you'd want to do that.
00:08Well, the size of bitmaps that you can actually use now in Flash Player 10
00:13has actually increased.
00:14So I will quickly show you what these new limits are, so I'll create just a
00:18blank ActionScript 3.0 document and go into the Actions panel.
00:21I'll just go ahead and create a new bitmap data object.
00:25I'll just call it bmd: BitmapData = new BitmapData.
00:32Here I have to pass in the width and the height.
00:34So now inside of Flash Player 10 we can now create bitmaps or use bitmaps that
00:40are 4095 pixels wide x 4095 pixels high.
00:46So that's essentially now the new maximum size.
00:49So you can see, if I test this, it's not giving me any errors.
00:53If I were to change my Profile to Flash Player 9, so I'll come in here and click OK,
00:59and now test this.
01:01We can see that I get a runtime error.
01:03It basically says Invalid BitmapData, because it's too large.
01:07If you're wondering the actual total number of pixels, this size would
01:11be 16,769,025 pixels.
01:16So that's the maximum number of pixels that you can use now, which is quite a bit.
01:21In Flash Player 9 or in previous versions, the largest you could go was 2880.
01:28So we have a considerable increase now in the size of bitmaps.
01:32So now if I test this, we can see it now works in Flash Player 9.
01:36Basically, the total number of pixels allowed previously was 8,294,400.
01:42So it's pretty much a little over double the number of pixels that you can now
01:47use when it comes to using bitmaps in Flash Player 10.
Collapse this transcript
Clipboard context menu
00:00So for a while now in Flash, we've had the ability to right-click on some text
00:05inside of our Flash movie and we then see basically the clipboard menu which
00:10contain things like Copy, Paste and we've had that ability with text.
00:14Well, in Flash Player 10 now, we can actually show that clipboard menu over any
00:20type of item, including just regular display objects and then we can respond to
00:25the events of the clipboard items.
00:28So you go ahead and open up the clipboard.fla file. This is just a simple
00:33movie with some selectable text here, and then just a box movie clip with an
00:38instance name of box.
00:40So if I test this movie now, we can see here is my selectable text field and
00:44again, I've always been able to do this.
00:46I can right-click on this selected text and choose Copy in order to copy this
00:51text to the clipboard.
00:52But you see when I right-click on this movie clip, I don't have that and this
00:57is what's new in Flash Player 10 is I can actually add that when I right-click
01:01over this movie clip.
01:03So I already have a locked actions layer here.
01:05So I am going to open it up and the first thing I am want to do is to create
01:09a new context menu.
01:11So essentially, we're creating a new menu to replace the default menu for that movie clip.
01:15So I am going to say var cm for ContextMenu and create a new context menu, and
01:24now we've had the ability to do this in previous versions of Flash Player.
01:27I can do things like hideBuiltInItems which will essentially get rid of the zoom
01:32and other things inside of the menu and then when I want to actually apply this
01:36ContextMenu to that box movie clip, all I have to do is say box and then set the
01:42contextMenu property equal to that new context menu.
01:46So if I test that now, you can see I've gotten rid of all but these three items
01:51which basically you can't remove these items.
01:55Now we need to deal with, how do we get those clipboard items into that menu?
01:59So the first thing we need to do is we need to set the clipboardMenu
02:03property equal to true.
02:06So by default, the clipboardMenu is not shown except in selectable text fields.
02:11So we set it equal to true here.
02:14Now, if we actually test this, I right- click on this movie clip, you can see the
02:18menu is there, but everything is grayed out.
02:20So here, I need to actually go through and individually say which of those items
02:25do I actually want to display.
02:27So to do that, I say cm and then clipboardItems and now inside of here,
02:33essentially, I can set all of those items to either display or not.
02:38So I can set the copy item equal to true.
02:42So that basically means that the copy command is now going to be in this context menu.
02:47So you can see when I right-click, now the copy item is actually activated, and
02:52I could do the same thing with Cut, Paste and Clear.
02:55So now I have that contextMenu but I am probably going to want to respond to
03:01that event when that happens, so that I can perhaps add some custom stuff to the clipboard.
03:07So when I do that, all I have to do to make that happen is just say
03:10box.addEventListener, and now to respond to the copy event, I just say Event.COPY.
03:20Now I can just create a function called onCopy, which I'll create really quick.
03:24We're not going to return anything and all I am going to do is simply trace out
03:32a message that says "copied."
03:35So again, now when I select that copy item from the contextMenu, I am just going
03:40to call this onCopy function, and I am going to trace that value out.
03:44So let's test it tested and now when I right-click on that movie clip and choose Copy,
03:48you can see in the Output panel we've traced out copied.
03:51So it basically enables you to use those clipboard menu items anywhere in your
03:57Flash projects, where before you were restricted to just using them within text fields.
Collapse this transcript
Conclusion
Goodbye
00:00All right, so that's it.
00:01Throughout this title, I've shown you all of the new features that are inside
00:05of Flash Player 10.
00:06Now, some of the areas that we covered, particularly surrounding the new
00:10text engine and the drawing API, these actually go a lot lower level than what I showed you.
00:16So if you're interested in kind of taking Flash to a much lower level,
00:20you should definitely look at the documentation for Flash Player 10 to find out everything.
00:25So if you want some more help or you wanted to find out more about me, you can
00:28go to my blog at theflashblog.com.
00:31Thanks for watching. We'll see you next time.
Collapse this transcript


Suggested courses to watch next:



Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 98,718 instructional videos.

start free trial learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 1,899 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.


site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked