31 October 2009

Level Timer code explained

It seems like my code in How To Create Flash Game Level Timer post is not as straightforward as I thought, because it was rejected as Tutorial on one of the directories, so I decided to give detailed explanation of it.

var count:Number = 0;
// this is a counter variable

var maxCount:Number = 75;
// maxCounter is duration of level in seconds

var intervalID:Number;
// Identification variable for repeating interval function

var timerStarted = false;
// variable which tells us if timer has started or not

var temp:Number;
// variable for shortening code writing

// next, we format and display seconds left
if(maxCount < 60) {
// if we have less then 60 seconds,

timeleft.text = "0 : "+maxCount;
// we display '0 minutes' in our Text Field 'timeleft' and concatenate maxCount seconds

} else {
// but if we have more than 60 seconds left

if((maxCount%60)<10) {
// and if we have to display seconds as one cipher number

timeleft.text = Math.floor((maxCount/60))+" : 0"+(maxCount%60);
// we display zero

} else {
// otherways,

timeleft.text = Math.floor((maxCount/60))+" : "+(maxCount%60);
// if we have two cipher number for seconds, we don't display zero

}
}

startlevel.onRelease = function() {
// when click is released on startlevel button

if(!(timerStarted)) {
// if timerStarted variable is false (we don't want to duplicate interval)

intervalID = setInterval(_root, "hronos", 1000);
// we set interval function 'hronos' to repeat once every second to act as counter

timerStarted = true;
// we declare that timer has started

this._alpha = 0;
// and we make invisible startLevel button.
// We chould also remove it from stage!

}
}

function hronos():Void {
// function hronos repeats every second

if(count < maxCount) {
// if counter is still less than maxCounter

count++;
// we increase counter by 1

temp = maxCount - count;
// temp variable holds seconds left until level end

// next piece of code is for formating and displaying purposes,
// same as above except instead maxCount we have temp variable.
if(temp < 60) {
if(temp < 10) {
timeleft.text = "0 : 0"+temp;
} else {
timeleft.text = "0 : "+temp;
}
} else {
if((temp%60)<10) {
timeleft.text = Math.floor((temp/60))+" : 0"+(temp%60);
} else {
timeleft.text = Math.floor((temp/60))+" : "+(temp%60);
}
}
} else {
// if counter is greater than maxCounter

clearInterval(intervalID);
// we clear our interval

timerStarted = false;
// we declare that timer is out of business

count = 0;
// we set counter to 0 so we can use it again

startlevel._alpha = 100;
// and we make startLevel button visible again

}
}

I hope this explanation is clear enough. If you have any questions, don't hesitate to ask.

*_*

23 October 2009

Protecting The Brand

Few days ago Envato (Australia based startup) announced they have to change one of theirs marketplace's name and URL. They run several websites like ThemeForest, GraphicRiver, AudioJungle, VideoHive, FlashDen and more. Latest one FlashDen is our suspect. What happend is that Adobe Systems Incorporated law firm representative contacted them asking to change their name, as TechCrunch reported. Envato did changed it into ActiveDen to avoid further legal problems.

There are few very strange things here. First, FlashDen is already registered trademark in Australia from August 2008 and therefor Envato should be protected by law, but they decided to change their name and url right away. Second, many websites use similar names like flashcomponents.net, flashloaded.com (to name a few) and a LOT more, but it seems like only Envato is contacted about this issue or at least I'm not aware of others. Idea that this is only first step and that all those websites will be contacted in near future is unlikely because it will be biggest technology suicide of all times!

Community responded and they responded hard. Just check 500+ comments on Envato forum. Some are furious, but many of readers are simply confused. Matthew Craig wrote:

"This is absolutely ridiculous… A community developed around a product to promote that product yet the product thinks it’s harmful to the product having a community promoting it? Makes no sense to me. It’s like mall-cops on a power trip thinking they are real cops."

and Mark wrote:

"I’m pretty annoyed that companies like Apple, and Adobe are so vicious with it’s legal protection of their trademarks. Sad really."

So, how about Adobe? What are their thoughts? Let's see what they say about proper use of the flash trademark:

"Trademarks help protect corporate and product identity, and the Flash® trademark is one of Adobe's most valuable trademarks. By following our guidelines, you can help Adobe protect the Flash brand name. The Flash trademark must never be used as a common verb, as a noun, or as a generic term for animation or video or to describe the output format. The Flash trademark should always be capitalized and should never be used in possessive form or as a slang term. It should be used as an adjective to describe the product and should never be used in abbreviated form."

