© Photographer 2009
se-nse.net
In this tutorial I will discuss several Adobe Flash Lite 2.x funtions. Flash lite 2.x action script is based on Flash 8 action script 2.0, with several limitations applied.
The subjects I will discuss in this tutorial are:
- Date arrays
- Time
- Date and time formatting
- Analog clocks
- Animations interacting with time and date
- Loading text from a txt file on the memory
- Loading images from files on the memory
- Catching ID3 tags
- Images interacting with music (Flash lite 2.0 only!)
Questions and answers:
Q: Is my phone Flash Lite 2.x compatible?
A: This is a chart of compatibility:
Flash lite 2.0: K630, K660, K850, W890,
W910, Z750, Z770
Flash lite 2.1: C510, C702, C902, C905,
G705, T700, W595, W705, W715,
W760, Z780
All functions explained in this tutorial are compatible with both 2.0 and 2.1 phones, except the trackID!
Q: What do I need for creating swf wallpapers?
A: Adobe Flash 8 pro or later, this is a payed application but you can download a 30 days trial version to see if you really want to buy this application.
Some notes:
1. In this tutorial I will from now on write flash instead of Adobe Flash Lite 2.x, for readability.
2. This tutorial is property of Photographer, and was written for se-nse.net.
Date arrays
An array means that you define several words or numbers in a row, separated with a comma and a space. The array function looks like this:
new Array();
Flash and days of the week
Inside the brickets () you can define your variables, in my case this will be the days of the week (flash is oldflashioned and still thinks the first day of the week is SUNDAY).
So now we have this:
new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
Creating converting to output strings
To let flash know we’re busy with creating a date output, we have to set a new variable in the very beginning of our actionscript, like this:
CODE
var today_date:Date = new Date();
You can set “today_date” to anything you want, it doesn’t matter.
Var means the following word on the line is the variable, :Date means that it’s a date.
So now we have this:
CODE
var today_date:Date = new Date();
new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
Interaction of arrays with the date
The array has to interact with the date, and is variable as well, so we convert it to the same layout as the first var, like this:
CODE
var today_date:Date = new Date();
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
Again you can set dayOfWeek_array to anything, from now on we want to speak to the date array with the instance name dayOfWeek_array.
The output of the getDay command will be in numbers, 0, 1, 2, 3 till 6. Because our final output should be a string, we have to let the numbers and array interact, we can do that with this script:
CODE
var day_str:String = dayOfWeek_array[today_date.getDay()];
Basically this new script binds the array and number together and sets the output to the date the array assigns to the numbers.
The var is called day_str, from now on we can talk to the date with day_str.
CODE
var today_date:Date = new Date();
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];[code]
[b]Textbox[/b]
Now we create a textbox on any layer, and give it an instance name and. My text box will be called “dateTb” without quotes. To let the output of our script appear in the text box, we have to write the following script:
[code]dateTb.text = day_str
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];[code]
[b]Textbox[/b]
Now we create a textbox on any layer, and give it an instance name and. My text box will be called “dateTb” without quotes. To let the output of our script appear in the text box, we have to write the following script:
[code]dateTb.text = day_str
This defines that the textbox will be filled with text, and the text comes from the day_str variable!
Finished script:
CODE
var today_date:Date = new Date();
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
dateTb.text = day_str
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
dateTb.text = day_str
Updating the date
To make sure that the date updates, we have to create a new keyframe on the 2nd frame on the actionscript layer, in there write gotoAndPlay(1);
Time
Time is a lot easier to accieve, we can still use the fscommand2(“getTimeHours”), fscommand2(“getTimeMinutes”) and fscommand2(“getTimeSeconds”) to define time, or of course the entire time in one line, fscommand2("GetLocaleTime").
I find the seconds a pretty useless addition for on wallpapers, so I want to format my time like this 21:16
To do this, we write:
CODE
h = fscommand2(“GetTimeHours”);
m = fscommand2(“GetTimeMinutes”);
time_tb.text = h+”:”+m
m = fscommand2(“GetTimeMinutes”);
time_tb.text = h+”:”+m
Explanation
The “:” part of the scripts adds the : mark in between time and minutes. Now all we have to do is create a text box, in my case called time_tb, and give it the instance name time_tb.
But hey… now when the minutes count is less than 10, it shows 21:9 instead of 21:09! We can fix this with the following script:
CODE
if (m < 10) {
m = "0"+m
}
m = "0"+m
}
Finished script:
CODE
h = fscommand2(“GetTimeHours”);
m = fscommand2(“GetTimeMinutes”);
if (m < 10) {
mf = "0"+m
}
time_tb.text = h+”:”+mf
m = fscommand2(“GetTimeMinutes”);
if (m < 10) {
mf = "0"+m
}
time_tb.text = h+”:”+mf
Voila
Date and time formatting
Expressing dateThere are a lot of ways to express the date,
21/05/2009
Sunday 17 May
Sunday, May 17
17-05-2009
We can format the date with arrays and some additional script. I will explain the example that shows us Sunday 17 May.
We already have the Date script:
CODE
var today_date:Date = new Date();
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
dateTb.text = day_str
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
dateTb.text = day_str
Which information will we use?
All we want to add is the number of the date and the month. The number of the day is very easy, we just write today_date.getDate(); for that later when we compile the string.
For the month we have to create a new array, in exactly the same format as we did for the day of the week.
CODE
var month_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
and then define a string where it is being put in, according to the number that the var month_str:String = month_array[today_date.getMonth()]; command gives us.
So now we have this:
CODE
var today_date:Date = new Date();
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
var month_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var month_str:String = month_array[today_date.getMonth()];
[code]
[b]Converting to one string[/b]
To set up one string that combines all of the input, we put a new variable inside the actionscript:
[code]
var date_str:String = (day_str+" "+today_date.getDate()+" "+month_str);
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
var month_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var month_str:String = month_array[today_date.getMonth()];
[code]
[b]Converting to one string[/b]
To set up one string that combines all of the input, we put a new variable inside the actionscript:
[code]
var date_str:String = (day_str+" "+today_date.getDate()+" "+month_str);
Now the entire date is put into date_str, the order of the 3 strings inside the () can be arranged by yourself.
Don’t forget to change the last line for the text box!
Finished script:
CODE
var today_date:Date = new Date();
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
var month_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var month_str:String = month_array[today_date.getMonth()];
var date_str:String = (day_str+" "+today_date.getDate()+" "+month_str);
dateTb.text = date_str
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day_str:String = dayOfWeek_array[today_date.getDay()];
var month_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var month_str:String = month_array[today_date.getMonth()];
var date_str:String = (day_str+" "+today_date.getDate()+" "+month_str);
dateTb.text = date_str
Analog clocks
This is where actionscript is becoming pretty complicated. Too complicated to explain as precisely as I did with the date and time.
Therefore I added a fla for the analog clock to the attachments, copy it into your own fla and don´t forget to copy the the code dot! You can move the code dot outside of the visible part of your swf, it only contains code, no function. The white hands will listen to the code in the dot and rotate like a clock.

