Archive

Archive for February, 2009

Building a simple clock application in as3

February 25th, 2009 3 comments

Yesterday I posted how the Date class worked in ActionScript 3.  Today I though I would build a simple clock application using the Date class.

Building the clock app involves using the Date class in a couple of ways. The Date class returns the current date and time of when the method is called and only once per object created. Basically the example I gave in my previous Date class post performed this once.

To have our clock continually roll through the time and date, a new Date object must be created and the methods of the Date class that return the date and time properties must be called at regular intervals to display the changing time. To create our clock application, we will use the Timer class.

The following code will create a TextField object to display the time and a Timer object that updates every 1/10th of a second in the updateTime() event handler for the Timer event of the Timer class.

When the updateTime() event handler is called on each TIMER event, a new Date object and a new variable for the time are created, concatenated, and set as the text property for myDisplay.

A new Date object needs to be created each time because the Date class stores only the time and date values for the time in which the object was created.

Alright.. Let's get into the code..

  1. var myDisplay:TextField = new TextField();
  2. var myTimer:Timer = new Timer(100);
  3.  
  4. myTimer.addEventListener(TimerEvent.TIMER, updateTime);
  5.  
  6. function updateTime(evt:TimerEvent):void{
  7.  
  8. var localDate:Date = new Date();
  9. var hour:int = localDate.getHours();
  10. var minute:String;
  11. var second:String;
  12.  
  13. /* Note that if the second and minute
  14. values are less than 10 we add a 0 to the
  15. single digit */
  16.  
  17. if(localDate.getMinutes()<10){
  18. minute = String(0)+localDate.getMinutes();
  19. }else{
  20. minute = String(localDate.getMinutes());
  21. }
  22.  
  23. if(localDate.getSeconds()<10){
  24. second = String(0)+localDate.getSeconds();
  25. }else{
  26. second = String(localDate.getSeconds());
  27. }
  28.  
  29. myDisplay.text = hour+':'+minute+':'+second;
  30.  
  31. }
  32.  
  33. myTimer.start();
  34. addChild(myDisplay);

Hope this helps ...  Peace...

The Date Class in AS3

February 24th, 2009 No comments

The Date class will allow you to check the current date and time on a user's computer. You'll find this class valuable when developing widgets like an event count down clock. To work with the Date class, you must instantiate a Date object:

  1. var myDate:Date = new Date();
  2. trace(myDate);

When the Date object has been built, you can call methods or get properties of the Date class to get date and time values:

  1. var myDate:Date = new Date();
  2. trace(myDate.getDate());

The getDate() method gets the current day of the month.

The getMonth() method gets the month of the year as a number value. Numeric references to the current month are not the normal month numbers we are used to working with.

For example, January is equal to 0 and December is equal to 11. For display reasons, always add 1 to the returned month number to get the true calendar month value.

Available methods for getting Time and Date properties of the Date class are:

  • getDate();
  • getDay();
  • getFullYear();
  • getHours();
  • getMilliseconds();
  • getMinutes();
  • getMonth();
  • getSeconds();

Note: For a full description of each method search "date class" via the Flash help menu.

Easy.. now get fancy with it and tell us what you created..

tar: Archive contains obsolescent base-64 headers

February 24th, 2009 9 comments

I was trying to install Ghostscript on my MediaTemple (mt) Linux server but I kept getting the following error:

  1. tar: This does not look like a tar archive
  2. tar: Skipping to next header
  3. tar: Archive contains obsolescent base-64 headers
  4. tar: Error exit delayed from previous errors

The quick fix around this is to type the following:

  1. gzip -d filename.tar.gz

and then

  1. tar -xf filename.tar

This should extract the file without errors.

Peace

Categories: Linux Tags:

Loading external images with ActionScript 3

February 22nd, 2009 16 comments

