Archive for the 'OOP' Category

12th Sep 2008

Comparing Flex Frameworks

Yesterday I attended a meeting of the local Flex user group. The subject was comparing Flex frameworks presented by Yakov Fain. You can view the slides from the presentation here.

I myself have never used one of these frameworks, as I simply have never had the need for one. However I have been researching them and after attending this presentation I still feel that my initial inclination towards them stands; they exist mostly for standardization when working in teams.

By this I mean you can accomplish the same thing you can with the framework using standard Flex code and ActionScript, more than likely in a much simpler fashion depending on the project. What they afford you when working in a team is that you know that if everyone is using the same framework, then they are coding in the same fashion, hence the code written by one team member should work with the code by another. And as Yakov pointed out, they allow you to spilt up large projects among a team.

This is a nice benefit, but these benefits often come at a cost. For example one of the major complaints about Cairngorm is that you have to write a lot of classes. One reason for this is that in Cairngorm each event that the application triggers has to have a corresponding Command class. That’s a class for every event (its actually worse than that as there are other classes that these need to communicate with that you need to write as well). For a large application with a lot of events, this quickly becomes a lot of code.

Another implication of this is that you can only have one event responder per event. In other words, you lose the benefit of being able to have multiple responders to a single event that is built into Flex events, which as far as I am concerned was a great improvement over the AS2 model. Cairngorm essentially takes you back to the AS2 model.

Mate has a better event model and it does do a nice job of managing dependencies via dependency injection, but you have to maintain an event map and Mate is an MXML only framework.

And as far as PureMVC goes (look at the flow diagram slide for it in the presentation I linked to) all I can say is ???????. In its defense, PureMVC was designed to be language agnostic, but it seems to suffer from the “trying to be everything to everyone” syndrome.

The slides I linked to do a good job of pointing out the strengths and weaknesses of each framework, so I will refer you to them if you are interested in learning more.

So for now, it seems that these frameworks would get in the way more than they would simplify anything for me.

Posted by Posted by Jeremy Wischusen under Filed under Flex, OOP Comments No Comments »

04th Sep 2008

Tween Sequencer

Many of the projects I have done have included creating some sort of repeating sequence of tweens. In my early projects I would trigger the next tween using the finished event for each tween. This sucked.

So recently I had some time and decided to take a crack at creating a tween sequencing class. Basic idea being that I add a sequence of tweens to a object and then just call a start function to trigger the sequence.

My first idea was to create a collection of tween objects and store references to them in an array. This led me to com up with this:

package com.vfd.animation.tweens{
import fl.transitions.TweenEvent;
import fl.transitions.Tween;
public class TweenSequencer {
private var _tweens:Array=new Array ;

private var index:Number=0;
public var loop:Boolean=false;
public function TweenSequencer() {
trace(“New Tween Sequencer”);
}
public function addTween(tween:Tween):void {
tween.stop();
tween.addEventListener(TweenEvent.MOTION_FINISH,nextTween);
this._tweens.push(tween);
}
public function removeTween(tween:Tween):void {
for (var i:Number=0; i < this._tweens.length; i++) {
if (this._tweens[i] == tween) {
this._tweens[i].removeEventListener(TweenEvent.MOTION_FINISH,nextTween);
this._tweens.splice(i,1);
break;
}
}
}
public function start():void {
this.startTween();
}
public function stop():void {
this.pause();
this.reset();
}
public function pause():void {
if (this._tweens[this.index]) {
this._tweens[this.index].stop();
}
}
private function nextTween(event:TweenEvent):void {
trace(“Index before ” + this.index);
trace(“Loop : ” + this.loop);
this.index++;
if (this.loop && this.index >= this._tweens.length) {
this.reset();
}
trace(“Index after ” + this.index);
this.startTween();

}
private function startTween() {
if (this._tweens[this.index]) {
this._tweens[this.index].play();
} else {
this.reset();
}
}
private function reset():void {
this.index=0;
}
}//end class
}//end package

The basic idea worked, but I ran into a couple of problems. I was testing this with a basic ball. I placed the ball in the top right corner of the screen. Every time I ran the thing it would play the tweens in the correct sequence, but the ball always started in the bottom right corner of the screen making the first run through the sequence incorrect. However, after the first run through it played as expected.

