Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Actionscript Editor in Flash Professional CS5

0 (0 Likes / 0 Dislikes)
[♪upbeat music♪] [ADOBE TV Presents...] [♪♪] [Paul Trani in...] [♪♪] [Adobe® Flash® Professional CS5 - Training with Trani] [♪♪] [♪♪] ...21, 22, 23. Oh, hi. Welcome back to Training with Trani. My name is Paul Trani, and aside from my little workout, what I'd love to show you is the code hinting and all of the powerful features you have when you're writing code in Flash. So I'm going to go ahead and start off with this file. It's pretty straightforward, but let me give you a little background because here's a smiley face, and what I want to do is I want this smiley face to appear in different places on the screen. And not only that, but as I double click in it, I want it to display a different smiley face, a different quote, for this health club. So that's the setup for what I want to do, and it's going to require sort of a custom class, it's going to require a fair amount of code, I should say. So where I'm going to start off is in my Timeline panel, the Actions layer. As I select that first frame, I can go to Window and open up my Actions panel. So it's really a good practice to comment all your code. I want to create a timer class that executes every two seconds and shows a different smiley face. And this is going to require the Timer class. And not only that, it's going to reposition and change the movie clip at random. So that's my agenda. All right. I'm going to start off by creating this Timer class. I'm going to start off by creating a variable called myTimer. [var myTimer:Timer] As I hit that colon, I get this code pop-up. Now I have the ability to go ahead and locate Timer. That's what I want to use is this Timer class. Watch what happens when I hit Enter. It not only completes the word, but it adds this import statement right here. [import.flash.utils.Timer;] So what Flash is doing is it's going to go out and grab all of that code that I didn't have to write and it's going to put it in my file. But again, I didn't have to worry about any misspellings or any of that. It's all right in there at my fingertips. All right. Just finish this out. [var myTimer:Timer = new Timer(2000);] The newTimer is what I'm going to use. And then within these two parentheses is where I want to put how long it's going to execute. In this case 2 seconds, which is actually 2000 milliseconds. That's how often this is going to execute. All right. Next step is to go ahead and let's take a look at Event Listeners because for myTimer, you're probably going to want to add an Event Listener, which is almost like the backbone for code when it comes to ActionScript, if you ask me. [myTimer.addEventListener(TimerEvent.TIMER, changeSmiley);] Notice how I can easily select it, it adds it, and literally, I'm not typing anything. Other than using my arrow keys, I'm just selecting options. Notice how I'm including that TimerEvent. When I include that TimerEvent, it actually adds that import statement up there as well. [import flash.events.TimerEvent;] Again, the less typing I do, the less chance there are errors. So TIMER, changeSmiley. There's my Event Listener. Now I need to go ahead and write my function. [function changeSmiley(e: TimerEvent):void{ changeSmiley. That is a Timer Event. Any time you get that pop-up, you just select that item, hit Enter, and there it is. Void. And then watch when I add this opening curly brace. When I hit Return, it automatically adds that closing curly brace. It may seem like something simple, but that will really get you out of a lot of jams. I'm glad it adds that. Now I can just throw in a quick trace statement just so that I know it works. [trace ("works");] And I will go ahead and run this file. Now, there is one thing I did not add, and that is the myTimer start method. So as I type in myTimer start, there it is, I select it, hit Enter. And I will save this file. Now let's run it. There it is, and we can see in the Output panel it starts to print out that word that I had in the trace statement. All right. So I have the structure down, and I'm dealing with some Flash classes. But what about potentially a custom class I might have created? I'm going to point you to how that works by first off just hiding Flash and going to my Desktop. Here's my Flash file that I'm working on. Let me go ahead and open up that Com folder because inside of that Com folder is that Utilities folder and inside of there is that RandomNum.as file, so a custom class that I wrote, and I'll double click on it. What it does is it has this function in there called getRandomNum. It's going to get a random number based on the start and end parameters that I define as I use this function. So again, that's just a custom class that's written. Now I'll go back into my Flash file, and I'm going to start to use it. Okay, so the first thing I want to do right up here is I want to create another variable called randomNum. [var randomNum:RandomNum] And I'm going to use that custom class. So as I type in that colon and start to type in Random num-- I love this! I love how it shows me that custom class. Very powerful. Locates it, I just select it, hit Return, it adds the word. And not only that, it adds that import statement pointing to that specific folder that I actually defined. [import com.utilities.RandomNum;] Very powerful being able to do this. So again, same method. RandomNum. There it is. [var randomNum:RandomNum =)( new RandomNum();] And there's my variable. All right. So far, so good. Now I want to go ahead and use it, so I'm just going to go ahead and hit some Returns so I can come down inside of this function. This is where I can use this variable. All right. So the first thing I'm going to do is I'm going to create another variable called frameNum. [var frameNum:int = randomNum.getRandomNum(] It's a number, and I'm going to make it equal to the randomNum defined here. Remember that function that I defined earlier? I'll just type that period, and there it is. It appears right at the top of my list. I can go ahead and use it just by selecting it. Bam! There it is. And now it even gives me code hinting for my own custom class, particularly this function. So I can add a start between numbers 1 and 6, the start and end. [var frameNum:int - randomNum.getRandomNum(1,6);] Go ahead and pick a random number because for frameNum, that's the variable I want to use for my smiley face. All right. So let me just jump out here, locate my smiley face. It's called smileyFace, so I'll just copy that, go back to my code right in here, and paste that name in. It's helpful to copy and paste just to eliminate any errors. [smileyFace.gotoandStop(frameNum)] Smiley face, go to and stop, and then go ahead and use frameNum, just like that. So whatever number is in here, which is a random number, go ahead and use right here. All right. Looks pretty good. But the final test is, of course, when you test your movie. All right. So all it's going to do is swap out those various movie clips. It actually jumps to that specific frame and shows me that quote. So it's like it's swapping out quotes. Very powerful. Works out great from a custom class that I made. Of course the Timer class is a built-in class. Looks good. And the next step would be to sort of reposition the smiley face, both its X and Y position. So I'm just going to go ahead and paste in that code. Here it just gets a random X position number and a Y position number and then moves the smiley face based on those two variables. And I'll just run this for our final result. So as you can see, the smiley face repositions and goes to a different quote randomly every two seconds. But those are just a couple of the code enhancements that are in Flash CS5 Professional. Join me again next time. [♪upbeat music♪] [Executive Producer - Bob Donlon] [Producer - Karl Miller] [Director/VFX - Kush Amerasinghe] [DP/Post Production - Erik Espera] [ADOBE TV Productions - tv.adobe.com]

Video Details

Duration: 10 minutes and 10 seconds
Country:
Language: English
License: All rights reserved
Genre: None
Views: 79
Posted by: adobetv on Oct 7, 2010

Join trainer Paul Trani as he shows off new features in Flash Professional CS5's Actionscript editor. Features like custom class code hinting and code completion, as well as automatic writing of the import statement for libraries will help streamline your workflow.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.