Archive for May, 2008

Scales in AS3

Thursday, May 29th, 2008

In actionscript 3 the scales for alpha, x scale and y scale have changed. In actionscript 2 they were a percentage rage between 0 and 100. In actionscript 3 this has changed to a scale between 0 and 1. So if you are converting from AS2 just divide your scale by 100.

Also the names of these have changed. In AS2 they were

  1. _xscale
  2. _yscale
  3. _alpha

In AS3 this has changed to

  1. scaleX
  2. scaleY
  3. alpha

Adobe CS4 beta release

Tuesday, May 27th, 2008

Adobe has released beta versions of Dreamweaver, Fireworks and Soundbooth CS4 at the Adobe Labs website. They have introduced a new layout for their products. I think they are trying to make the interface standard across all their products which will make switching between them much easier. The Beta versions include some great new features such as AIR prototyping right within Fireworks as well as new CSS layouts.

They have also introduced better code hinting for AJAX and javascript in Dreamweaver. There is also a thing called Photoshop Smart Objects where you can drap and drop Photoshop files directly into Dreamweaver. Adobe has updated the CSS support to include the best practices for the web. With the CSS property inspector it makes it easy for all the non coders out there to enter valid CSS. There is also SVN support to manage your files.

I haven't checked out Soundbooth. But to check it out as well as the others head on over to the Adobe Labs website and download the trial versions. They are really worth a look.

Flash 10 – Astro

Sunday, May 25th, 2008

On the 15th of this month (May) Adobe released their beta version of the new Flash player 10. This new player has native 3d support which looks as though it will be able to handle a lot of common things that people do with other 3d flash api's such as Papervision.

Flash 10 also has the ability to read and write files directly to your hard drive. This saves the need to upload information to a server and then download again.

Another thing adobe has added in flash 10 is the ability to type arrays called vectors. This means that you can make an array only have 1 specific type of content in it, such as a string or a number.

If you would like to know how you can test out Flash player 10 for yourself, have a look at Lee Brimelow's tutorial on how to install it.

Load an image with Actionscript 3

Friday, May 23rd, 2008

To load an image into flash with actionscript 3 the first thing you need to do is set up 2 variables. The first will be the loader which is what will actually load in the image. The second is the URL request which will tell flash where the image to be loaded is.

  1. var url:URLRequest = new URLRequest("myimage.jpg");
  2. var loader:Loader = new Loader();

Now we will call flash to load the image into the loader variable.

  1. loader.load(url);

However if we just have this, flash wont know what to do with it. So what we have to do is setup some event listeners which will call a function to tell flash what to do when it loads the file.

We will create one event listener to check what is happening while the image is loading.

  1. loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);

At first you may be thinking "why do I need contentLoaderInfo in there? Why can't I just add an event listener straight onto the loader?" The reason for this is basically that the loader just holds the image whereas the contentLoaderInfo hold all the information about the file. So if you don't use contentLoaderInfo then you can't get any information about the file.

Create another event listener to check if the file has finished loading;

  1. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

Now these 2 event listeners are calling some functions one called loadProgress and the other called loadComplete. So lets create those functions.

  1. function loadProgress(event:ProgressEvent):void
  2. {
  3. }
  5. function loadComplete(event:Event):void
  6. {
  7. }

In the loadProgress function you will notice that it is looking for a progress event. What this means is that while the image is downloading flash keeps checking this function to check the progress of the image download. This is called in the event listener that we created earlier.

In the loadProgress function we want to see the percentage of the file being downloaded. for this example we will just use the trace function.

  1. function loadProgress(event:ProgressEvent):void
  2. {
  3. var percentLoaded:Number = Math.round((event.bytesLoaded/event.bytesTotal) * 100);
  4. trace("Loading: "+percentLoaded+"%");
  5. }

What is happening here is we are getting the bytesLoaded from the image and dividing that by the bytesTotal of the image. This will get a number between 0 and 1. We then multiply that by 100 to get the percentage of the download. We also want to round this off so it won't display a number with a long decimal at the end like 13.2352274564. We then trace this out and when the image is downloading we will see how much of it has been downloaded.

Once the image has been downloaded we then need to tell Flash what to do with that image. What we will do in this instance is add it to the stage. So go into the loadComplete function and add this

  1. function loadComplete(event:Event):void
  2. {
  3. trace("Complete");
  4. addChild(loader);
  5. }

This tells flash that once the image has been downloaded add the loader to the stage. This will now display the image.

Your code should now look like this.

  1. var url:URLRequest = new URLRequest("myimage.jpg");
  2. var loader:Loader = new Loader();
  3. loader.load(url);
  5. loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
  6. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
  8. function loadProgress(event:ProgressEvent):void
  9. {
  10. var percentLoaded:Number = Math.round((event.bytesLoaded/event.bytesTotal) * 100);
  11. trace("Loading: "+percentLoaded+"%");
  12. }
  14. function loadComplete(event:Event):void
  15. {
  16. trace("Complete");
  17. addChild(loader);
  18. }

If you are using this inside a class then you would also need to import:

  1. import*;
  2. import;
  3. import flash.display.Loader;

New Blog

Friday, May 23rd, 2008

I have decided to start a new blog. In this blog I will be posting tutorials, news, and anything that I have learned about flash, actionscript, html, css, javascript and anything else that I think could be useful. It is intended to be a resource for not only you, but also for myself to go back to see what I have learned.

I hope that it will prove useful to you.