Meta-Blog

SEARCH QandO

Email:
Jon Henke
Bruce "McQ" McQuain
Dale Franks
Bryan Pick
Billy Hollis
Lance Paddock
MichaelW

BLOGROLL QandO

 
 
Recent Posts
The Ayers Resurrection Tour
Special Friends Get Special Breaks
One Hour
The Hope and Change Express - stalled in the slow lane
Michael Steele New RNC Chairman
Things that make you go "hmmmm"...
Oh yeah, that "rule of law" thing ...
Putting Dollar Signs in Front Of The AGW Hoax
Moving toward a 60 vote majority?
Do As I Say ....
 
 
QandO Newsroom

Newsroom Home Page

US News

US National News
Politics
Business
Science
Technology
Health
Entertainment
Sports
Opinion/Editorial

International News

Top World New
Iraq News
Mideast Conflict

Blogging

Blogpulse Daily Highlights
Daypop Top 40 Links

Regional

Regional News

Publications

News Publications

 
Adobe Flash CS3
Posted by: Dale Franks on Thursday, January 24, 2008

Yeah, I picked up Adobe Flash CS3, as you can see from the Electoral Vote Counter, and I'm playing around with its odd flavor of Java, called ActionScript 3.0.

I'm actually pretty impressed with it. The new version of ActionScript now allows you to put all of the code on its own layer in the presentation, instead of spreading it all out among the various objects in the movie. It also gives you much fuller—and easier—control over the various drawing objects in the movie.

Some of the conventions are a little irritating at first, however. For instance, all of the mouse events have to be trapped, then sent off to a custom function. In this presentation, all of the states are drawing objects, named with their state abbreviations. So, to tell if you've clicked on a state, you have to catch the mouse click, then send it off to the delegate function, using the syntax:

CA.addEventListener(MouseEvent.CLICK, changeColor);

This line of code tells the program to "listen" for a mouse click on California, and if it "hears" it, to send it off to the delegate function "changeColor".

I'm also not entirely impressed with the variable declaration, because it seems a little odd. In order to create an integer variable called newVotes, you'd use the syntax:

var newVotes:int = 0;

I think this is a bit cumbersome, compared to the same code in, say, C#, which would be:

int newVotes = 0;

I also don't like that the naming conventions for data type names aren't fully standardized. An int is declared as an "int", but a string is declared as a "String". In a case-sensitive language, this is inevitably gonna cause a problem. Make up your mind. Either capitalize your naming conventions or not, but please don't mix them. It's irritating.

For some, the "switch" statement will cause a problem, since cases cannot fall through to one another. At the end of every case, you have to put in a "break;" line. For some of the C-based programmers, this will cause a problem, since they are used letting the cases fall through to the next case. Coming from C#, though, this is how I expect it to work.

Despite the minor irritants, though, ActionScript 3.0 is about 1,000 times better than v2.0. Putting all the code together in one place makes it a LOT more manageable, and the language gives you much greater control over everything on the stage.

I put the electoral vote counter application together in a couple of hours. It would've taken much longer in ActionScript 2.0 to make it work. So, the proof is in the pudding as far as the ease with which you can create applications go.

The extra line of code to do delegation really makes a lot of sense, once you begin working in AS3. It's functionally way different from AS2, but when you begin working in it, you begin to see that it really does allow you to do things much more quickly, all in the same place, with a much greater degree of control than ever before.

I think I'll be able to do some nice things with it.

In case you're a real geek, the code for the Electoral Vote application is below the fold. It's only 318 lines of code, and that includes the blank lines for spacing.
 
import flash.events.MouseEvent;
import flash.geom.ColorTransform;

redText.text = "0";
blueText.text = "0";
grayText.text = "538";