You can modify the hands by double clicking on them and editing the image there. You can also use the eraser tool and import your own image. I recommend using vector shapes (like in my fla) because regular png images turn out jagged and ugly when using them as rotating object
Animations interacting with time and date
To add some funky elements to my wallpapers, as you can see in the example.
Example:

At 23:00 the moon shows up and the bird falls asleep. This looks funny and is not too hard to make!
OMG! What do we have to do for this!?
First of all you import your images to the stage with CTRL+R, preferably on a new layer. Place the images where you want, and convert them to a movieclip (F8). Now give it a name, I will call the movieclip with the awake duck and without moon awake and the movieclip with sleeping bird and moon asleep. Put the instance names of those movieclips to “awake” and “asleep” as well!
This is the script we will use:
CODE
h = fscommand2("GetTimeHours");
if (h<8){
asleep._visible = true;
awake._visible = false;
}
else if (h<22){
asleep._visible = false;
awake._visible = true;
}
else if (h>21){
awake._visible = false;
}
if (h<8){
asleep._visible = true;
awake._visible = false;
}
else if (h<22){
asleep._visible = false;
awake._visible = true;
}
else if (h>21){
awake._visible = false;
}
Changing times
Now you can mess with the numbers and see what comes out. In this setting above, the moon and sleeping duck show when the hours is more then 21 (which means 22:00 till 23:59) AND the moon shows up from hours is 0:00 till 07:59 . The awake bird shows from 08:00 till 21:59.
Don’t forget to make the time update and put gotoAndPlay(1); on the 2nd frame of the layer where the previous actionscript is on.
Retrieving ID3 Tags (Added By Jockep
Using Flash lite and ID3 can be really fun, This script will help you get the music playing.
First as Joost said in the post below we will use
CODE
onEnterFrame = function ()
{
};
{
};
Updating
To get updates, then we add:
CODE
onEnterFrame = function ()
{
loadVariables("MP://data", _root);
};
{
loadVariables("MP://data", _root);
};
Finalisation
Wich loads MediaPlayer data into root, if you create a movieclip named mp to put text in change to _root.mp. Now we will add 3 strings (Title, Album & Artist). but first create 3 textboxes give them variable (Title, Album & Artist) and then add the following three lines:
CODE
onEnterFrame = function ()
{
loadVariables("MP://data", _root);
[b]Title.text = _root.TITLE;
Album.text = _root.ALBUM;
Artist.text = _root.ARTIST;[/b]
};
{
loadVariables("MP://data", _root);
[b]Title.text = _root.TITLE;
Album.text = _root.ALBUM;
Artist.text = _root.ARTIST;[/b]
};
Finished!
Now when music is playing the three textboxes will change to ID3 tags
Give the three text boxes the instance names Title, Album and Artist.
Changelog:
17-05-2009: Initial release 1.0
17-05-2009: Formatting changes
17-05-2009: ID3 tags added by Jockep (cheers!)
18-05-2009: Formatting changed
08-06-2009: Added Petike215's guide for rotating image [Removed by complaints]


