30 August 2010

Windows-like select tool in Flash

This little select object tool can be used in games or apps. It mimics windows select tool (even colors are the same). In this example selected items have decreased alpha properties, but that action can be easily modified to suit any need.



*_*

28 August 2010

Interactive Flash Banner Game Example

Online advertising world has seen clear evolution path from text links via static and annoying dynamic banner to interactive banners and beyond. Nobody is immune to banners, advertiser have 'faith' in them, some users hate them, some find them useful. Whatever you feel about banners they are here to stay in one form or another.

With Flash, banners have introduced fun in advertising equation. But there are two kinds of Flash banners, playable and not playable ones. Not playable banners use only Flash animation power to attract visitors and in most cases users do feel deluded about the experience.

With original, not-generic playable banner you can do much more. Good advice is to give user an option (after playing the game) to click or not to click. After experiencing some new and interactive stuff, user is usually open and exited to new content and if landing page offers 'next level' of experience (or game) even better!

Here is one simple example of interactive Flash banner game. Click on letters to form a word.



Have you clicked on continue?

If you need interactive Flash banner game, contact me, I'm open for freelance work.

*_*

23 August 2010

AS3 Elevator System Simulation

I continue to rewrite older code to AS3. In April last year I posted small chunk of AS2 code needed for Elevator system simulation. This time AS3 version is much better and you can test it by yourself. Click on gray square buttons to call the elevator. While elevator is moving click on more buttons and check calling queue info.



When elevator reaches destination (callingQueue[0] element) it stops for a while; waits for people to come in :) then deletes that floor call and goes to next call. Just like in real life, at least like elevator in my building works.

Here is the code (CC license):

/*
* Elevator Simulation
* @author: http://flanture.blogspot.com
* @date: August 2010
* @license: Creative Commons Attribution-NonCommercial-ShareAlike 3.0
* ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
*/

/**
* Imports
*/

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

/**
* Variables
*/

var _numberOfFloors:uint = 6;
var _callingQueue:Array = new Array();
var _btnsArray:Array = new Array();
var _buildingGroundX:uint = 75;
var _buildingGroundY:uint = 350;
var _floorHeight:uint = 50;
var _currFloor:uint = 1;
var _waitSemaphore:Boolean = false;
var _waitCounter:int = 40;

/**
* Functions
*/

function startSimulation():void
{
currentFloorTF.text = _currFloor;
drawBuilding();
}

function drawBuilding():void
{
// add building and calling buttons
for(var i:uint = 0; i < _numberOfFloors; i++)
{
var floor:floorMC = new floorMC();
floor.x = _buildingGroundX;
floor.y = _buildingGroundY-(_floorHeight*i);
addChild(floor);

var bellBtn:bell = new bell();

// to which floor button is added
bellBtn.fn = i+1;
bellBtn.x = _buildingGroundX + 200;
bellBtn.y = _buildingGroundY-(_floorHeight*i)-10;
addChild(bellBtn);

bellBtn.addEventListener(Event.ENTER_FRAME, bellOnFrame);
function bellOnFrame(evt:Event):void
{
evt.target.stop();
}
bellBtn.addEventListener(MouseEvent.MOUSE_UP, bellOnUp);
function bellOnUp(evt:MouseEvent):void
{
if(evt.target.currentFrame == 1) {

// if elevator is working check if it can stop by
if (_callingQueue.length > 0)
{
var test:Boolean = isBetween(evt.target.fn, _currFloor,

_callingQueue[0]);

// if elevator can stop, add this floor to queue
if (test)
{
_callingQueue.splice(0, 0, evt.target.fn);
evt.target.gotoAndStop(2);
queueTF.text = _callingQueue;
} else {

var queueCounter:int = 0;
while (queueCounter < _callingQueue.length-1)
{
if (isBetween(evt.target.fn, _callingQueue

[queueCounter], _callingQueue[queueCounter+1]))
{
_callingQueue.splice

(queueCounter+1, 0, evt.target.fn);
queueCounter =

_callingQueue.length;
evt.target.gotoAndStop(2);
queueTF.text = _callingQueue;

} else {
queueCounter += 1;
}
}
if (queueCounter < _callingQueue.length)
{
_callingQueue.push(evt.target.fn);
evt.target.gotoAndStop(2);
queueTF.text = _callingQueue;
}
}
} else {

// if queue is empty add to queue if it's not same floor

if (!(evt.target.fn == _currFloor))
{
evt.target.gotoAndStop(2);

// update queue
_callingQueue.push(evt.target.fn);
queueTF.text = _callingQueue;
}
}
}
}
_btnsArray.push(bellBtn);
}

// add elevator
var elevator:elevatorMC = new elevatorMC;
elevator.x = _buildingGroundX + 50;
elevator.y = _buildingGroundY;
addChild(elevator);

elevator.addEventListener(Event.ENTER_FRAME, elevatorOnFrame);
function elevatorOnFrame(evt:Event):void
{
// if queue is not empty elevator should move
if (_callingQueue.length > 0)
{
// check if elevator needs to wait for a while
if((_waitSemaphore)&&(_waitCounter > 0))
{
_waitCounter -= 1;
if(_waitCounter == 0)
{
_waitSemaphore = false;
_waitCounter = 40;
}
} else {

// find current elevator floor
_currFloor = 1+Math.floor((_buildingGroundY-evt.target.y)/_floorHeight);

// elevator goes up
if (_callingQueue[0] > _currFloor)
{
evt.target.y -= 2;
}

// elevator goes down
if (_callingQueue[0] < _currFloor)
{
evt.target.y += 2;
}

// if elevator reached destination stop it and change variables
if (_callingQueue[0] == _currFloor)
{
if(evt.target.y < _buildingGroundY-(_currFloor-1)*_floorHeight)
{
evt.target.y += 2;
} else {
evt.target.y = _buildingGroundY-(_currFloor-1)

*_floorHeight;
var temp:uint = _callingQueue.splice(0, 1);
_btnsArray[_currFloor-1].gotoAndStop(1);
queueTF.text = _callingQueue;
_waitSemaphore = true;
}
}
currentFloorTF.text = _currFloor;
}
}
}
}