function changeColor(event:MouseEvent):void
{
var colorInfo:ColorTransform = event.target.transform.colorTransform;
var sRedVotes:String = redText.text;
var redVotes:int = int(sRedVotes);
var sBlueVotes:String = blueText.text;
var blueVotes:int = int(sBlueVotes);
var sGrayVotes:String = grayText.text;
var grayVotes:int = int(sGrayVotes);
var newVotes:int = 0;

switch(event.target.name)
{
case "AL":
newVotes = 9;
break;

case "AK":
newVotes = 3;
break;

case "AR":
newVotes = 6;
break;

case "AZ":
newVotes = 10;
break;

case "CA":
newVotes = 55;
break;

case "CO":
newVotes = 9;
break;

case "CT":
newVotes = 7;
break;

case "DE":
newVotes = 3;
break;

case "DC":
newVotes = 3;
break;

case "FL":
newVotes = 27;
break;

case "GA":
newVotes = 15;
break;

case "HI":
newVotes = 4;
break;

case "ID":
newVotes = 4;
break;

case "IL":
newVotes = 21;
break;

case "IN":
newVotes = 11;
break;

case "IA":
newVotes = 7;
break;

case "KS":
newVotes = 6;
break;

case "KY":
newVotes = 8;
break;

case "LA":
newVotes = 9;
break;

case "ME":
newVotes = 4;
break;

case "MD":
newVotes = 10;
break;

case "MA":
newVotes = 12;
break;

case "MI":
newVotes = 17;
break;

case "MN":
newVotes = 10;
break;

case "MS":
newVotes = 6;
break;

case "MO":
newVotes = 11;
break;

case "MT":
newVotes = 3;
break;

case "NB":
newVotes = 5;
break;

case "NV":
newVotes = 5;
break;

case "NH":
newVotes = 4;
break;

case "NJ":
newVotes = 15;
break;

case "NM":
newVotes = 5;
break;

case "NY":
newVotes = 31;
break;

case "NC":
newVotes = 15;
break;

case "ND":
newVotes = 3;
break;

case "OH":
newVotes = 20;
break;

case "OK":
newVotes = 7;
break;

case "OR":
newVotes = 7;
break;

case "PA":
newVotes = 21;
break;

case "RI":
newVotes = 4;
break;

case "SC":
newVotes = 8;
break;

case "SD":
newVotes = 3;
break;

case "TN":
newVotes = 11;
break;

case "TX":
newVotes = 34;
break;

case "UT":
newVotes = 5;
break;

case "VT":
newVotes = 3;
break;

case "VA":
newVotes = 13;
break;

case "WA":
newVotes = 11;
break;

case "WV":
newVotes = 5;
break;

case "WI":
newVotes = 10;
break;

case "WY":
newVotes = 3;
break;


}
switch(event.target.transform.colorTransform.color)
{
case 0xFF0000:
colorInfo.color = 0x0000FF;
event.target.transform.colorTransform = colorInfo;

redVotes = redVotes - newVotes;
blueVotes = blueVotes + newVotes;
redText.text = String(redVotes);
blueText.text = String(blueVotes);
break;

case 0x0000FF:
colorInfo.color = 0xCCCCCC;
event.target.transform.colorTransform = colorInfo;

blueVotes = blueVotes - newVotes;
blueText.text = String(blueVotes);
grayVotes = grayVotes + newVotes;
grayText.text = String(grayVotes);
break;

default:
colorInfo.color = 0xFF0000;
event.target.transform.colorTransform = colorInfo;

redVotes = redVotes + newVotes;
redText.text = String(redVotes);
grayVotes = grayVotes - newVotes;
grayText.text = String(grayVotes);
break;


}
if(blueVotes >= 270)
blueWin.text = "Winner!";
else
blueWin.text = "";

if(redVotes >= 270)
redWin.text = "Winner!";
else
redWin.text = "";

}