One technique of loading external images is using the Loader class. It's similar to the URLLoader class but the Loader class loads and displays loaded images and SWF content. The Loader class is a part of the DisplayObject class; it is capable of displaying content as well as loading it. The goal of this technique is to make the loading operation as fast and hassle free as the queuing process of Getminted and other websites of similar nature.

To load external images using the Loader class, you need to create an object of the Loader class.

  1. var imgLoader:Loader = new Loader();

To load an image into the Loader Object, the load method of the Loader class is used, along with a URLRequest.

  1. var imgLoader:Loader = new Loader();
  2. imgLoader.load(new URLRequest('image.jpg'));

The LoaderInfo class also has events and event types that dispatch information about the progress of the load through the Loader class.

The code below traces a loaded message after the loader object has completed loading the image.

  1. var imgLoader:Loader =  new Loader();
  2. imgLoader.contentLoaderInfo.addEventListner(Event.COMPLETE,loaderCompleteHandler);
  3.  
  4. function loaderCompleteHandler(e:Event):void{
  5.    trace('Image has loaded.');
  6. }
  7.  
  8. imgLoader.load(new URLRequest('image.jpg'));

At this point all you have done is loaded in the image to the Loader Object. For the loaded image to display you will need to add the Loader object to the display list.


  1. addChild(imgLoader);

The complete source code looks like this.

  1. var imgLoader:Loader =  new Loader();
  2. imgLoader.contentLoaderInfo.addEventListner(Event.COMPLETE,loaderCompleteHandler);
  3.  
  4. function loaderCompleteHandler(e:Event):void{
  5.    trace('Image has loaded.');
  6.    addChild(imgLoader);
  7. }
  8.  
  9. imgLoader.load(new URLRequest('image.jpg'));

hope this helps...

Do you need a working .fla of this including a preloader? Buy me a coffee and I'll send it to you via email. Remember to reference your email address.



Making flash sites search engine friendly

February 22nd, 2009 No comments

Until now Flash sites have not ranked well with search engines because they could not index them. For web developers or SEO specialists, this meant extra work.

In a press release on Tuesday Adobe announced that it was working with both Yahoo! and Google to enable indexing of Flash files. The project will enable searches on Flash content to return text and links, which can then be indexed. Better still, current Flash content will be immediately searchable by search engines, without alteration.

David Wadhwani, general manager and vice president of the Platform Business Unit at Adobe said:

Until now it has been extremely challenging to search the millions of RIAs (rich Internet applications) and dynamic content on the Web, so we are leading the charge in improving search of content that runs in Adobe Flash Player. We are initially working with Google and Yahoo! to significantly improve search of this rich content on the Web, and we intend to broaden the availability of this capability to benefit all content publishers, developers and end users.

Of course, all this assumes that the search engine has the Flash tech working: Google is rolling out Flash search today, but Yahoo! said it was going to enable the feature in a later release of its search engine and that it was “working with Adobe to determine the best possible implementation.” And no, Microsoft wasn’t mentioned at all.

However, Adobe’s statement does indicate Adobe will work with other search engines as well. With Microsoft having its Flash competitor, Silverlight, however, I’m wondering if that will slow things down between the two companies.

Downgrade to Flash 9

February 22nd, 2009 No comments
I recently needed to downgrade from Flash 10 to Fflash 9 because some of my scripts stopped working as soon as I made the update. You can download old versions of the player @ http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14266&sliceId=1.

Remove dotted lines from links

February 18th, 2009 3 comments

The dotted lines that appear around links is an accessibility feature for people who can't use a mouse and are forced to use a keyboard to navigate. It works well when you use the tab key but it still shows when you are using a mouse.

If your working on government sites that need w3c compliance then I would not recommend removing this feature, otherwise use the CSS code below.

  1. a {
  2. /* Mozilla */
  3. outline:none;
  4.  
  5. /* IE */
  6. -moz-outline-style: none;
  7. }

