Flash – Case 3
Let the programming start!
This week we’ve been introduced to ActionScript 3.0, the programming language used inside Flash.
Case 3: In this case you have to move your character by using ActionScript, you also have to make sure that the character is kept “within the screen” (an invisible border that you assign in the script).
Having small amounts of experience within the whole programming setting is something that I’ve felt, in a negative way, the last days. I have a bit of experience from Assembly, and a bit of bash/C++ programming, but it’s not really comparable to ActionScript.
I have completed this case, more or less to a satisfying extent, although I have to admit that I’ve cross-referenced most parts of my code within theĀ “Learning AcrionScript 3.0: A Beginner’s Guide” book.
I’m going to read about packages, functions, statements (if, while, then, etc), classes, loops, and events. I also have to add another sequence to my walk-animation, as well as tidying up the sprite I’ve made out of all the animations.
Here’s the code (pastebin) I’ve written to solve this case. Here’s the zip archive of the ActionScript file, the flash file, and a Flash movie with the two files combined.
And here’s the code pasted directly into this post, it appears quite messy as WordPress doesn’t really allow “clean” indents when you quote text. I recommend checking the Pastebin version as it formats the code with colors according to ActionScript.
package { import flash.display.MovieClip; import flash.events.Event; public class Main extends MovieClip { var speed:Number = 5; var walk:Walk; public function Main() { addEventListener(Event.ENTER_FRAME, Update); walk= new Walk (); walk.x = 200; walk.y = 50; walk.scaleX = 1; walk.scaleX = 1; addChild(walk); trace(“Flash”); } public function Update (e:Event) : void { walk.x+=speed; if(walk.x>400-walk.width/2) { speed= -speed; walk.scaleX = -1; trace(walk.x); } if(walk.x<0+walk.width/2) { speed= -speed; walk.scaleX = 1; trace(walk.x); } } } }
The groups in our course got two example files, one .as (ActionScript) file and one .fla (Flash) file. I studied the examples while reading along the code, to better understand what the code was all about. Thanks to Eirik (Antihelt) who chugged up some code to the web, which I was allowed to take part in myself, and later used parts of. I wrote most of the code down on my own using “Learning ActionScript 3.0: The Beginner’s Guide”, and added some code that I found out would “improve” the script, like dividing the walk.x so it turns inside the assigned screen-limit/border. I still need to learn more of the functions and so on to get a broader understanding of what I actually write, and why I do it.
About this entry
You’re currently reading “Flash – Case 3,” an entry on Skarh
- Published:
- September 22, 2009 / 4:11 pm
- Tags:
- ActionScript, assignment, Case, Event, Flash, Package
1 Comment
Jump to comment form | comment rss [?] | trackback uri [?]