This took me a while to figure out, but as it turns out that when I created the tweens, even though I immediately stopped them, it was setting the properties of the ball to the start values of the second set of tweens that were applied to the x and y coordinates.

I tried all sorts of variations including writing my own tween class that overrode the starting behaviors of the standard tween class and I still ended up with the same results (though it is entirely possible that I missed something simple).

I did turn out that if I explicitly set the x and y coordinates of the clip after creating the tweens, it worked as expected. However, I was only testing with many tweens applied to one object. If I was applying tweens to multiple objects I would have to reset all of them and having to explicitly set the coordinates defeated the purposes of placing them on the stage where I wanted them to begin with. Additionally, I ran into this problem with tweens applied to x and y, but if there are other properties that behaved the same way, I would have to reset those as well. This class was intended to make this process sequencing tweens easier, not simply introduce a new set of headaches.

After some time I came up with the idea of using a single tween inside of the sequencer class. Instead of storing multiple tween instances, I would just store sequence of properties and values that I wanted to tween an update the single tween instance. this would keep the tweens property settings from conflicting with one another and throwing the sequence off. This lead to:

package com.vfd.animation.tweens{
import fl.transitions.TweenEvent;
import fl.transitions.Tween;
import flash.display.Sprite;
public class TweenSequencer {
private var _tweens:Array=new Array();
private var tween:Tween;
private var index:Number=0;
public var loop:Boolean=false;
private var placeHolderSprite:Sprite = new Sprite();
public function TweenSequencer() {
trace(“New Tween Sequencer”);
this.tween = new fl.transitions.Tween(this.placeHolderSprite,”alpha”,null,1,1,1,true);
this.tween.stop();
this.tween.addEventListener(TweenEvent.MOTION_FINISH,nextTween);
}
public function addTween(obj:Object, prop:String, easing:Function, begin:Number, end:Number, duration:Number, useSeconds:Boolean = false):void {
this._tweens.push(arguments);
}
public function start():void {
this.startTween();
}
public function stop():void {
this.tween.rewind();
this.reset();
}
public function pause():void {
this.tween.stop();
}
private function nextTween(event:TweenEvent):void {
this.index++;
if (this.loop && this.index >= this._tweens.length) {
this.reset();
}
this.startTween();

}
private function startTween() {
this.tween.stop();
if (this._tweens[this.index]) {
this.tween.obj = this._tweens[this.index][0];
this.tween.prop = this._tweens[this.index][1];
if (this._tweens[this.index][2] is Function) {
this.tween.func = this._tweens[this.index][2];
}
this.tween.begin = this._tweens[this.index][3];
this.tween.finish = this._tweens[this.index][4];
this.tween.duration = this._tweens[this.index][5];
this.tween.useSeconds = this._tweens[this.index][6];
this.tween.start();
} else {
this.reset();
}
}
private function reset():void {
this.index=0;
}
public function reverse() {
this._tweens.reverse();
}
}//end class
}//end package

So now this:

import com.vfd.animation.tweens.TweenSequencer;
var ts:TweenSequencer = new TweenSequencer();
ts.loop = true;
ts.addTween(ball, “alpha”, null, 0,1,2,true);
ts.addTween(ball, “x”, null, 130,300,2,true);
ts.addTween(ball, “y”, null, 130,300,2,true);
ts.addTween(ball, “x”, null, 300,130,2,true);
ts.addTween(ball, “y”, null, 300,130,2,true);
ts.addTween(ball, “alpha”, null, 1,0,2,true);
ts.start();

Produces this:

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, OOP, Open Source Projects Comments 5 Comments »

15th Aug 2008

Hold on a Second

You can find a lot of tween libraries for AS2 and AS3. Many of these include some sort of mechanism for delaying the start of a tween. A while back I took my own shot at this based off of another class that I found and came up with:

import mx.transitions.Tween;
class com.vfd.animation.tweens.DelayedTween extends Tween{

private var intervalID:Number
private var delay:Number = 0;

public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay) {

super(object, property, easingFunction, start, end, duration, useSeconds);
this.delay = Math.abs(delay*1000);
this.setDelay();

}
private function start() {

}

private function setDelay() {
if (this.delay > 0) {
this.intervalID = setInterval(this, “startAnimation”, this.delay);
}else {
this.startAnimation();
}
}

private function startAnimation() {
clearInterval(this.intervalID);
super.start();
}

}

