This blog has moved to a new location! http://iqandreas.github.com/

Friday, December 11, 2009

Debug Text has been updated - now with Documentation!

In addition to making the appearance of the blog a little nicer, I finally got around to updating and creating Documentation for DebugText.


DebugText now has it's very own hosting thanks to a very helpful contributor. :)

The library can be downloaded directly at:
http://iqandreas.isbetterthanyou.org/DebugText/DebugText_1.0.0.zip
(If anyone prefers "rar" or any other compression, just ask)

And the Documentation can be viewed directly in the browser at:
http://iqandreas.isbetterthanyou.org/DebugText/Documentation/


The ZIP file includes the class, ASDoc documentation, and and some example usage.

Check out the old thread for a few examples, all of which can also be found in the example.swf file found in the ZIP:
http://iqandreas.blogspot.com/2009/10/debugtext-onscreen-trace-replacement.html



This is taken directly from the "README.txt" file.
DebugText version 1.0

DebugText is a lightweight, onscreen, visual tracing tool.

This tool was developed because 'trace()' is not always available (like when preloading external SWFs), and the process of creating new TextFields all the time can become a bit of a hassle. The DebugText class will create a small textField on the screen that displays whatever you "trace" out, and instead of several lines of code to make this TextField, one line is enough.

There are two versions of the DebugText class. Both versions use the same code, but different packages:
  • Top level (no package name) - Place the AS file directly into your Global Classpath. Named for convenience, to avoid import statements. It can be moved to a specific package, but then an import statement is required at the top of every class that uses DebugText.
  • aRenberg.utils.DebugText - Requires import statements for each class DebugText is used in.

For sample uses, see the Examples folder.

I hereby release this code to the general public. All users are allowed to use and modify the code as they please as long as they don't publicly take credit for the code as their own work. References to where the code can be found are appreciated, but not required.


Copyright 2009 Andreas Renberg
http://iqandreas.blogspot.com/
http://iqandreas.isbetterthanyou.org/



Now I only have go get around to creating the rest of the Debug suite...

Saturday, December 5, 2009

Simple AS3 VolumeKnob component

An entire month went and not a single post... Sadly, there is a lot of valuable information I learn that I don't put on my blog, which I should, I just never get around to it.


I still haven't written any documentation for it, but I thought I'd throw this out there in case there is anyone else trying to create the same effect.

Pass in a DisplayObject as the "knob", and when the user holds down the mouse and drags around, the volume will increase when rotated to the right, and decrease when rotated to the left.

It is "continuous", like those digital volume knobs, where you can turn without limit left and right, and even if volume is all the way down to 0, you can still keep turning left etc.

Files stored here:
http://iqandreas.isbetterthanyou.org...VolumeKnob.zip
The ZIP contains the class (src/VolumeKnob.as) and one simple example file (src/Main.as) as well as a compiled SWF in the bin directory.
(Thanks to a very helpful donor for the webspace!)


Better description, ASDoc, and examples to come. Refer to comments inside of AS file for more details until then.

Feel free to use and distribute the class freely, but NEVER pass it on as your own work telling others you made it. PLEASE tell me if you end up using it for any projects. It's not a requirement, but it I would like it.

Wednesday, October 28, 2009

DebugText - Onscreen "trace" replacement

Debug text has been updated!
And, DebugText now has it's very own hosting thanks to a very helpful contributor. :) Follow this link for the current version:
http://iqandreas.isbetterthanyou.org/DebugText/DebugText_1.0.0.zip
(If anyone prefers "rar" or any other compression, just ask)

And the Documentation can be viewed directly in the browser at:
http://iqandreas.isbetterthanyou.org/DebugText/Documentation/


The ZIP file includes the class, ASDoc documentation, and and some example usage.


The blog entry with more details can be found at:
http://iqandreas.blogspot.com/2009/12/debug-text-has-been-updated-now-with.html





It's not much, but because trace is not always available (like when preloading external SWFs), and the process of creating new textFields all the time is a bit of a hassle.

The DebugText class will create a small textField on the screen that displays whatever you "trace" out, and instead of several lines, one line is enough. It's just a quick little thing I made in a few minutes, and I definitely plan on expanding on it in the future.


Usage
Place the AS file directly into your Global Classpath. It can be moved to a specific package, but then an import statement is required at the top of every class that uses DebugText.

It is possible to create a new DebugText instance, but it is not recommended. Instead, use the static function "add" to trace output onto a specific DisplayObject (such as the stage or a new or specific sprite)

The first parameter is the container for the DebugText. Note that you can trace to several different locations completely separate to one another by just passing in different values for container. Calling the "add" function several times with the same container passed in will not create multiple instances of DebugText, instead it will add text to the existing DebugText instances.

Since DebugText is a textField, the font can be changed by referencing that DebugText instance which can be made available from either "DebugText.getDebugText(container)" or the instance that is returned from "add()"

Sample
ActionScript Code:
//Outputs to the stage: Hello World!
DebugText.add(stage, "Hello World!");

//The third parameter lets you timestamp the output, but is by default set to false
//Outputs to stage: [0012428] Collision detection completed.
DebugText.add(stage, "Collision detection completed.", true);

//Removes the DebugText instance from the stage, and removes all references for garbage collection
DebugText.remove(stage);

In this example, a lot of items are going to be traced out at once:
ActionScript Code:
var nameArray:Array = ["Andreas", "Brad", "Cedric", ... ];

//Limits to a maximum of 15 lines on the screen at once
DebugText.maxDisplayedLines = 15;

//Trace out all of the names in an array
//Because of the previous line, even if there are more than 15 names in the array,
//only the LAST 15 names will still be visible.
for (var i:int = 0; i < style="color: rgb(0, 0, 255);">length; i++)
{
DebugText.add(stage, "[" + i + "]" + nameArray[i]);
}

//To save everything that has been recorded by a specific DebugText instance,
//use the "listOutput" property
var allNames:String = DebugText.getDebugText(stage).listOutput;