function isBetween(caller:int, currentPosition:int, destination:int):Boolean
{
if ( ( (caller < destination)&&(caller > currentPosition) )||
( (caller < currentPosition)&&(caller > destination) ) ) {
return true;
} else {
return false;
}
}

startSimulation();



Source file and additional help available via email request. I hope you find this useful.

*_*

21 August 2010

Convergence of Flash Portals and Social Gaming Slides Presentation

View more presentations from danctheduck.


*_*

18 August 2010

AS3 Random Star Field Animation

This simple function creates star field animation. You need MovieClip in your library with 'star' class linkage. If stars are not your thing, feel free to try it with any other image you make.



code ::


import flash.events.Event;
import flash.events.MouseEvent;

function starField():void {

var i:uint = 0;

while (i < 30) {
var a:star = new star();
a.x = Math.random()*400;
a.y = Math.random()*260;
var size:Number = Math.random()*40+20;
a.width = a.height = size;
a.addEventListener(Event.ADDED_TO_STAGE, getSpeed);
function getSpeed(evt:Event):void
{
evt.target.speed = Math.random()*20-10;
}

a.addEventListener(Event.ENTER_FRAME, onFrame);
function onFrame(evt:Event):void
{
evt.target.rotation += evt.target.speed;
}
addChild(a);
i++;
}
}

starField();

addEventListener(MouseEvent.MOUSE_UP, onup);
function onup(evt:MouseEvent):void
{
while(this.numChildren > 0) {
this.removeChildAt(0);
}
starField();
}


*_*

16 August 2010

How to split ActionScript Array in two or more

Until today my ActionScript Search Array functions have been downloaded 2386 times, according to Box.net counter. Despite of this number I do think every piece of code can and should be improved. That's way I'm adding new function:

splitTo(Array, int):Array

This function splits given Array to int parts. Resulting Array is two-dimensional. How it works?

Let's say you have Array of Numbers



Array a has 10 elements and you want to split this Array into 3 new Arrays. Resulting Array will return new Array as image shows.



As you can see remaining elements (in this case element 11) will be attached to last the Array. If you don't want to attach any residual elements just delete the only while loop in the code.

Here is the function:


// function splitTo splits array 'ar1' to 'parts' number of arrays

public static function splitTo(a1:Array, parts:uint):Array
{
if (parts > 1) {

var aCount:Number = a1.length / parts;
var limit:int = int(aCount);
var res:Array = new Array();

// if aCount <= 1
if (aCount <= 1)
{

// put every element in new array
for (var i:uint = 0; i<a1.length; i++)
{

// make new array and resulting array
var newarray:Array = new Array();
newarray.push(a1[i]);
res.push(newarray);
}
} else {
for (var k:uint = 0; k<parts; k++)
{
var newarray2:Array = new Array();

if (a1.length > 0)
{

// if a1 is not empty
for (var j:uint = 0; j<limit; j++)
{
newarray2.push(a1.splice(0, 1));
}
res.push(newarray2);
}
}

// put rest of the elements inside last array
while (a1.length > 0)
{
res[res.length-1].push(a1.splice(0, 1));
}
}

// return resulting Array of Array[s]
return res;
} else {
return a1;
}
}