This was more or less a simple copy of the class I had found. I got a chance to look at this again today and realized I could simplify it a bit. I ended up with:

/**
* @author Jeremy Wischusen
* This class allows for a delay before starting the animation.
*/
import mx.transitions.Tween;
import mx.utils.Delegate;
class com.vfd.animation.tweens.DelayedTween extends Tween {
/*
Holds the number of seconds to wait before starting the animation.
*/
private var _delay:Number = 0;
/*
Instance variable holding a reference to the start function of the Tween class.
This is needed due to scoping issues when using setTimeout.
*/
private var superStart:Function;
public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay) {
this.delay = delay;
/*Use the Delegate class to create a reference back to the tween start funciton
that can be used with setTimeout. */
this.superStart = Delegate.create(super, super.start);
super(object,property,easingFunction,start,end,duration,useSeconds);
}
/*Override the default start function so that the delay can be applied.*/
public function start() {
if (this._delay>0) {
_global.setTimeout(this.superStart,this._delay);
} else {
super.start();
}
}
/*Setter function for delay attribute*/
public function set delay(seconds:Number){
this._delay = Math.abs(seconds*1000);
}
}

As you can see, I reduced the number of functions, used the simpler setTimeOut and rely more on inheritance and overriding than in the previous version. I also decided to make and AS3 version.

package com.vfd.animation.tweens{
import fl.transitions.Tween;
import flash.utils.setTimeout;
/**
* @author Jeremy Wischusen
* This class allows for a delay before starting the animation.
*/
public class DelayedTween extends Tween {
/*
Holds the number of seconds to wait before starting the animation.
*/
private var _delay:Number = 0;
public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay) {
this.delay = delay ;
super(object,property,easingFunction,start,end,duration,useSeconds);
}
/*Override the default start function so that the delay can be applied.*/
public override function start():void {
if (this._delay>0) {
setTimeout(super.start,this._delay);
} else {
super.start();
}
}
/*Setter function for delay attribute*/
public function set delay(seconds:Number):void {
this._delay = Math.abs(seconds*1000);
}
}
}

I have noticed that occasionally the compiler spits out:
The superconstructor must be called first in the constructor body.

If you place the super constructor before the delay variable is set, the tween just starts immediately since the variable has a default value of 0. This is what caused the need for the additional functions in the first version. While the compiler may occasionally complain (sometimes it shows the message and other times it does not), it still compiles and works.

Will be committing these to the repository on Google code sometime today.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 2, ActionScript 3, OOP, Open Source Projects Comments No Comments »

08th Aug 2008

Enforcing a Singleton

Been doing some research on Cairngorm and in the process came across this little trick for enforcing singletons. ActionScript will not let you set the access modifier for a constructor to private and as such, despite having a singelton architecture, there would be nothing stopping someone from directly calling new Singleton, which defeat the purpose of a singleton in the first place. The solution involves using what amounts to a private class that is a required argument of the constructor. This looks like this:

package
{

/**
* …
* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
*/
public class Singleton
{
private static var instance:Singleton;
public function Singleton(enforcer:SingletonEnforcer)
{

}
public static function getInstance():Singleton
{
if (Singleton.instance == null)
{
Singleton.instance = new Singleton(new SingletonEnforcer);
}
return Singleton.instance;

}
}

}
class SingletonEnforcer
{}

Notice the class definition for SingletonEnforcer is ourside of the package definition. When you define a class like this in the same file as a another class, it is only available to main class defined in the file (the one inside the package statement).  In other words the class is private. Since the constructor requires an instance of this class, trying to instantiate using new Singleton will throw an error since there is no way that an enforcer can be created and passed to the constructor other than within the Singleton class itself.

Hopefully in future versions of ActionScript we will have private constructors (along with method overloading just in case anyone is listening hint hint), but for now, this should do the trick.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, OOP Comments No Comments »

29th Jun 2008

Upon Reflection

The other day I was revising the one of the systems on one of the sites I work on into an object oriented structure. Everything was all well and good until I realized that I had to pass the values contained in one of my new objects into the templating system that we use. So I initially just passed a reference to the object. This did not work out so well.

It turns out that the templating system was having a hard time dealing with instance variables that are references to other objects and decided to throw a fit and halt processing. So I started looking for an easy way to translate my object into something the templating system could use (an array). More specifically, I wanted to produce an array that contained the values of my instance variables, but only the ones that were not references to other objects.