trace(allNames);
//Outputs the following:
// 1 Andreas
// 2 Brad
// 3 Cedric
// etc...


//For verbose output of ALL DebugText instances,
//use the static DebugText.listOutput.
var allOutput:String = DebugText.listOutput;

trace(allOutput);
//Outputs the following:
// [00001291] [object Stage] 1 Andreas
// [00001292] [object Stage] 2 Brad
// [00001292] [object Stage] 3 Cedric
// etc...

One more sample use, here you can trace out directly onto the button when it is hovered over, and hovered out:
ActionScript Code:
btn1.addEventListener(MouseEvent.ROLL_OVER, onOver);
btn2.addEventListener(MouseEvent.ROLL_OVER, onOver);
btn3.addEventListener(MouseEvent.ROLL_OVER, onOver);
// etc...

btn1.addEventListener(MouseEvent.ROLL_OUT, onOut);
btn2.addEventListener(MouseEvent.ROLL_OUT, onOut);
btn3.addEventListener(MouseEvent.ROLL_OUT, onOut);
// etc...

DebugText.maxDisplayedLines = 1;

function onOver(ev:Event)
{
DebugText.add(ev.currentTarget, "OVER");
}
function onOut(ev:Event)
{
DebugText.add(ev.currentTarget, "OUT");
}


TODO (Future updates):
  1. Allow the textField to dock to a specific part of the screen instead of just the default top left
  2. Allow each instance to have a different max characters
  3. Allow each instance to "clear screen" of all existing text
  4. Treat each trace string as an object instead of a string, allowing additional information to be added such as time when traced
  5. Allow users to add monitoring to specific properties, so when that property value changes, the new value is updated on the list (this is reserved for my LiveDebug project, still work in progress)

I didn't add these features yet because it's difficult, but only because I don't need these features yet, but if anyone has any need for them, I can easily add them.


Any more suggestions for improvement?

Fixing Vector Support in FlashDevelop

More and more of my projects are becoming entirely FlashDevelop based, as 98% of the time, I don't need to see the stage. If I do, I code everything in FlashDevelop, and debug it with Flash.

Sadly, I ran into a snag when FlashDevelop didn't want to recognize the Vector class, at least not with code completion. The solution was actually quite simple.

