Tuesday 10 February 2009

Day ? - Where am I at?

Well it been over 14 days and still no arcade game. How do I feel about this? It's more good than bad. I guess the bad part is that I haven't accomplished what I set out to do. The good part is that I've got a good understanding of the basics, and I think realistically it might take two to four weeks to pull some kind of game off. I'll post the code when I figure it out. Admittedly I haven't geeked out and stayed in a darkened room coding for the last 2 weeks. I've chilled out and done other stuff.

This what I've learnt:

1) There are alot more resources out there on learning AS 3.0 then there used to be when I first had a look around for books etc a couple of years ago. This is can only improve - even i have managed to write this blog and used open source tools to capture my screen and embed video.

2) To build even basic applications requires a very good understanding of AS 3.0

3) Workflow is important. By this I mean the approach you take in building your projects and knowledge in AS 3.0. OOP Projects require more that 1 file and this can get complicated when trying to revise code so achieves goals more efficiently. At the moment I'm using version control to keep succesful experiments.

4) Looking at step 3 means that the challenge to learn AS 3.0 would be very difficult for complete beginners to coding.

5) Get Moock's EAS 3.0, but get Learning AS 3.0 to jump right in too.

6) FlashDevelop isn't too tricky to get working and seems to do the job well (once you the trace working - i think this is easy and was just me being stupid) Couldn't get code indent to work that would have been nice.

7) Although AS 3.0 isn't something you can be expertise in in a week or two. I'm guessing that you could probably get some competence in the order of months (ok I know that remains to be seen). Contrasting this to learning a foreign language which is probably more approaching the order of years, for me, means it worth pursuing.

Sunday 1 February 2009

Day 12 - keyboard event outside the main class

I need how to deal with keyboard events. This isn't too difficult, but I found it tricky to do this outside the main class. Anyway got onto the forums and got an answer off Nutrox, (see the post with a description of the problem in detail and has the code too).

Not sure if this is the right way of doing it, but ultimately I wanted the logic for controlling for the spaceship is a ship class not in the main class, so thats just some background to the problem.

Thursday 29 January 2009

Day 11 - hitTestObject

I'm getting more confident writing basic functionality in classes. Got caught out by a few scope issues.

Got hitTestObject working quiet nicely. As you can see in the video when the blue square hits the red square the blue square stops. The method is called from the main class

blueClip.hitStuff(redClip);

Got better ways of doing this? Or want more explanation please comment.



This is the code for the main class

package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;

public class Main extends flash.display.Sprite{
private var blueClip:Rec;
private var redClip:Rec;
private var greenClip:Rec;
public function Main() {
blueClip= new Rec(300,50,0x66CCFF);
addChild(blueClip);
blueClip.go( -1);
redClip = new Rec(20, 50, 0xDC143C);
addChild(redClip);
redClip.go(1);
greenClip = new Rec(70, 50, 0x669900);
addChild(greenClip);
greenClip.go(1);
blueClip.hitStuff(redClip);
}
}
}


This is the code for the Rec class that draws the rectangles

package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.utils.Timer;

public class Rec extends Sprite {
//private var movetimer:TimerEvent;
private var moveTimer:Timer=new Timer(10,0);
public function Rec(xPos:Number,yPos:Number,shapeColour:uint) {
graphics.beginFill( shapeColour , 0.5 );
graphics.drawRect( xPos , yPos , 20,20 );
graphics.endFill( );

}
public function go(speed:Number):void {
moveTimer.addEventListener(TimerEvent.TIMER,onTimer);
moveTimer.start();

function onTimer(e:TimerEvent):void{
x += speed;
e.updateAfterEvent();
}
}
public function hitStuff(clip:Rec):void {

addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame():void{
if (hitTestObject(clip)) {
moveTimer.stop();
trace("collision with " + clip.name);
}

}
}
}
}

Day 10 - Practiced some code

Just familiarised myself with rewriting a few classes

Tuesday 27 January 2009

Day 9 - Signed up for Safari Books Online

I finished Moock's Tamagotchi tutorial, and it's well worth it. Still hungry for more tutorials so I signed up for Safari Books Online the cheapest offer is $11.50 for 5 books on the shelf for a month.

