What if ActionScript 3.0 had no Conditional Statements? : Part I

Think in Non-Linear Concepts
Other than the fact that nested conditionals can create the worst kind of object binding as each condition sends the program further down the binding rabbit hole, we seem to really need them for working out certain kinds of problems. For example, in a visual game scenario, the user may be faced with choices. Suppose the game state is a crossroad where the player must choose to go North, East, West or South (NEWS). Alternatively, the choice may be video perspectives of different directions. Any one of the choices carries with it a whole set of other states, conditions, capabilities and properties.
One way to handle this kind of choice is with a conditional statement. The following shows two things. First, it shows that when a direction is selected, it typically has more than one thing being affected. (The more than one thing is furnished by “Everything else.”) Second, the binding for each is represented by the conditions within each conditional. (You could do the same thing with a Switch statement, but the binding wouldn’t change.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | package { import flash.display.Sprite; public class NEWS extends Sprite { private var newsArray:Array = new Array("north","east","west","south"); private var dir:Object; public function NEWS() { for (dir in newsArray) { if(newsArray[dir]=="north") { trace("Hellloo Siberia"); trace("Everything else...."); trace(""); } else if(newsArray[dir]=="east") { trace("Visiting Bejing"); trace("Everything else...."); trace(""); } else if(newsArray[dir]=="west") { trace("Dude! You made it!"); trace("Everything else...."); trace(""); } else if(newsArray[dir]=="south") { trace("¡Recepción a la Argentina!"); trace("Everything else...."); trace(""); } } } } } |
That certainly can solve the issue of generating different responses from different object properties. It’s compact and saves ground-fills of wasted bits. It illustrates a common method of dealing with multiple options. The loop iterates through the object, and each iteration is examined by four conditional statements.
Unconditional Programming
Let’s go back to the NEWS example, and instead of having trace statements representing different directions, this next example uses short videos pointing in different directions. (I live in the woods so the videos are fairly woodsy—but they show the four points of the compass—honest.) I want to make an app with four buttons that plays a video pointing in the selected direction. Plus, I don’t want to use any conditional statements. (Easier than you think.) Click the Play and Download buttons to see a working example and get the code and videos.
![]()

In the next section where we examine the code you will see two things: No conditional statements and a non-linear solution. The user has several choices, and simply by making a choice she/he goes directly to the object desired—a directional video.
Read more…
Gentle Readers: Chandima and I try different things, and this is the first time (I think) that we’ve taken an online Adobe Connect presentation and the accompanying PowerPoint slides and translated them into an article (post.) If you were able to attend the online talk, you have all of the slides along with written commentary and you can take your time to review them. Of course if you are unable to attend because it’s 3:30 am in Mumbai, this provides an asynchronous means of participating. Let us know what you think. Is it effective? Ineffective? Makes no difference? Your comments are valuable and invited. 


It’s about time for another Golden Lunch Bucket Contest, and once again you can reap fame and fortune! (And again, we’ll provide the former if you provide the latter. This time, though, we must insist that you provide better prizes for yourself if you’re one of the winners!)

Bill Sanders
Recent Comments