I decided to add a method called toArray to the object in question. Now I just needed an implementation. My first shot at this was to use PHP’s get_object_vars passing $this as a parameter.

public function toArray(){
return get_object_vars($this);
}

However, all was not well. It seems that when you call this function passing $this as a parameter it returned all of the variables from all of the objects referenced in instance variables. So I was basically back were I started.

So I gave it a bit of thought and came up with this.

/**

* Convert values held in instance variables into an array.
* This allows the data to be more easily used by a
* smarty variable  as well as making the data more easily cachable.
*
* @return Array
*/
public function toArray ()
{
$data = array();
foreach ( $this as $key => $var )
{
/**
* Exclude complex objects from the array.
*/
if ( !get_class( $var ) )
{
$data[$key] = $var;
}
}
return $data;
}

Problem solved. Now I only got back an array that contained the values of instance variables for that specific class that were not references to other objects.

Posted by Posted by Jeremy Wischusen under Filed under OOP, PHP Comments No Comments »

26th May 2008

Hey Look, a Mouse.

In one of the books I am reading, Foundation Actionscript 3.0 Animation : Making Things Move! by Keith Peters, he has an example of using trig to make an arrow point at the location of the mouse. I decided to play with this a bit and make an animation where the eyes follow the mouse. I actully ended up adding this to my animation class, so this (after attaching the class via the library linkage):

can be accomplished with:

leftEye.startWatchingMouse();

rightEye.startWatchingMouse();

 

Functions in class:

 

public function startWatchingMouse():void{

stage.addEventListener(MouseEvent.MOUSE_MOVE,watchMouse);

}

public function stopWatchingMouse():void{

stage.removeEventListener(MouseEvent.MOUSE_MOVE,watchMouse);

}

private function watchMouse(event:MouseEvent):void{

var dx:Number = stage.mouseX - this.x;

var dy:Number = stage.mouseY - this.y;

var rad:Number = Math.atan2(dy,dx);

//for some reason the example as written was 90 degrees off, so I added 90 and that fixed it.

this.rotation = rad*180/Math.PI + 90;

}

Edit:

Found a version of the class that has these function in it.