More similar functions coming soon.
Stay updated by subscribing to blog RSS feed, or follow me on Twitter.
Thanks for sharing.

*_*

11 August 2010

Flash Comics Album version 2.0

First steps with Flash Comics Album were taken back in May 2007. Right now, I'm moving all my previously done stuff towards AS3 version and if it is possible improvements will be included also. If you wanna read more, here are all previous posts about Comic Album.

1) Comic Album Flash application
2) project reactivated
3) Good Ideas and Clumsy Efforts

Comic Album v2.0 is intended for comic/strip artists who want to present their work on the web. Application reads external assets and they include configuration XML file and images. Main feature of Comic Album is it allows you to present comic in two modes, with and without text bubbles. This is why every comic scene comes with two images. One image is scene itself and can be jpg, gif, png and second image is transparent png which presents only text.

User can turn text on/off, enjoy whole thing or only look at images. Example file use fixed size 400x300 pixels images, but on request this can be altered.


How to use Comics Album 2.0

First, you need to download example files to your computer. Replace images inside assets folder with your own images. Then open comic.xml file with any text editor. Change 'scene' and 'txt' attributes of page tags to correspond to your files names. Upload swf and assets folder to your website and embed into desired page.


If you need different size album, some extra features or you have suggestions how to improve this version, feel free to comment or send me e-mail. This version doesn't include error checking code, so you have to be careful to have proper xml file and images. Also, idea is to have small images, few Kb per image, so album doesn't come with preloaders.

*_*

09 August 2010

Flash Tutorial : How to create vertigo animation

There are many situations where interesting Flash animations can be applied, in games, flash widgets, as website effect etc. Some animations require slow frame-by-frame making process and some can be created quickly using free community shared tools.

Spiral tool can be found on author's website. After you download it and install it, you can take a look how this tool is created by opening your Flash Configuration folder. On Windows this folder should be located at C:\Documents and Settings\Administrator\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Tools. Among others you will find files: Spiral.xml, Spiral.png and Spiral.jsfl. Simply open Spiral.jsfl with your favorite text editor to see Spiral tool source code.

You can use newly installed Spiral tool directly from Tools panel (see image below).

Flash Spiral Tool
When you are satisfied with spiral you created convert it to movie clip and add simple rotation code to it:

import flash.events.Event;

addEventListener(Event.ENTER_FRAME, rotate);
function rotate(evt:Event):void
{
rotation += 5;
}

Click on image to see live demo.



That's just a starting point. You can go further and make all kinds of complex vertigo animations. Simple adjustments would be to change drawing line size, style and color. Combine few different spiral lines with different rotation speeds to get even more complex vertigo.

*_*

07 August 2010

Indie Games Development - Solo vs Team

In the latest July 2010 issue number 107 of [games] develop magazine, Sophie Houlden speaks about her way into indie game development. Article titled "You can do it" starts with: "Sophie Houlden hasn’t spent a penny on tools to make her indie games – she just rolled up her sleeves and got on with it". Inspiring story.

However, I don't think that's the right way to do it. Few of us went there and never returned. Making it on your own can have just a few positive consequences, ego tripping is one. Financial gain? Hardly. Chances for you to make good money as one-man-team developer are so small, you'll be better off playing lottery.

But main loss is learning. Fact is - you will learn much more in a team about tools, code practices and everything else than by doing it by yourself. I don't even want to mention importance of being around other people during those long hours ... What can you learn by taking solo project except for how to take more solo projects?

I don't have anything against indie games development, quite opposite, but my advice is always work in a team. Why? Well, if project doesn't succeed, at least you had your fun - and you do have fun while making games, right?

*_*

02 August 2010

Good Ideas and Clumsy Efforts

Summer vacation is over. This one was longer than usual which translated to single post in July, lowest number of posts per month in 3+ years of blogging. However, good side is, it allowed me to clearly observe entire blog experience and pinpoint new goals and directions.

One thing I found is some older projects need to be rewritten. There were some great ideas and clumsy efforts to make things work. Few of those will get back to life in weeks and months ahead.

I'll start with Comics Album, previously written in AS2, some 3 years ago. Here are two posts about it:

1) Comics Album Flash App
2) project reactivated

This time it's all about AS3 code. Here is screen preview of Comics Album version 2.0 (work in progress).

comics album flash application preview


*_*

 

template by blogger templates