ForumsProgramming ForumEverything in actionscript

14 7558
Annihalation
offline
Annihalation
479 posts
Nomad

OK, so I need help. I recently got FlashDevelop (google it im lazy) and its a program that can write in AS3. So I need someone to teach me how to write stuff and do animations using AS3 (not Adobe Flash CS3/CS4) because this program is all text :/ anyone willing to teach me a few basic things about ActionScript? I know like... absolutely nothing about it... BUT im willing to learn

  • 14 Replies
KGuare
offline
KGuare
29 posts
Nomad

Haha, the age old question "How do i write AS3?"

It's like asking how to draw, or
how to write poetry. You can't answer it
in a couple sentences.

If you want to learn AS3, just check out
a couple tutorials through google.
Here's a nice one

Good luck. :]

Annihalation
offline
Annihalation
479 posts
Nomad

ugh... tutorials are horrible and never tell you what you want. what i mean is like a big list of EVERY base command in actionscript, and what each one does. kind of like a cheat sheet. then maybe a few examples of them that i could copy/paste, then tinker with. But thanks for the tutorial, ill watch it

Drace
offline
Drace
3,880 posts
Nomad

Check out the tutorials in http://www.adobe.com/devnet/flash/articles/flash_in_a_flash.html

There pointed toward Adobe Flash users though. Why didn't you get it?...

Erasmus_Darwin
offline
Erasmus_Darwin
59 posts
Nomad

Zip file <-- Adobe's huge ActionScript language reference. Unzip it and click on index.html to start at the top.

It's the same as what's on the website, but it's a lot easier when you don't have to wait for it to load. You can also go into the flash folder to go straight to a given object. In flash\\display is where a lot of the graphically-oriented classes are.

You might not get much from the Flash in a Flash tutorials that Drace posted, as I suspect they're geared towards building graphics in the Flash environment and then attaching ActionScript to them.

Also, here's a huge PDF on programming AS3: PDF

Annihalation
offline
Annihalation
479 posts
Nomad

thank you Erasmus

Drace, i couldnt get it cuz it wouldnt work (Ill email you later some time.

Annihalation
offline
Annihalation
479 posts
Nomad

Ok, just a simple AS3 question. Don't give me a bunch of tutorials. How do I set graphics with AS3? (like, what code is it). I guess a "AS3 Animating Tutorial" would be helpful (google is rejecting me right now). Thanks everyone!

Annihalation
offline
Annihalation
479 posts
Nomad

anything at all? lol

Erasmus_Darwin
offline
Erasmus_Darwin
59 posts
Nomad

Basically, you just create a Sprite object, draw to the Graphics object within the Sprite, and then attach the Sprite to the stage.

First select Project->New Project, select an AS3 Project, give it a name, and check the "create a new directory for the project" box. FlashDevelop will create the project and give you a Main.as with a bit of starter code in it.

Quick sidenote: If you hit F5, the project should compile and produce a blank Flash window since you've technically got enough to qualify as a Flash application even if it doesn't do much.

Edit Main.as and where you see the import statements at the top, add the following:
import flash.events.TimerEvent;
import flash.utils.Timer;

Right after:
public class Main extends Sprite
{
Add:
private var triangle:Sprite;
private var timer:Timer;

And right after:
// entry point
Add:
triangle = new Sprite();
triangle.graphics.beginFill(0xFF0000);
triangle.graphics.moveTo(5, 0);
triangle.graphics.lineTo(0, 5);
triangle.graphics.lineTo(10, 5);
triangle.graphics.endFill();
stage.addChild(triangle);
triangle.x = 100;
triangle.y = 100;
timer = new Timer(2000, 5);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();

Finally, after the closing bracket "}" for the init function, add:
private function onTimer(e:TimerEvent): void {
triangle.scaleX++;
triangle.scaleY++;
}

What this does is it creates a triangle and increases its size every 2 seconds, stopping after 5 increases. The main drawing bit is the triangle.graphics stuff. Once it's done drawing on the Graphics object within the Sprite object stored in the triangle variable, then it attaches it as a child to the stage which is what makes it show up.

Another thing you can do is embedding bitmaps. What you do is you add the image (such as a .png) to the lib directory. Then create a new class -- in the project window, right-click on src and select "New Class..." and give it a name ("MyImage" in this example). Part of the class will look something like this:

public class MyImage

You want to change it so your class extends the built-in Bitmap class:

public class MyImage extends Bitmap

Then you want to create a blank line above that line. While your text cursor is still on that line, go to the project window, right-click on your .png file, and select insert into document, which will give you something like this:

[Embed(source='../lib/image.png']
public class MyImage extends Bitmap

Then when you instantiate the MyImage class, it'll show image.png. You'd do that like this (for example at the "// entry point" in Main.as):

var image:MyImage = new MyImage();
stage.addChild(image);

Annihalation
offline
Annihalation
479 posts
Nomad

are you a AS3 genius or something? You deserve an award, honestly. How long have you been working with AS and the like?

Ok, so adding the image as a child of the stage is what makes the program render the image on screen? I don't need to use any "render" functions? Cool

Annihalation
offline
Annihalation
479 posts
Nomad

ok, I learn AS3 MUCH easier like this than online tutorials and reading. Could you show me something that can make the triangle spin/rotate while growing?

Also, what is tweening?

Drace
offline
Drace
3,880 posts
Nomad

Annihalation, I'm guessing you got it to work?

Erasmus_Darwin
offline
Erasmus_Darwin
59 posts
Nomad

Heh. I wouldn't call myself an AS genius. I'm still learning it, and there's a lot I don't know. I just started two months ago, and there have been long gaps during those two months where I haven't worked with it as much as I would have liked. I do, however, have a lot of experience programming in other languages, so it does help.

Making the triangle spin is pretty simple. There's a rotation property for the Sprite class (well, actually the DisplayObject class which is a parent of Sprites), and setting it rotates the object.

So you can just add "triangle.rotation += 15;" to the onTimer function that's also scaling up the triangle, and it'll rotate 15 degrees each time it scales up.

As a side note, if you look in that ActionScriptLangRefV3 zip that I linked earlier, you can find the documentation for the rotation property. Just look in flash\\display and click on Sprite.html. At the top of the property list will be a link that says "Show Inherited Properties" or "Hide Inherited Properties". If it says "Show", click on it to reveal the inherited properties. Then scroll down to see the rotation property. If you look to the right, you'll see it's actually defined in the DisplayObject class. Click on rotation, and the documentation will open up the DisplayObject documentation and jump to the description of the rotation property.

Tweening produces the in-between animations when you're changing a shape. For example, if you've got a circle at 0,0 and at 20,0 later on, then tweening will produce all the intermediate positions before the final state. Unfortunately, I haven't really gotten into tweening, so I can't tell you more. I believe a lot of the tweening-related tools are built into the Flash authoring environment, so things are a little more difficult for FlashDevelop users.

Annihalation
offline
Annihalation
479 posts
Nomad

ok i like tweening. with a GIF image, you have to draw every frame, but with this, you set the start point, the finish point, and the speed at which it moves, and then you get all the images (until the max# of frames), thats cool.

And Drace, i'll talk to you over the IM.

Darkroot
offline
Darkroot
2,763 posts
Peasant

Annihilation no offense but you are not going to learn actionscript if you just ask question and have people give you all the answers. There is almost no effort on your part to learn. Do you know what a class is? objects? Object orient language? These are the fundamentals that you must understand if you going to get anywhere. At one point you just going to have to sit down and learn if you want to do anything beyond a simplistic point and click adventure game or stealing other peoples code and tinkering with it.

Showing 1-14 of 14