Day 8 - Passing arguments and tutorials

Although it would have been nice to get my head round Passing Arguments with Events I admit it was a bit of a stretch. I did manage to use the code and implement my own version, but was a bit uneasy about spending too much time trying this particular technique considering I'm only on Day 8, and still gaining familiarity with basic syntax and concepts. To close Day 8 I ended up midway through one of the mighty Moock's tutorials that creates a Tamagotchi

Friday 23 January 2009

Day 5 - Things are getting complicated

Today I thought I'd look into what used to be called the hitTest in AS 2.0, maybe they called the same in AS 3.0. I figured I'd need them if I'm going to build an arcade game. I didn't get that far though, cus I ended up having to solve Passing Arguments with Events. This is interesting, cus it's only day 5 and the realisation that I need fairly sophisticated techniques to develop simple projects is becoming apparant.

I'm a bit unsure about work flow aswell
Still at the experimental stage, how should I work? I end up duplicating folders and modifying code to move to the next concept that I want to learn. Possibly should be using some kind of version control

passing parameters tutorials
learningactionscript3.com
onebyonedesign.com

Thursday 22 January 2009

Day 4 - Auto Format / indent in FlashDevelop

Can't get this AutoFormat / Indent Plugin to work, this is a shame, possible be doing something wrong but the keyboard shortcut doesn't work and I can't compile the swf any more. So I disabled it.

Day 4 - Class paths

If need be, you can add classpaths in FlashDevelop in Tools/Global Classpaths. Use import in the class itself; the path you specify will go directly to root of the classpath you entered in global classpaths. Of course, this saves the need to duplicate a class that is better reused.

Day 4 - Adapted LA 3.0 bookcode for Zeno's paradox for FlashDevelop

Ok, I'm reading through many of the examples in the book, but not testing them all. At the moment it doesn't seem too difficult to adapt the code - and I might not adapt any further examples as for now I've established proof of concept.


To adapt the Zeno's paradox code (explained on pg 127 and see video above) all you need to do is move the instance creating code from the fla to a class file. FD just needs .as files, this book example, like many others, has projects split into class .as files. There is often one .fla file that opens in Flash and might use graphical assets in the Flash Library but then uses standard .as class files that can used in FD without modification.

The class below is the main class in FD, and if you right click it in the project window set it to 'always compile'. Remember class names are the same as file names.

package {
import flash.display.Sprite;
import flash.events.Event;
import Ball;
public class ZenoMain extends Sprite {
private var clip1:Ball;

public function ZenoMain() {
clip1= new Ball(20,50);
clip1.x = clip1.y = 100;
addChild(clip1);
clip1.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
function onLoop(evt:Event):void {
clip1.x += velFriction(clip1.x, mouseX, 8);
clip1.y += velFriction(clip1.y, mouseY, 8);
}
function velFriction(orig:Number, dest:Number, coeff:Number):Number {
return (dest-orig)/coeff;
}

}

}
}

then you need a code for a class for a ball like

package {
import flash.display.MovieClip;
public class Ball extends MovieClip{
private var xPos:Number;
private var yPos:Number;
public function Ball(xPos:Number,yPos:Number) {
graphics.beginFill( 0xff0000 , 1 );
graphics.drawCircle( 20 , 20 , 20 );
graphics.endFill( );
trace ("Ball falls")
x = xPos;
y = yPos;
}
}
}

Day 4 - Losing focus a bit

Trying not to lose focus, seem to be more into polishing the blog than writing the code. Anyway I thought it would be cool to add a bit of video into the blog to show example of the code output. As blogger doesn't let you upload swfs and I haven't got any webspace to embed them from. So I thought I'd try Youtube..... Found this pretty cool open source tool called camstudio thats capture swf motion and other screen motion.

Day 3 - Theory

I read more theory. Didn't feel good either so had a bit of lightweight code day. I know excuses, excuses...

Tuesday 20 January 2009

Day 2 - Pg 99 of LA 3.0

I'm going to have a go at modifying the code in the book, to make the graphics work with FD. It looks like it might have to wait till tomorrow. Have to go out for dinner.