It seems that Adobe is just trying to protect their brand. There is nothing wrong with it and I think there is no room for talks about 'evil Adobe' (at least not for now). Just imagine what would The Ronald do in same situation. They will sue everyone, right away, until extermination! And after dust comes down, they will sue some more! If you put The Ronald and other big aggressive brands together in same room, Adobe would be like nerd teenager trying to get attention, nothing more. For now.

*_*

15 October 2009

How To Create Flash Game Level Timer

In this post I'll explain how to create Flash game level timer mechanism. Code I'm using here is very simple, it's not something you should use in your final product. Code is ActionScript2.0. Sample FLA is Flash 8 file and it demonstrates how timer works.




Graphic elements are simple. We have startBtn movie clip in Library with 'startlevel' instance on Stage. Another graphic element is dynamic single-line text field with instance name 'timeleft'. When you start sample file situation our text field shows time left in minutes and seconds. Start level button is visible and waiting for click. When that happens button get zero alpha (should be moved from Stage) and countdown timer start to work.



Some formating is done, so numbers are displayed like they should, instead of 1:1 we have 1:01 etc. Timer resets when reach 0:00 and start level button is visible again, waiting for action. In real time situation, you can have different level durations for different levels. That means you should replace maxCount variable with Array of different intervals each represents duration of levels in seconds.

Here is the code:


var count:Number = 0;
var maxCount:Number = 75;
var intervalID:Number;
var timerStarted = false;
var temp:Number;

if(maxCount < 60) {
timeleft.text = "0 : "+maxCount;
} else {
if((maxCount%60)<10) {
timeleft.text = Math.floor((maxCount/60))+" : 0"+(maxCount%60);
} else {
timeleft.text = Math.floor((maxCount/60))+" : "+(maxCount%60);
}
}

startlevel.onRelease = function() {
if(!(timerStarted)) {
intervalID = setInterval(_root, "hronos", 1000);
timerStarted = true;
this._alpha = 0;
}
}

function hronos():Void {
if(count < maxCount) {
count++;
temp = maxCount - count;
if(temp < 60) {
if(temp < 10) {
timeleft.text = "0 : 0"+temp;
} else {
timeleft.text = "0 : "+temp;
}
} else {
if((temp%60)<10) {
timeleft.text = Math.floor((temp/60))+" : 0"+(temp%60);
} else {
timeleft.text = Math.floor((temp/60))+" : "+(temp%60);
}
}
} else {
clearInterval(intervalID);
timerStarted = false;
count = 0;
startlevel._alpha = 100;
}
}



*_*

07 October 2009

Free Microblog Flash Widget v1.0

Microblog is Flash widget that represents tiny version of blog or website. It can be embedded on blog sidebar or as standalone application. Microblog is XML based widget. Entire content is stored and controlled from external data.xml file. You don't need any previous Flash knowledge to change the content. Simply, by changing text inside data.xml widget is updated.

Main text field is scrollable. Use up and down triangles on right to navigate current page. If page has long text then navigation is there to help. You can also expand main text filed by clicking on rectangle placed between navigation triangles. Clicking again on same rectangle will shrink text field to it's original size.

When user click on page title, Microblog takes him to original blog page or custom web location. Links are also stored inside XML file.

On the left side of the widget you can load preview images in few formats: JPEG, PNG, GIF and even SWF. Preview files should be 60 x 60 pixels. Microblog free Flash widget is resizable. Original size is 250 x 125 pixels.


Download archive file which includes: microblog.swf, data.xml, folder Images and help.pdf file with instructions on how to use and modify Microblog widget content. No Flash knowledge is required.

Microblog movie clip contains link to this blog.

You are free to use Microblog Flash Widget in any way you desire as long you don't sell it, claim it's your work, modify or use source without author permission.




For custom solution and support please contact.


*_*

06 October 2009

Myth hacked: Flash on iPhone

Watch and weep!





*_*

05 October 2009

Flash Catalyst beta 2

There was a lot of mixed reactions on beta 1 release of Flash Catalyst, from those who were praising it like Flash On The Beach visitors to others who were completely confused about where to include it concerning development workflow.

Adobe has just released beta 2 of Flash Catalyst with lots of new stuff and improvement. Ryan Stewart gives you an introduction via his screencast.




*_*

 

template by blogger templates