You could get fancy and use the dotted line to your advantage. With CSS you can change the dotted line type to solid or change its colour to suit the design.

Good Luck!

Categories: CSS Tags: ,

Adobe Announce Flash 10 For Android

February 16th, 2009 No comments

Adobe have announced that Flash 10 will be making it's way to the Android platform by the end of the year. In an announced at the Mobile World Congress event in Barcelona, Adobe revealed that they plan to release their first full-fledged Flash multimedia player for smartphones by the end of 2009.

"We've made a lot of progress, but there is still a lot of engineering work to be done," said Anup Murarka, director of partner development and technology strategy for Adobe's platform business unit.

Adobe are expected to demonstrate the Flash Player 10 for smartphones beta during the Mobile World Congress event.

Categories: News Tags: , , ,

The name of this class, [class name], conflicts with the name of another class that was loaded, [class name]

February 7th, 2009 No comments

I've never come across this error before and I'm sure its not common, unless you constantly send files somewhere on the planet with a different timezone.

I recently created a snow as2 script for BigStockFlash.com but it got rejected because of a class conflict error. I tested the files again and found nothing was wrong with the files.

I re-packaged the files without modifying the code and sent it through. This time it worked. The only difference was the time I sent it.

Solution
Change your system clock to be the same as the time in the country your sending the files to or wait 24hrs before sending them again,

How to create bubbles in flash (ActionScript 2.0)

February 4th, 2009 7 comments

Here is a simple peice of ActionScript that can also be used to create snow or rain. I've seen a few particle engines on the net that I easily could have used but I wanted something simpler.

So this is what I came up with.

  1. var total:Number = 30; //total number of bubble
  2. var sw:Number = Stage.width; //stage width
  3. var sh:Number = Stage.height; //stage height
  4.  
  5. for (var i=0;i<total;i++){
  6.  
  7. var bubble:MovieClip = this.attachMovie("mcBubble",
  8. "mcBubble"+i,this.getNextHighestDepth());
  9.  
  10. // set the initial random speed
  11. bubble.yspeed = random(500) + 3;
  12.  
  13. // set the initial random position
  14. bubble._y = sh;
  15. bubble._x = random(sw);
  16.  
  17. // set the initial wobble factor (the X movement)
  18. bubble.xspeed = random(3);
  19.  
  20. if (random(2) eq 1) {
  21. bubble.xspeed = -bubble.xspeed;
  22. }
  23.  
  24. bubble.onEnterFrame = function(){
  25.  
  26. // the bubble movement
  27. this._y = this._y - this.yspeed;
  28.  
  29. // check if the bubble is out of the top of the screen
  30. if (this._y <= -15) {
  31.  
  32. // then reset to the bottom
  33. this._y = sh;
  34. this._x = random(sw);
  35. this.yspeed = random(5) + 3;
  36.  
  37. // now to randomise the scale of the bubble so
  38. // we get a few wee ones too
  39.  
  40. scale = 2 + (random(8));
  41. this._width = scale;
  42. this._height = scale;
  43.  
  44. // set the initial wobble factor (the X movement)
  45. this.xspeed = random(3);
  46.  
  47. if (random(2) eq 1) {
  48. this.xspeed = -this.xspeed;
  49. }
  50. }
  51.  
  52. // change the X value of the bubble
  53. this._x = this._x + this.xspeed;
  54.  
  55. // the bounce code for either the left or right of the
  56. // margin for the bubble
  57. if (this._x > 100 or this._x < 50) {
  58. this.xspeed = -this.xspeed;
  59. }
  60.  
  61. }
  62.  
  63. }

Easy.. now this is what it looks like.

You could make it more realistic by tweaking the speed, wobble values and add blurs or better graphics but what I needed  it for, this is perfect.

Download the Source Code - Use it any way you want, just let others know how you used it by leaving a comment. Peace!

Enjoy.

SEO Powered by Platinum SEO from Techblissonline