I don’t like external as files. Most developers prefer this and claim it’s better. Explain why is it better to use classes in ActionScript 3.0.
My ActionScripts are different. I strip the classes away and paste it in the Flash IDE. 9 out of 10 times it works fine. My question is Socratic, but I really feel ignorant about this, since there is less code for what I’m trying to do. Have fun with this.
Here’s a tutorial I dissected – "example tests keyboard output"
//AFTER
//remove curly brackets and "outer shell of class definitions"
//remove class function "don't need it"
//function at bottom, remove "public", make sure it has a body {}
var _time_scale:Number = .25;
var _frames_elapsed:int = 0;
var _clip:MovieClip;
function handleEnterFrame(e:Event):void {
_frames_elapsed++;
_clip.gotoAndStop(Math.round(_clip.totalFrames * _frames_elapsed * _time_scale));
}
//BEFORE
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite {
private var _time_scale:Number = .25;
private var _frames_elapsed:int = 0;
private var _clip:MovieClip;
public function Main():void {
_clip = new SomeClip;
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function handleEnterFrame(e:Event):void {
_frames_elapsed++;
// we multiply the "real" time with our timescale to get the scaled time
// we also need to make sure we give an integer as a parameter, so we use Math.round() to round the value off
_clip.gotoAndStop(Math.round(_clip.totalFrames * _frames_elapsed * _time_scale));
}
}
}
There may be no answer, but there must be a definative explanation that makes sense.
This sounds like 2 questions:
1) Why is it bad to put the code in the Flash IDE (CS4)?
First, the editor in the flash IDE is historically awful. It just doesn’t have the features that I expect from an editor for code.
Second, it can be hard to find code that’s in the timeline.
Third, when you make a change in the ide and check it into your code repository (you do use version control, right?), the changes are binary and can’t be tracked and diffed easily.
2) Why is object orientation good?
Object orientation is about encapsulation. It’s not the only way to do things, but currently, it’s the most popular. Here’s a page that does a decent job of explaining it:
http://www.alagad.com/blog/post.cfm/what-does-object-oriented-programming-do-for-me