Make sure you have the intrinsic AS file
Browse to the directory where you have FlashDevelop stored (in my case "C:\Program Files\FlashDevelop\".

Continue browsing through to "\Library\AS3\intrinsic\FP10\".
If you have the same setup as me (the default install path) the folder should now read:
C:\Program Files\FlashDevelop\Library\AS3\intrinsic\FP10\

If that folder contains Vector.as, you are good to go on to the next step, otherwise, you either need to update to the newest FlashDevelop, and/or the newest stable release of the Adobe Flex SDK (big file)


Make sure your projects are being treated as Flash 10 and not Flash 9
Finally, (and this was the part that wasn't working for me) on the menu bar, choose Tools > Settings, or press F10.

When the dialog appears, go to "AS3Context", and make sure the "Default Flash Version" is set to 10, instead of the default 9.


While you are in there, take the time to make sure other settings are set to your preference, such as class paths and the SDK location.


If it's still not working for someone, post a comment, and I'll try to debug it.

Friday, September 18, 2009

Wii Internet Channel with FlashLite 3.1 confirmed!

In my last post regarding Flash on the Wii, I was still looking for a reliable source to confirm that the new browser definitely had support for FlashLite, and it wasn't just a lousy rumor.

I was overjoyed to read the following message in my Wii Message board:

From Nintendo:
The Internet Channel, which allows everyone to easily access and enjoy the Internet, has been updated.

The main updates are as follows:
* Change from Adobe Flash version 7 to Adobe Flash Lite 3.1 (This corresponds to Adobe Flash version 8)
* The Internet Channel is now available to download for 0 Wii Points.

Press start at the bottom right of the screen and you will be able to download the updated Internet Channel from the Wii Shop Channel.

If you previously used 500 Wii Points to download the Internet Channel to your Wii console, at the end of October we will be offering you the opportunity to download, for 0 Wii Points, one NES game of your choice (valued at 500 Wii Points) from the Virtual Console catalog. Details of this download offer will be provided via the Wii Message Board or on Nintendo.com soon.

Nintendo




So, now all I have to do is decide which NES game I would like to download... Hmmm...

On a related note, I find it funny that Nintendo offers one NES game for up to 500 points instead of offering any software for 500 points or just putting 500 points onto your account. In an article I read recently, certain distributors (or something or the other) received rewards for putting offline Wii users online. After 10 rewards, they were granted full access to download and and all NES games they wished.

So why only NES games? My guess is that Virtual Console NES game sales aren't really doing that great compared to many of the WiiWare and newer Virtual Console games, so Nintendo is really pushing to make a greater profit and get those games distributed.

Of course, that's just my educated guess, and I could be wrong...


Time to start developing Wii Friendly games. :)

Thursday, September 17, 2009

Most common Flash Questions (AS3 FAQ)

When you help out beginners as much as possible each day, you tend to hear the same questions again and again (and again, and again).

Ignoring the fact that when I was little, I used to think FAQ was a bad word (not joking), I have here compiled a few links for threads with the most frequently asked questions in the Kirupa.com ActionScript 3.0 Forums.


TypeError: Error #1009: Cannot access a property or method of a null object reference.
Hands down, with no doubt possible in anyone's mind the absolute #1 error. There are 2 possible causes:


Duplicating a MovieClip (or at least creating a new version of whatever you pass in)
http://www.kirupa.com/forum/showpost...80&postcount=3
http://www.kirupa.com/forum/showthread.php?t=333120
http://www.kirupa.com/forum/showthread.php?t=334933 - Didn't realize the "constructor" property was so vulnerable. Nice discussion.


The difference between instance name and library name
http://www.kirupa.com/forum/showthread.php?t=333041


The Dictionary Class (Passing in custom variables to Events)
Personally, I really like using it since it allows you to pass in other variables to events such as telling which URLs go to which buttons, so you can use one function for the onClick event.
http://www.kirupa.com/forum/showthread.php?p=2484903
http://www.kirupa.com/forum/showthread.php?t=331118
http://www.kirupa.com/forum/showthread.php?p=2501990 - Some sample usage


Wow! How can I learn to be a great coder like you?
First of all, I'm good with Logic, but sadly I often use Flash instead, which is often similar, just uglier and meaner.
http://www.kirupa.com/forum/showpost...51&postcount=6 - Some great reading
http://www.kirupa.com/forum/showpost...85&postcount=2 - The Flash and PHP Bible


The advantage of using static properties and functions
I need to dig out an old MSN messenger discussion on this as well. It's on my rediculously long todo list.
http://www.kirupa.com/forum/showthread.php?t=334492


The strange way frames work in Flash
http://www.kirupa.com/forum/showthread.php?t=325891 - How frames really work. Might need some updating as this was posted early on when I was first learning Flash.
http://www.kirupa.com/forum/showthread.php?t=325884 - This guy still owes me a beer


There are plenty more, I just want to avoid digging through all 600+ of my forum posts for the gold nuggets. If anyone finds any more (by me, or anyone else for that matter) comment.

What's AS3 got that FlashLite doesn't?

I thought I was going to have to dig around for a while, perhaps comparing the language reference class for class until I found this, but it turns out Adobe already had the differences listed. (whew!)

Taken from:
http://livedocs.adobe.com/flashlite/3.0/docs/help.html?content=00005655.html


Unsupported Classes

  • Accessibility
  • Camera
  • ContextMenu
  • ContextMenuItem
  • CustomActions
  • LocalConnection
  • Locale (mx.lang.Locale)
  • Microphone
  • NetConnection (Available in FlashLite 3.0, but not FlashLite 2)
  • NetStream (Available in FlashLite 3.0, but not FlashLite 2)
  • PrintJob
  • TextField.StyleSheet
  • TextSnapshot
  • XMLUI

Unsupported Methods (Functions)
  • Mouse.hide, Mouse.show
  • MovieClip.attachAudio
  • MovieClip.getTextSnapshot
  • Selection.getBeginIndex, Selection.getCaretIndex, Selection.getEndIndex
  • System.setClipboard
  • System.showSettings
  • TextField.getFontList
  • Video.attachVideo (Available in FlashLite 3.0, but not FlashLite 2)
  • Video.clear

Unsupported Properties
  • Button.blendMode, Button.cacheAsBitmap, Button.filters, Button.menu, Button.useHandCursor
  • System.capabilities.language, System.capabilities.manufacturer, System.capabilities.pixelAspectRatio, System.capabilities.playerType, System.capabilities.screenColor, System.capabilities.screenDPI, System.capabilities.serverString
  • Key.isToggled
  • MovieClip.menu
  • MovieClip.useHandCursor
  • Stage.showMenu
  • System.exactSettings
  • TextField.menu, TextField.mouseWheelEnabled, TextField.restrict
  • Video._alpha, Video.deblocking, Video._height, Video.height, Video._name, Video._parent, Video._rotation, Video.smoothing, Video._visible, Video._width, Video.width, Video._x, Video._xmouse, Video._xscale, Video._y, Video._ymouse, Video._yscale

Unsupported Global Functions

  • asfunction
  • MMExecute
  • print, printAsBitmap, printAsBitmapNum, printNum,
  • updateAfterEvent

Unsupported Event Handlers
  • onUpdate
  • Mouse.onMouseWheel

Unsupported fscommands
  • allowscale
  • exec
  • fullscreen (I wonder if that means that FlashLite apps are unable to go fullscreen, or if you are just not able to set it to fullscreen via fscommand)
  • quit
  • showmenu
  • trapallkeys


Luckily, most of them are quite logical exclusions such as classes related to right clicking, using the cliboard, and accessing usb components such as the camera, microphone, or printer. The other methods and properties I rarely use anyway, so I could possible mark many as my custom classes as "FlashLite Safe". :)

Wii Internet Channel now supports Flash!

Good news developers! As a followup to my earlier (rather short) post regarding future Flash support for the Wii, it seems as though my hopes have come true (mostly).

I recently was able to get my Wii connected to the internet again, when I stumbled upon a notice that the Internet Channel had a new update available. Curious, I prowled the web for any information regarding this new update. Sadly, I found no official source, however the Internet Channel's Wikipedia page state:
"In addition it updated Flash Player to Adobe Flash Lite 3.1 which corresponds to a full implementation of Adobe Flash version 8 with certain features of Flash 9." -- Footnote: The Wii Browser now Identifies its self as "AFL 9,1,122,0" to Flash applications as can be seen by visiting
http://kb2.adobe.com/cps/155/tn_15507.html in the Wii Browser.

So, Flash Lite, that is a great start on Nintendo's part. Sadly, it doesn't contain the fancy 3d features of Flash 10 or even the Vector class I love so, but it is a start.

For people wanting to start developing in FlashLite, it is basically like regular ActionScript, but 'stripped down' missing several libraries. If I can find some time I'll try to track down a list of what classes FlashLite is lacking.

Until then, here are some helpful links for aspiring FlashLite developers:
Adobe's FlashLite FAQ - http://www.adobe.com/products/flashlite/faq/
Adobe's "Getting Started With FlashLite 2.x and 3.0" - http://livedocs.adobe.com/flashlite/3.0/docs/help.html?content=Part4_API_Ref_1.html
And of course, my favorite, the Language Reference, can be found on that same page as listed above.


Also, as a final note, here are a last few Wii/Flash links I have yet to look into which look (at least two of them) promising:

WiiFlash (http://wiiflash.bytearray.org/)
Connects directly to the WiiMote using your computer's BlueTooth connection, and accesses it from Flash through your localhost address. Pretty smart. :) That would be a great workaround for many features not currently available natively in Flash. I seem to be getting "Security Sandbox" errors, but it seems like it's working for other people. Not sure if it works in online games, though.

WiiCade API (http://wiicade.com/home.aspx)
There is supposed to be some sort of support for which allows you to use the "arrow buttons" on the Wiimote as if they were the WASD keys on the keyboard. I'm not sure how they pull it off, and current games look quite crappy and cheap. If anyone has any experience in using this API, please comment.

Wii Opera SDK (http://wiioperasdk.com/)
It looks like a thirteen year old who just learnt how to use FrontPage developed the site, so I can't help but be a little suspicious. I have no earthly idea what kind of support this has, so again, any outside comments are appreciated.

Wednesday, September 9, 2009

Error: Error #2071: The Stage class does not implement this property or method.

Error: Error #2071: The Stage class does not implement this property or method.
at Error$/throwError()
at flash.display::Stage/set x()
at Untitled_fla::MainTimeline/frame1()[Untitled_fla.MainTimeline::frame1:1]
Similar to Error #2069, Error #2071 occurs when you try to set stage properties that have been overriden.

To quote the ActionScript 3.0 Language Reference:
Quote:
In addition, the following inherited properties are inapplicable to Stage objects. If you try to set them, an IllegalOperationError is thrown. These properties may always be read, but since they cannot be set, they will always contain default values.
  • accessibilityProperties
  • alpha
  • blendMode
  • cacheAsBitmap
  • contextMenu
  • filters
  • focusRect
  • loaderInfo
  • mask
  • mouseEnabled
  • name
  • opaqueBackground
  • rotation
  • scale9Grid
  • scaleX
  • scaleY
  • scrollRect
  • tabEnabled
  • tabIndex
  • transform
  • visible
  • x
  • y
Logically thinking, you can't really set the x, y, or rotation values of the stage, since it is supposedly "God", what everything else in Flash is measured against. Sure, if the user is running a SWF as a projector or through the debugger, they can move the dialog box around, however, this doesn't really change the x and y values of the stage, as the stage will still always be at 0,0 inside of its container.

If you want to measure any farther, you will have to start measuring in the operating system's coordinate space. That's going a little too far, and is even outside of Flash's capabilities.

Also note that the following stage properties are overriden, and throw errors if you try to set them. These are different than the properties listed above because they will hold actual values, not just the default ones, but you are still not allowed to modify them.
  • height - can be read, but throws an IllegalOperationError if set
  • width - can be read, but throws an IllegalOperationError if set
  • stageHeight - is able to be set, and will not throw an error, but it seems as though changing this property has no effect on the stage, at least not when run in the Debugger Player
  • stageWidth - is able to be set, and will not throw an error, but it seems as though changing this property has no effect on the stage, at least not when run in the Debugger Player
  • textSnapshot - cannot be read or accessed. Should be in the list above, but I'm not sure why Adobe didn't include this property to the list.

NOTE: Unless you like boring nitty gritty details, you can just stop reading right here. The rest is just for reference.

In addition, some properties and methods cannot be run outside of the stage's security sandbox without the proper permissions, so those methods are overridden just so Flash can check their security credentials. They act just as the regular methods they override with the difference that they will dispatch a SecurityError if accessed by an object outside of the current sandbox.

The affected properties all have to do with children and are "mouseChildren", "numChildren", and "tabChildren". The affected methods that have to do with containing children are addChild(), addChildAt(), removeChild(), removeChildAt(), setChildIndex(), and swapChildrenAt(). Finally, the only other affected methods have to do with Event Dispatching, and are all overriden for security checks; addEventListener(), dispatchEvent(), hasEventListener(), and willTrigger(). Strangely enough, removeEventListener(), doesn't require a security check...

However, don't bother memorizing them as these methods will act just like any other display object to outside users, and won't affect your code at all.



Thanks to Senocular for pointing much of this out.

Error: Error #2069: The Loader class does not implement this method.

Error: Error #2069: The Loader class does not implement this method.
at Error$/throwError()
at flash.display::Loader/addChild()
at Main/onXMLComplete()[C:\Documents and Settings\Andreas\Desktop\temp\menu_8_sept\Main.as: 116]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Following this error number leads to a simple line:
ActionScript Code:
var imgLoader:Loader = new Loader();
var preloader:Preloader = new Preloader(); //Just a little custom preloader class that says "Image Loading"
imgLoader.addChild(new Preloader()); //ERROR #2069



At first thought, this should be possible. Checking the language reference, the Loader class extends "DisplayObjectContainer", so it should indeed have that function.

In fact, all of the following functions will give an error message:
  • addChild()
  • addChildAt()
  • removeChild()
  • removeChildAt()
  • setChildIndex()


The answer is hidden away in small print inside of the Language Reference:
Quote:
The Loader class overrides the following methods that it inherits, because a Loader object can only have one child display object—the display object that it loads. Calling the following methods throws an exception: addChild(), addChildAt(), removeChild(), removeChildAt(), and setChildIndex(). To remove a loaded display object, you must remove the Loader object from its parent DisplayObjectContainer child array.
So, basically, because the Loader class can only ever contain one item, you are not allowed to run functions on the loader class that change how many items are inside of the loader.

As usual, the ActionScript 3.0 Language Reference is your best friend.

Thursday, August 13, 2009

TIP: Tweening Functions

I often get annoyed by the fact that most tweening engines do not allow the tweening of functions.

Here is how you work around that!

This example will be using TweenLite, but if anyone wants me to write similar code for other Tweening engines (such as GTween or Tweener), just ask.


Here I will be tweening the graphics.lineTo() function to draw a simple line from the top left corner of the stage down to the bottom right, straight through the center of the movie, but tweened!

The key is creating a new object, and then applying the needed properties of that object to the function you want to run.

ActionScript Code:
import gs.TweenLite;

//This sprite is what we will draw the lines on, insead of drawing them directly onto the stage.
var lineSprite:Sprite = new Sprite();
this.addChild(lineSprite);

//The key is to create a new object, and put tweenable properties on it
var drawObj:Object = new Object();
drawObj.targetObject = lineSprite;
drawObj.x = 0;
drawObj.y = 0;
drawObj.endX = this.stage.stageWidth;
drawObj.endY = this.stage.stageHeight;

TweenLite.to(drawObj, 5, { x:drawObj.endX, y:drawObj.endY,
onStart:startDraw, onStartParams:[drawObj],
onUpdate:updateDraw, onUpdateParams:[drawObj] } );

function startDraw(obj:Object):void
{
obj.targetObject.graphics.lineStyle(5, 0x000000);
obj.targetObject.graphics.moveTo(obj.x, obj.y);
}

function updateDraw(obj:Object):void
{
//Here is where all the action happens.
//This code is executed each and every time the tweening engine changes the value of x or y
//Here is where you place the function you want to tween, and use whatever parameters are needed
obj.targetObject.graphics.lineTo(obj.x, obj.y);
}



That code can also be abbreviated down a lot. This code is less clear to read, but will run faster. Also, instead of creating a new function that will call the function to be tweened, the lineTo() function will be called directly.
ActionScript Code:
import gs.TweenLite;

//This sprite is what we will draw the lines on, insead of drawing them directly onto the stage.
var lineSprite:Sprite = new Sprite();
this.addChild(lineSprite);

//The key is to create a new object, and put tweenable properties on it
var drawObj:Object = {targetObject:lineSprite, x:0, y:0, endX:this.stage.stageWidth, endY:this.stage.stageHeight};

//Prepare the sprite for drawing
//This code was originally in a startDraw function
drawObj.targetObject.graphics.lineStyle(5, 0x000000);
drawObj.targetObject.graphics.moveTo(obj.x, obj.y);

TweenLite.to(drawObj, 5, { x:drawObj.endX, y:drawObj.endY,
onUpdate:obj.targetObject.graphics.lineTo,
onUpdateParams:[drawObj.x, drawObj.y]

Sunday, June 7, 2009

Fonts for your Game - How much is too much?

I was browsing around a very helpful site with a lot of great blog entries specifically aimed at developers interested in sponsorships as well as other post-development categories. http://freelanceflashgames.com/


A lot of the information is really helpful, and even though the few code samples that are there are mainly in AS2, I would really recommend taking a look at the site. Some information, though, seems quite obvious, such as advice of being polite or kind to sponsors even if they refuse to sponsor you. Perhaps that just comes naturally to me and seems obvious, while to others it might be more helpful, but nonetheless, it contains a lot of valuable advice.


One post that caught my attention, though, was a post regarding finding fonts for a game. http://freelanceflashgames.com/news/2008/07/18/fonts-for-your-game/ So I replied:
I was just a bit curious about the quote "Nobody wants to look at a bland default font while their playing a game."

I'm not sure I fully agree with that. If special and fancy fonts are used in moderation, then yes, of course. However, when reading long segments such as people talking in little speech bubbles or reading a tutorial or letter in the game, you really don't want something ridiculously extravagant. It's difficult to read, and gets annoying after a while. Also, unless you embed the font, it might not show up the same on all computers (meaning that a signpost might bleed over some of the text outside the main area, even if just slightly)

Here is my rule of thumb, as long as the main title of the game is readable, fancy fonts give it a fantastic effect, but for long segments of text, you really don't want to be trying to read something written like this (I picked the first font I saw from the recommended site Dafont) http://www.dafont.com/holiday-home.font

I haven't seen this problem a lot in games, but at in schools and such (or anywhere where you will find a beginner and a word processing program) you see sheets printed out by people who went crazy with the font and text size buttons. I must confess, when I was 13 I myself made these blunders all the time.

I have learned that often simplicity it what is the most appealing, at least for adults. Children might be different. In fact, that is the whole idea behind Feng Shui. The human mind feels more relaxed looking at a clear table than one that is filled with nick-nacks and bricka-breck. Although it looks fun at first and is mentally stimulating, it becomes wearisome after a while.

Just take a look at this site as a perfect example. ALL the text on the site (including buttons and text in banners) seems to be Arial or some simple, similar font, all moderately sized. The only things that use an original font are two brand names, Mochiads and Evony. Those names stand out, as they should, and any other text on the page is not overly distracting or annoying.


That's just my 52 cents. I might be wrong. Any other opinions?


Anyway, love the really handy links as well as all your other really helpful posts.

Andreas J. Renberg

Tuesday, June 2, 2009

Flash 9+ for the Wii? [And more links + praise for FireFox]

FireFox, and its glorious offline tabs

Since I have a 45 minute commute to and from work (and luckily, I'm rarely the one driving), and at work I have no time to read up on blogs and sites, when I get to work and during my breaks, I find something interesting or try to find the solution to some problem that has been bugging me.

Then, instead of reading the post or blog (which usually ends up being pretty long and not worth spending my precious break time on) I open it in a tab in FireFox. Often, I'll notice an interesting title in the sidebar, which leads to another post, so I open it in another tab to read later. This process repeats several times during the day.

Finally, when I leave work, I have 40 different tabs containing all sorts of interesting information. The problem is, when I get home from work, I am to tired to stare at a screen, trying to comprehend with a blurry mind what some see as a clear solution to one of my problems. So the next day I go to work, still holding those 40 tabs, ready to be read. But during break, I accumulate even more!

So then you get to the point I am at now; 6 windows and 87 tabs (exactly, according to FireFox). And when you think you are all set to go, Windows XP decides to restart the computer and apply all those updates he thinks is so very important. [Tears hair from head, wanting to explode]

Thank goodness for the built in Session Restore feature. I don't know what I would do without FireFox, even though I believe that the programmers at Microsoft put in some sort of bug system that targets FireFox, hoping that internet users will switch over to the new and improved Internet Explorer [plays fanfare] .... not happening. FireFox is my friend, and I will never be unfaithful.

Enough about FireFox, on with the links!



Math.getProbability(Nintendo.Wii + Adobe.Flash));

I was Googling around, searching for any hope that Wii's built in browser might support might some day support Flash 9 or 10 (more specifically, AS3). That way, I wouldn't have to find an oldschool coder to convert my complex and likely sloppy code to slow, inefficient AS2.

I stumbled across this link, which brings a little hope to my heart, but sadly I can't verfiy the aucenticity of the information. I really hope so, but I wouldn't guarantee anything. It doesn't say anything about adding support for the browser, but it will allow Flash Developers to create games for WiiWare without having to learn a new language. :D

http://nintendo.joystiq.com/2009/03/13/cave-story-dev-nintendo-opens-wii-to-flash-development/

Now the big question is, will WiiWare development be open to anyone, or just people who pay an outrageous price for the WiiSDK and have a full fledged corporation where the proprietary information can be stored securely?

If anyone can verify this information with hard, cold evidence, please leave a comment or email me.



An important announcement from Developers woldwide:
Do you see the ads at the bottom of the page? Click them.

Most developers work for free, and the only money they earn is from advertisement income. It doesn't cost you a penny to click the link, and usually, you might find some pretty good deals or learn about a new neat site.

So give those developers a chance! Help keep free software... FREE!

CLICK THE ADS! (of other developers)

-- A message from your local department of coders.


So I encourage everyone, right now. Put down what you are doing. Stop thinking about how tired you are getting off this site. Next time you are on someone's site, show some appreciation, and click. Enjoy the great deals you find from clicking the ads, and deep inward satisfaction that you are putting food in my belly and getting me (legal people, read: others) through college. :)

Ads can actually be quite beneficial. For example, I recently clicked a link for an RTS game, and I'm actually enjoying it. (No, I won't give out the site address unless I get paid to advertise it)




More links to come once I get some sleep... Work tomorrow as well... Ugh...

Friday, April 10, 2009

Understanding the AS3 "1203 No default constructor found in base class %s. " Error

Gather 'round children, and I will describe to you the 1203 error in child friendly Layman's Terms.

"1203 No default constructor found in base class %s.
You must explicitly call the constructor of the base class with a super() statement if it has 1 or more required arguments."



When you extend a class in AS3, flash will automatically add a function that initializes the class that you are extending.

For example, let's say you have a "ship" class. When you create this class, you have a whole bunch of functions that create walls, shields, passenger compartments, motors, etc.

ActionScript Code:
public class Ship
{
public function Ship():void
{
//Here you will build the ship, and make sure it is functional.
this.buildHullAndWalls();
this.buildPassengerCompartments();
this.addElectronics();
this.addNavigation();
this.addMotors(new HyperDrive(), new SublightEngine());
this.addSheilds();

if (this.scanForDefects())
{
emailCaptain("Ship is in working order and ready to go! :) ");
}
else
{
emailCaptain("There is something wrong! There are problems with this ship still!");
throw new ShipBuildError("An error occured when building the ship. Please wait for repairs.");
}
}

}



Now, when you want to extend a class, it is like creating a new version of the parent class AND adding to it.

So to create a Cruiser (basically a basic ship with weapons), you could write all this out:
ActionScript Code:
public class Cruiser
{
public function Cruiser():void
{
//Here you will build the ship, and make sure it is functional.
this.buildHullAndWalls();
...
this.addSheilds();
this.addWeapons();

if (this.scanForDefects())
{
...
}
}

}


But doing this for each and every ship that extends the Ship is long, tedious, and memory consuming. Also, if you want to make any changes to the way the ship works (for example, adding the shields before you add the motors), you have to go back and change that code in every single ship that is built from a Ship, or extends the Ship.

So to have the Cruiser extend Ship:
ActionScript Code:
public class Cruiser extends Ship
{
public function Cruiser():void
{
this.addWeapons();
}
}



This simplifies making ships immensely, however, we have one (major) problem. Here, you are telling the crew to start adding weapons to the ship. That's fine and dandy, but where is the ship? You haven't told the crew to start building a ship yet! How are they supposed to add on the weapons?

Luckily, The Flash Compiler (known to his friends as "Foreman Flash") realizes this, so when you tell the crew to start building the ship, Flash looks through the list of tasks for the crew to do. He realizes that you are technically building a ship, and since the builders can't add anything to the ship until the ship is built, he adds a task for the builders at the start of the list. He tells them "First, build a standard ship, like the one you made for Larry last month. Then, add weapons to it, and make it a cruiser instead."

ActionScript Code:
public class Cruiser extends Ship
{
public function Cruiser():void
{
super(); //This means, do everything that the super class (or Ship) does to start out.
this.addWeapons(); //Now you can add weapons when you have a ship built!
}
}



That's OOP 101. However, sometimes things get a little more complicated than that. What if in order to build the standard Ship, the builders have to know how many passengers it will hold. Otherwise, they don't know if they should build a little or a small ship.
ActionScript Code:
public class Ship
{
public function Ship(howManyPassengers:Number):void
{
//Here you will build the ship, and make sure it is functional.
this.buildHullAndWalls();
this.buildPassengerCompartments(howManyPassengers);
this.addElectronics();
this.addNavigation();
this.addMotors(new HyperDrive(), new SublightEngine());
this.addSheilds();

if (this.scanForDefects())
{
...
}
}

}



Now we run into a problem. Foreman Flash has the task of building another Cruiser. As usual, he looks through the list to check if the ship can be built, so cruiser weapons can be added to it. Realizing that someone forgot that command, he again adds super() to the list, and the builders start working.

The builders start gathering supplies, when one person calls out "Wait a minute! How big is this ship supposed to be? Foreman Flash, we do not know how many passengers this thing will hold!"

Foreman flash looks at his clipboard again and again, but he has no idea of how big the client wanted the cruiser. He is now confused, and the builders are getting angry. Guessing a random numbe could be disasterous.

"1203 No default constructor found in base class! Help! I'm confused! No one ever told me what to do! I can't build without proper instructions!"

There is your error.


Next time, the ship buying millionare is smarter. When he orders a Cruiser, he says "I want the ship to hold 24,000 passengers. Get it done right this time."

ActionScript Code:
//This code is run elsewhere, perhaps on the main timeline
var NumberOfPassengersForMyCruiser:Number = 24000;
var MyPimpedOutCruiser:Cruiser = new Cruiser(NumberOfPassengersForMyCruiser);

//Here is the actual class located elsewhere.
public class Cruiser extends Ship
{
public function Cruiser(passengers:Number):void
{
super(passengers); //Now we add building the ship to the list so the Foreman doesn't have to worry about adding it himself.
this.addWeapons(); //Now you can add weapons, because the builders know how big the ship will be!
}
}



Another way of doing this, is perhaps there is a law in place which states that all cruisers must be built for 40,000 passengers. No more, no less.
ActionScript Code:
public class Cruiser extends Ship
{
public function Cruiser():void
{
super(40000); //Because the super() command just won't suffice!
this.addWeapons(); //Now you can add weapons, because the builders know how big the ship will be!
}
}



Or, if you are really smart, you could change the plans of the Ship design to say that, unless you hear anything differently, the ship will always be built for 30,000 passengers.

ActionScript Code:
public class Ship
{
public function Ship(howManyPassengers:Number = 30000):void
{
//Here you will build the ship, and make sure it is functional.
this.buildHullAndWalls();
this.buildPassengerCompartments(howManyPassengers);
this.addElectronics();
this.addNavigation();
this.addMotors(new HyperDrive(), new SublightEngine());
this.addSheilds();

if (this.scanForDefects())
{
...
}
}

}


Now the Cruiser class can look like this:
ActionScript Code:
public class Cruiser extends Ship
{
public function Cruiser(passengers:Number):void
{
//Don't bother adding the super() command here. The Foreman will do it automatically. That's what he's getting paid for. :)
//You can add it if you want to, but I say it is a waste of your time.
this.addWeapons();
}
}


When the Foreman looks through the list, he sees that you never told the workers start building the ship. "No problem, I'll just add the super() command here."

Then the builders receive their instructions. "First, build a ship, then add weapons to it. Wait! The foreman never told us how many passengers he want the ship to hold. Oh well, by default, they want 30,000 passengers, so we will just do what we usually do."

No errors. Everyone is happy.



Now. To go back to your code...
ActionScript Code:
package
{
import com.RadarPoint;
public class Rp1 extends RadarPoint
{
function Rp1():void
{
trace("YEAY! New RadarPoint child RP1 created!");
}
}
}


The Foreman looks through this code, and sees that you are building a RadarPoint, but you never told the workers to start building the RadarPoint! Proposterous! He quckly adds it to the list and send the workers on their way.

ActionScript Code:
import com.RadarPoint;
public class Rp1 extends RadarPoint
{
function Rp1():void
{
super(); //Added by the foreman.
trace("YEAY! New RadarPoint child RP1 created!");
}
}


So the workers look at the list, and start building a Radar Point. "Woah!! Big problem!! Foreman!!! We don't know what the values of newProp1:int, newProp2:Number, and newProp3:String are supposed to be!!"

ActionScript Code:
import flash.display.Sprite;
public class RadarPoint extends Sprite
{
function RadarPoint(newProp1:int, newProp2:Number, newProp3:String):void
{
this._prop1 = newProp1;
this._prop2 = newProp2;
this._prop3 = newProp3;
}
}



Next time, when the millinaire is ordering his brand new RP1, he remembers to tell the foreman and the builders what specifications he wants, avoiding any confusion:
ActionScript Code:
package
{
import com.RadarPoint;
public class Rp1 extends RadarPoint
{
function Rp1():void
{
super(3467, -345.37327, "Red/Blue");
trace("YEAY! New RadarPoint child RP1 created!");
}
}
}


Moral of the story, always tell Foreman Flash what to do, otherwise he gets mad and thows errors and swearwords in your way.



I should win a Pulizer.

Sunday, April 5, 2009

Blender 3D - Mobile Intel 965 Express Chipset Family Driver Problems

This post is mostly copied and pasted directly from my post in the blender.org forums.
http://www.blender.org/forum/viewtopic.php?t=14331

Problem
Whenever I try to type anything into a text field in Blender, it will not show up, neither the IBeam nor the new text. I can't even remove any old text. However, when I click outside (or deselect) the textfield, whatever I wrote in the textfield, any new values or any modifications, show up. The biggest problem is that you have no idea if you have made a typo until you deselect the textfield. This happens to every text field in the entire program, weather it's saving your project, or inputting a numerical amount.

My Hardware Specs
Although this should work for many other computers and blender releases, here are my hardware specifications:

Blender
Blender Version 2.48a
Python Version 2.5

Computer/Laptop
HP Compaq 2710p
Microsoft Windows XP - Tablet PC Edition 2005
Version 2002 - Service Pack 3
Intel(R) Core(TM)2 Duo CPU U7600 @ 1.20GHz
790 MHz, 2.99 GB of RAM (?? I thought I had 4 Gigs...)

Graphics Cards
Mobile Intel(R) 965 Express Chipset Family
Mobile Intel(R) 965 Express Chipset Family


Solution
No matter how I tried to install the driver, since I am running Windows XP Tablet Edition, it would not update to the new version. So I finally found a way around it.

Download the ZIP of the driver (not the EXE) from http://downloadcenter.intel.com/confirm.aspx?httpDown=http://downloadmirror.intel.com/17179/a08/win2k_xp1437.zip&agr=&ProductID=2800&DwnldId=17179&strOSs=&OSFullName=&lang=eng and unpack it to the desktop (or any temporary folder for that matter).

Go to Start and right click "My Computer", and choose "Properties".

Click "Hardware" and then the "Device Manager" button.

Click "Display Adapters" so it expands to reveal "Mobile Intel 965 Express Chipset Family". Right click that, and choose "Update Driver". That should reveal the "Hardware Update Wizzard" dialog.

Select the "Install from a list or specific location (Advanced)" radio button, and click next.

IMPORTANT: Then select "Do not search. I will select the driver to install." and click next.
Note that choosing "Search for the best driver in these locations" will not work. It will not recognize the new driver as better than the one you already have.


Click the "Have Disk" button, and then "Browse" in the dialog that appears.

Browse to the location to where you unpacked the new driver, and then open the "Graphics" folder. Double click on the file named "igxp32.inf", and then click "OK".

The driver "Mobile Intel 965 Express Chipset Family" should now appear in the list. Make sure it is selected, and then click next.

Wait while Windows copies over the new driver files. When it is finished, it should prompt you to restart the computer. Note that the new settings will not take effect until the computer is restarted, but this can be done at any time.


Hopefully this will make a difference for anyone out there. It did for me. :)

The 7 Wonders of the Flash World [The Best and Most Beautiful uses of Flash]

When browsing around online, you realize how rampant Flash is. Most of the time, you see the same old, same old, and each time you enter a new site, you pray "Please God, don't make this site have another slideshow made in Flash!"

Then there are those sites, often made for big Hollywood movies, that take 10 minutes to load, and all they do is let you see trailers and photos for the upcoming movie, and links to where you can download wallpapers cluttered with titles, logos, and release dates.

Cheap interactive advertisements on the side of pages, where you just can't help but click to speed up santa so he can outrun the elf, or shoot the ducks, seeing how many you can hit before you are forcibly redirected to some site that wants your credit card number in return for sending you "free" stuff.

Video sharing sites, where you can find anything from a guy waving a lightsaber around almost dislocating his shoulder to a ninja giving advice on life. Thousands of Terrabytes of video, filled with thousands of duplicates of other videos hosting TV shows, movies, and some crap someone made in 3 minutes with their webcam.

Game sharing sites, where you can waste hundreds of hours doing something that won't make anyone's life any better (or so they say. I disagree. The more you play, the more developers like me get paid!), most games only a clone of a classic or previously made game.

Finally, there are those sites filled to the brim with embedded with YouTube videos and Flash Games, often made by 13 year olds who have just found the glory of using templates and hosted websites.

Is there nothing original with Flash anymore in this world?


Now and then, I stumble upon a gem online, something original, so amazing that it cannot be described by words, but requires Flash to display it's pure beauty. Maybe it's the developer in me who sees these gems, amazed by how much time and effort must have been put in to making this possible, or perhaps the child in me, amazed by all the special effects and flashing lights.

Nonetheless, to free you out of the dark days where everything online made in Flash looks exactly the same, I bring you SWF files that stand out beyond the rest:



IKEA - Kitchens You Dream About
http://demo.fb.se/e/ikea/dreamkitchen/site/default.html
http://www.ikea.com/ms/en_CA/rooms_ideas/ckl/default.html
Countless hours rendering the output from your 3d modeling program have brought you what? A fantastic display of kitchens frozen in time where you can fly around from house to house looking at kitchens and activities therein. Beautiful.


Soy Tu Aire (I am your Air) - More than just music
http://soytuaire.labuat.com/
Despite being rediculously long to load (like all worthwhile flash apps are) this is a beautiful display of what would happen if you mixed a Japanese Paint program with Windows Media Player. I wish there was more music set up to play this way.


GE - Plug Into the Smart Grid - Argumented Reality
http://ge.ecomagination.com/smartgrid/#/augmented_reality
If you don't have a webcam, get one! This display is totally worth the 5 dollars you spend on a cheap camera. Also requires a printer. When you print out the sheet on the page, hold it up to the camera, and watch it come alive.
If you don't have a camera or a printer, at least watch the "See how it works" video, so you at least you know what you could have spent the last 5 minutes messing around with and thoroughly enjoying!



And then there was Salsa!  [Added Mar 5, 2010]
http://vimeo.com/9194146
Looks like an ordinary commercial? Prepare to be amazed...


Mercedes from A to S  [Added Mar 13, 2010]
http://www.a-to-s.co.uk/home.php
The ambient music (that's what it's called right? I have never been good with this 'new-agey lingo') sets a nice mood for these ninteneen different interactive slides which each bring out some little information about their suite of cars.
Many of the effects, although very neat, are actually quite simple. I might even write a small tutorial one day, taking one effect at a time and explaining how it was done.


The Scale of the Universe  [Added Mar 14, 2010]
http://primaxstudio.com/stuff/scale_of_universe.swf
You never realize what a tiny speck earth is in the middle of nowhere. This interactive display lets you zoom in and out of the known universe from the Strings of String Theory to the edge of the known and observable universe.
The images are mostly low quality and vector based, but they still get the point across, and if they hadn't been drawn in vector, you would likely need to wait 15 minutes for the entire presentation to load, so it works just the way it is and is still very well done.


The Eco Zoo  [Added Mar 26, 2010]
http://www.ecodazoo.com/
If you take a close look a the animals there, you might be able to get some tips to live in a more environmentally friendly way. 
A fantastic interactive 3d presentation. I'm not sure if they are using a publicly available library such as Papervision, or if they are using their own library, but whatever the case, it is very smooth and nice. One thing I didn't realize at first was that you can move around in the pop-up book scenes like you can in the main tower scene.
This is how story books are meant to come to life. Just add a story narrated by James Earl Jones, and make each character move around, and you have got yourself a story book that even the technology spoiled youth of today can enjoy.
(In my day, we had books made of paper, and the closest thing to interactivity was Barney. Now my 10 year old niece has her own phone, her own laptop, and several MP3 players)


FlashMoto's 10 top Flash Websites  [April 12, 2010]
http://www.flashmoto.com/blog/flash-news/the-most-fascinating-flash-websites-youve-ever-seen/
Similar to this blog entry, FlashMoto added posted a blog entry of the 10 most fascinating Flash websites they have come across. Instead of reposting them all here, check it out on their blog.



[Work in progress. Leave a comment if you find anything else that deserves a mention]

This is an Open Post, which means that the list will keep getting added to over time. Subscribe to the feed for this page to be notified of any updates.