A prospective employer put forward this little test to screen potential candidates, this is my quick solution. Not quite production ready code, but I don't think they are expecting that for something like this :)
The problem:
Write a Flash application that loads a BML file from an arbitrary URL. A BML file is "ball markup language". It looks something like this:
ball_name:
color: FF0000
radius: 40
appear:
time: 2
x: 40
y: 40
disappear:
time: 15
x: 260
y: 260
A solution:
My solution was written in Flex, which if you can't tell, I am smitten with. I didn't implement the loading from an arbitrary URL part, but that is trivial using an URLLoader or HTTPService. The code I wrote to parse the BML input is real horror show. But in the real world we'd use XML, JSON, etc. to retrieve this data so I didn't think it was necessary to write something more robust.
I like to write elegant, maintainable code. This is not necessarily the most elegant solution, but it's not bad given that I only spent a few hours doing it. Check out the Ball.as class which does most of the heavy lifting. You can right click on the app to view the source code.
Here is some sample BML markup that you can paste into the app:
brownie_points:
color: 5B4202
radius: 30
appear:
time: 1
x: 175
y: 175
disappear:
time: 15
x: 15
y: 15
deep_purple:
color: 380A67
radius: 35
appear:
time: 5
x: 50
y: 50
disappear:
time: 15
x: 250
y: 250
green_monster:
color: 3F912D
radius: 99
appear:
time: 3
x: 350
y: 125
disappear:
time: 18
x: 45
y: 125
orange_crush:
color: ECB834
radius: 77
appear:
time: 10
x: 250
y: 50
disappear:
time: 20
x: 25
y: 250
No comments:
Post a Comment