AK.addEventListener(MouseEvent.CLICK, changeColor);
AL.addEventListener(MouseEvent.CLICK, changeColor);
AZ.addEventListener(MouseEvent.CLICK, changeColor);
AR.addEventListener(MouseEvent.CLICK, changeColor);
CA.addEventListener(MouseEvent.CLICK, changeColor);
CO.addEventListener(MouseEvent.CLICK, changeColor);
CT.addEventListener(MouseEvent.CLICK, changeColor);
DE.addEventListener(MouseEvent.CLICK, changeColor);
DC.addEventListener(MouseEvent.CLICK, changeColor);
FL.addEventListener(MouseEvent.CLICK, changeColor);
GA.addEventListener(MouseEvent.CLICK, changeColor);
HI.addEventListener(MouseEvent.CLICK, changeColor);
ID.addEventListener(MouseEvent.CLICK, changeColor);
IA.addEventListener(MouseEvent.CLICK, changeColor);
IL.addEventListener(MouseEvent.CLICK, changeColor);
IN.addEventListener(MouseEvent.CLICK, changeColor);
KS.addEventListener(MouseEvent.CLICK, changeColor);
KY.addEventListener(MouseEvent.CLICK, changeColor);
LA.addEventListener(MouseEvent.CLICK, changeColor);
MA.addEventListener(MouseEvent.CLICK, changeColor);
MD.addEventListener(MouseEvent.CLICK, changeColor);
ME.addEventListener(MouseEvent.CLICK, changeColor);
MS.addEventListener(MouseEvent.CLICK, changeColor);
MI.addEventListener(MouseEvent.CLICK, changeColor);
MN.addEventListener(MouseEvent.CLICK, changeColor);
MO.addEventListener(MouseEvent.CLICK, changeColor);
MT.addEventListener(MouseEvent.CLICK, changeColor);
NB.addEventListener(MouseEvent.CLICK, changeColor);
NV.addEventListener(MouseEvent.CLICK, changeColor);
NH.addEventListener(MouseEvent.CLICK, changeColor);
NJ.addEventListener(MouseEvent.CLICK, changeColor);
NM.addEventListener(MouseEvent.CLICK, changeColor);
NC.addEventListener(MouseEvent.CLICK, changeColor);
ND.addEventListener(MouseEvent.CLICK, changeColor);
NY.addEventListener(MouseEvent.CLICK, changeColor);
OH.addEventListener(MouseEvent.CLICK, changeColor);
OK.addEventListener(MouseEvent.CLICK, changeColor);
OR.addEventListener(MouseEvent.CLICK, changeColor);
PA.addEventListener(MouseEvent.CLICK, changeColor);
RI.addEventListener(MouseEvent.CLICK, changeColor);
SC.addEventListener(MouseEvent.CLICK, changeColor);
SD.addEventListener(MouseEvent.CLICK, changeColor);
TN.addEventListener(MouseEvent.CLICK, changeColor);
TX.addEventListener(MouseEvent.CLICK, changeColor);
UT.addEventListener(MouseEvent.CLICK, changeColor);
VT.addEventListener(MouseEvent.CLICK, changeColor);
VA.addEventListener(MouseEvent.CLICK, changeColor);
WA.addEventListener(MouseEvent.CLICK, changeColor);
WV.addEventListener(MouseEvent.CLICK, changeColor);
WI.addEventListener(MouseEvent.CLICK, changeColor);
WY.addEventListener(MouseEvent.CLICK, changeColor);
 
TrackBacks
Return to Main Blog Page
 
 

Previous Comments to this Post 

Comments
Actually, ActionScript is a variant of javascript, not java. Common error, but preventable. Java is a C++-like compiled language, javascript is an objects-via-prototypes interpreted language with mild syntax resemblance to Java.
 
Written By: Charlie (Colorado)
URL: http://explorations.chasrmartin.com

 
Add Your Comment
  NOTICE: While we don't wish to censor your thoughts, we do blacklist certain terms of profanity or obscenity. This is not to muzzle you, but to ensure that the blog remains work-safe for our readers. If you wish to use profanity, simply insert asterisks (*) where the vowels usually go. Your meaning will still be clear, but our readers will be able to view the blog without worrying that content monitoring will get them in trouble when reading it.
Comments for this entry are closed.
Name:
Email:
URL:
HTML Tools:
Bold Italic Blockquote Hyperlink
Comment:
   
 
Vicious Capitalism

Divider

Buy Dale's Book!
Slackernomics by Dale Franks

Divider

Divider