package com.vfd.animation{
/**
* Animation class. Based off of mc_tween2.as project.
* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
*/
import flash.display.Sprite;
import fl.transitions.Tween;
import fl.motion.Color;
import flash.geom.ColorTransform;
import fl.transitions.TweenEvent;
import flash.events.Event;
import flash.events.MouseEvent;
public class AnimatedClip extends Sprite {
private var originalX:Number;
private var originalY:Number;
private var xTween:Tween;
private var yTween:Tween;
private var alphaTween:Tween;
private var rotationTween:Tween;
private var widthTween:Tween;
private var heightTween:Tween;
private var eventTween:Tween;
private var tweenArray:Array;
private var colorTween:Tween;
private var colorTrans:ColorTransform;
private var tweenToColor:Number;
private var lastColor:Number;
private var timerClip:Sprite;
private var orbitAngle:Number = 0;
private var _orbitVelocity:Number = .5;
private var _orbitY:Number = stage.stageHeight/2;
private var _orbitX:Number = stage.stageWidth/2;
private var _orbitDistance:Number;

public function AnimatedClip() {
this.originalX = this.x;
this.originalY = this.y;
this.xTween = new Tween(this, "x", null, this.x, this.x, 1, true);
this.yTween = new Tween(this, "y", null, this.y, this.y, 1, true);
this.alphaTween = new Tween(this, "alpha", null, this.alpha, this.alpha, 1, true);
this.rotationTween = new Tween(this, "rotation", null, this.rotation, this.rotation, 1, true);
this.widthTween = new Tween(this, "width", null, this.width, this.width, 1, true);
this.heightTween = new Tween(this, "height", null, this.height, this.height, 1, true);
this.timerClip = new Sprite();
this.colorTween = new Tween(this.timerClip,'alpha',null,0,1,1,true);
this.colorTween.stop();
this.tweenArray = new Array(this.xTween, this.yTween, this.alphaTween, this.rotationTween, this.widthTween, this.heightTween,this.colorTween);
this.colorTrans = this.transform.colorTransform;
this._orbitDistance = this.width*2;
this.colorTween.addEventListener(TweenEvent.MOTION_CHANGE, updateColor);

}
public function resetPosition():void {
this.x = this.originalX;
this.y = this.originalY;
}
public function moveToPoint(x:Number, y:Number,duration:Number = 0, loop:Boolean = false):void {
this.xTween.finish = x;
this.xTween.duration = duration;
this.xTween.looping = loop;
this.yTween.finish = y;
this.yTween.duration = duration;
this.yTween.looping = loop;
this.xTween.start();
this.yTween.start();
}
public function fadeTo(val:Number =0, duration:Number = 0, loop:Boolean = false):void {
this.alphaTween.finish = val;
this.alphaTween.duration = duration;
this.alphaTween.looping=loop;
this.alphaTween.start();
}
public function sizeTo(w:Number, h:Number, duration:Number=0, loop:Boolean = false):void {
this.widthTween.finish=w;
this.widthTween.looping = loop;
this.widthTween.duration = duration;
this.heightTween.finish = h;
this.heightTween.looping = loop;
this.heightTween.duration = duration;
this.widthTween.start();
this.heightTween.start();

}
public function widthTo(width:Number, duration:Number, loop:Boolean = false):void {
this.widthTween.finish =width;
this.widthTween.looping = loop;
this.widthTween.duration = duration;
this.widthTween.start();
}
public function heightTo(height:Number, duration:Number, loop:Boolean = false):void {
this.heightTween.finish =height;
this.heightTween.looping = loop;
this.heightTween.duration = duration;
this.heightTween.start();
}
public function spinTo(rot:Number= 0, duration:Number = 0, loop:Boolean = false):void {
this.rotationTween.finish=rot;
this.rotationTween.duration = duration;
this.rotationTween.looping = loop;
this.rotationTween.start();
}
public function xTo(x:Number, duration:Number = 0, loop:Boolean = false):void {
this.xTween.finish = x;
this.xTween.duration = duration;
this.xTween.looping = loop;
this.xTween.start();
}
public function yTo(y:Number, duration:Number = 0, loop:Boolean = false):void {
this.yTween.finish = y;
this.yTween.duration = duration;
this.yTween.looping = loop;
this.yTween.start();
}
public function set easing(ease:Function):void {
for (var tw in this.tweenArray) {
tweenArray[tw].func = ease;
}
}
public function colorTo(toColor:Number, duration:Number):void {
this.lastColor = this.transform.colorTransform.color;
this.tweenToColor = toColor;
this.colorTween.duration = duration;
this.colorTween.start();
}
private function updateColor(event:TweenEvent):void {
this.colorTrans.color = Color.interpolateColor(this.lastColor, this.tweenToColor,event.position);
updateColorTransform();
}
public function set currentColor(clr:Number) {
this.lastColor = clr;
this.colorTrans.color= clr;
updateColorTransform();

}
public function startOrbit():void {
this.addEventListener(Event.ENTER_FRAME,orbit);
}
public function stopOrbit():void {
this.removeEventListener(Event.ENTER_FRAME,orbit);
this.orbitAngle = 0;
}
private function orbit(event:Event) {
this.y = this._orbitY + Math.sin(this.orbitAngle)*this._orbitDistance;
this.x = this._orbitX + Math.cos(this.orbitAngle)*this._orbitDistance;
this.orbitAngle += this._orbitVelocity;
}
public function startWatchingMouse():void{
stage.addEventListener(MouseEvent.MOUSE_MOVE,watchMouse);
}
public function stopWatchingMouse():void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,watchMouse);
}
private function watchMouse(event:MouseEvent):void{
var dx:Number = stage.mouseX - this.x;
var dy:Number = stage.mouseY - this.y;
var rad:Number = Math.atan2(dy,dx);
this.rotation = rad*180/Math.PI + 90;
}
public function set yEasing(ease:Function) {
this.yTween.func = ease;
}
public function set xEasing(ease:Function) {
this.xTween.func = ease;
}
public function set heightEasing(ease:Function) {
this.heightTween.func = ease;
}
public function set widthEasing(ease:Function) {
this.widthTween.func = ease;
}
public function set alphaEasing(ease:Function) {
this.alphaTween.func = ease;
}
public function set rotationEasing(ease:Function) {
this.rotationTween.func = ease;
}
public function set orbitVelocity(velocity:Number) {
this._orbitVelocity = velocity;
}
public function set orbitY(y:Number) {
this._orbitY = y;
}
public function set orbitX(x:Number) {
this._orbitX = x;
}
public function set orbitDistance(distance:Number) {
this._orbitDistance = distance;
}
public function get currentColor():Number {
return this.lastColor;
}
private function updateColorTransform() {
this.transform.colorTransform = this.colorTrans;
}
}
}

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, OOP Comments 2 Comments »