Day 2 - Strategy Change

I'm not doing to badly with FlashDevelop, well have installed it, and managed to instantiate classes to draw some primitive shapes on stage. Managed to attached to attach a jpeg also. Problem is when searching for online tutorials, most seem to use the Adobe Flash IDE. This is quite frustrating for learning. This is the same for the books I have. Actually, I haven't took a good look at EAS 3.0, cus I know it is know it is going to be too in depth to start with.

So I've downloaded the trial of Flash CS 4.0 (this lasts a month) and am going to try and follow the examples in the 'Learning AS 3.0' book then try and implement examples in FlashDevelop.

So far, so good. This approach pushes me not just to cut'n'paste but rewrite code to get it to work in FlashDevelop.

I've managed to get the intial part of the inheritance chapter (chapter 6) working in FD. This doesn't use any graphics though.

All I had to do was modify the base Class, which is the .fla in the book.


package {
import flash.display.MovieClip;
import flash.events.Event;
public class MainClass extends MovieClip {
private var vehicle:Vehicle;
public function MainClass() {
var vehicle:Vehicle = new Vehicle(21, 18);
vehicle.go();
}
}
}

Day 1 - attaching a jpeg

this tutorial brings a jpeg into your flash

Monday 19 January 2009

Day 1 - Ball bouncing on screen

Got as far as pg 2 on this tutorial,

http://www.gotoandplay.it/_articles/2006/07/as3intro_p02.php

this means getting a ball bouncing across the screen.

I had to make the BallClip class public to get it to work

Ran into some errors the next pages, but didn't dwell on them. I reckon it better to do a number of basic tutorials than focus on details

download the ball here (link to download at the bottom of page)

Day 1 - auto indent and bkg color of flashdevelop

i'm sure there are solutions for this. But FD defaults with a white bkg for coding, this is harsh. Intial websearchs for this indicate that changing this to a nice dark background isn't going to be a matter of a few mouse clicks. C'est la vie.

No autoformat for indenting text, there is a plugin for this though.
http://www.flashdevelop.org/community/viewtopic.php?f=4&t=3726

Day 1 - This is blog is about my experiance of using FlashDevelop

I've got 2 weeks off work, so I thought I'd squeeze in trying to learning AS 3.0 using flashDevelop 3. I could download the Flex Builder trial, but wouldn't be as cool. Although, I might if I get frustrated with FlashDevelop.

Ah I better say where my skill level is at right now. I've got some coding experiance with AS 2.0 but minimum with OOP and non with AS 3.0. But that's where I want to be at the end of two weeks - some competence in AS 3.0 using OOP.

The idea, behind this blog is that it supports my learning. If I make a hash of stuff I can go back to see where I went wrong and pick up where I left off. Also, it might anyone else looking help - who knows, you might even be able to help me.

Apparantly it's good to be goal orientated. So the idea is by the end of the two weeks I'll have an simple arcade game built, I'm thinking something similar to space invaders.

This is where I'm at now:

I've bought a couple of books:

Essential ActionScript 3.0 - Moock - This book is off the hook, well that's what everyone says, and they probably right. But quite frankly if you ain't a natural coder - it's pretty hard work to get started with AS 3.0 with it. But still it'll probably come in handy later on.

Learning ActionScript 3.0 - Rich Shupe with Zevan Rosser
This looks really promising, but its based on using flash cs 3. Which is cool, but I'd rather try out FlashDevelop. My current thinking is adapt examples in this book for FlashDevelop

If things get tough, I'm think maybe Lynda.com. But I'm going to do this learning thing on mimimum resource for now.

I've installed FlashDevelop with these tutorials I found on the web.

http://nuigroup.com/forums/viewthread/1689/
got a nice video too

Got a trace working with this
http://www.theyak.net/flashdevelop/FlashDevelopTrace.php

that's where I'm at, I'll post soon. Feel free to post comments on anything you like AS 3.0, Flash, random stuff on non-code stuff, it's all welcome, it'd be a nice suprise to find that it's not just me reading this blog.

ps this is currently Day 2.0 and I got 'Hello World' up on Flash, not a bad start I guess.