14th May 2008

AS 3 Animated Clip Class

So recently I finished (as in have something usable, they’re never finished) an AS3 animation class.

Basically I client of mine had me use mc_tween.as for a few projects and I decide to have a go at creating something similar in AS3 (from what I have read on the author’s site, he to is working on an AS3 version).

If you want to check out the class, you can find it on google code. Again, all of this stuff is a work in progress, so bugs are par for the course.

Here is a quick sample of how it can be used. The following example is created using this code:

//ball is a movie clip whose class I have set in the linkage dialog to com.vfd.animation.AnimatedClip;
import fl.transitions.easing.*
ball.easing = Bounce.easeInOut
ball.fadeTo(0,2, true);
ball.sizeTo(10,10, 2, true);
ball.spinTo(90, 2, true)
ball.orbitDistance = 50;
ball.startOrbit();

UPDATE:

Also started an AS 2 version. In the same code repository on google code.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, OOP, Open Source Projects Comments No Comments »

28th Apr 2008

Setting Up A Global Class Path In Flash

If you are just getting into using classes in Flash, chances are you are probably just creating your class (.as files) in the same directory as your FLA. This is simple, fast and works, but if I want to reuse a class from one Flash piece in another, I now have to copy over all of those class files into my new project directory. If I use that methodology, if I have to update something in one of my classes, I now have to update them in more than one location. This quickly turns into a maintenance nightmare and it turns out there is a simple solution.

Flash (as far back as mx 2007, not sure about older versions) will allow you to select a folder(s) where you can store classes that are used across multiple projects. This is commonly referred to as a class path. When you set up a class path and then do something like:


import com.mydomain.MyClass;
var myInstance:MyClass = new MyClass();

where MyClass is some custom class that you wrote, Flash will now look in your specified class path to see if it can find the corresponding class file (in this case MyClass.as). This means I am now free to use this class in any of my projects without having copy my class file into each project directory.

Please note that I am showing you how to set this for the program as a whole. You can also set this on a per document basis using the publishing settings

So how do we set this little piece of magic up?

  1. Got to the Edit menu and select Preferences.
  2. The following dialog box should appear:
    Flash Preferences
  3. Select ActionScript from the list on the left.
  4. Click the button entitled “ActionScript [version number] Settings” next to the Language label and the following dialog box should appear.
  5. Make sure to hit the + button resetting the entry that reads $(LocalData)/Classes will reset the default class path for Flash and Flash will no longer be able to find its built in classes. Clicking the + sign should make a blank line appear in the list.
  6. Click on the icon that looks like cross hair. This should bring up a file selection dialog box.
  7. Select the folder where you would like to store your classes.
  8. Keep clicking OK until all of the dialog boxes have closed.

Now you have your class path set up. This means that you can start storing you class files in this location. Please take note of the following:

  • Now that you have the class path set up, you can use import statements to bring in your classes just like you do with the standard Flash classes. For example import com.mydomain.MyClass; . Note a few things about the import statement.
    • The actual folder you selected is NOT included in the import statement (in my example C:\asclasses)
    • In import statements, dots = slashes. What I mean by this is that in our example, com.mydomain.MyClass is looking a file named MyClass.as in a folder mydomain that is a subfolder of com (i.e. /com/mydomain/MyClass.as). The beginning folder com in turn is actually a sub folder of the class path (i.e. C:\asclasses\com\mydomain\MyClass.as). Since we have setup C:\asclasses as a class path, Flash automatically looks in that location and we only have to specify the path using the dot syntax from that folder down. If you want to learn more about this dot syntax, do some research on the topic of packages in Flash.
    • As you may have noticed, you leave off the .as file extension.

Now that you have you class path set up, you can truly begin to start creating classes that are reusable across projects and only have to be maintained in one location.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 2, ActionScript 3, Flash, OOP Comments 2 Comments »