Archive

Archive for the ‘ActionScript 3.0’ Category

Using swfObject with Mootools

August 4th, 2009 11 comments

I'm sure most of us use swfObject, which in my opinion is the best option when it comes to embedding flash.

Lately I've been having a lot of fun with mootools and needed a way to embed flash dynamically. Basically I wanted my flash file to be embedded after a mootools click event was triggered.

So without further ado..

  1. window.addEvent('domready', function() {
  2.  
  3. //get the div I want to embed my flash into.
  4. var flashcontainer = $('flashcontainer');
  5.  
  6. //set all the flash properties
  7. var file = 'file.swf';
  8. var moviename = 'nameMyFlash';
  9. var width = '640';
  10. var height = '424';
  11. var version = '9';
  12. var bgcolor = '#000000';
  13.  
  14. //create the function that will fuse swfObject with mootools
  15. var embedFlash = function(){
  16. var so = new SWFObject(file, moviename, width, height, version, bgcolor);
  17. so.addParam("quality", "high");
  18. so.addParam("align", "middle");
  19. so.addParam("play", "true");
  20. so.addParam("loop", "true");
  21. so.addParam("scale", "exactfit");
  22. so.addParam("allowFullScreen", "true");
  23. so.addVariable("variable1", "variable 1 value goes here");
  24. so.addVariable("variable2", "variable 1 value goes here");
  25. so.write(flashcontainer);
  26. }
  27.  
  28. //get button by id
  29. var myButton = $('mybutton');
  30.  
  31. // create click event to fire my function called "embedFlash()"
  32. myButton.addEvent('click', embedFlash);
  33.  
  34. });

And that's it.. Hope it helps....

You can download the latest tools used above from the links below:
MooTools - download release 1.2.3 or SWFObject 2.2

Your slots payouts will be out of proportion from the progressive slots when you hit the slots bonus using the slots secrets of CasinoBonus.org!

Building a Preloader in ActionScript 3

March 1st, 2009 3 comments

We are going to explore how to build a preloader in as3.  Before building the preloader you will need to understand how to load external images/data with ActionScript 3.

If you read the loading external images post you will know that the image was loaded into the contentLoaderInfo property of the Loader object. This is what the code looks like.

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

To monitor the loading progress of this externally loaded image we need to use the LoaderInfo object which is a package of information about the load that is passed to the event listener of contentLoaderInfo. The properties of the LoaderInfo class along with the event object will provide all the information needed to build our preloader.

The available properties of the LoaderInfo class are:

  • bytesLoaded
  • bytesTotal
  • content
  • frameRate
  • height
  • width
  • loader

The available event types of the LoaderInfo class are:

  • COMPLETE
  • INIT
  • PROGRESS
  • UNLOAD

From the event types above we need to use the PROGRESS event type like the following.

  1. imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
  2. preloaderHandler);

Then to display the bytes being loaded we need to use the bytesLoaded and bytesTotal properties, and trace them when the function preloaderHandler is triggered. If you divide the 2 and multiply by 100 you will get the percentage loaded.

  1. function preloaderhandler(e:ProgressEvent):void{
  2. trace('bytesLoaded:  ' + e.bytesLoaded);
  3. trace('bytesTotal:  ' + e.bytesTotal);
  4. trace('percentage loaded:  ' +
  5. Math.round((e.bytesLoaded/e.bytesTotal)*100) + "%");
  6. }

The complete source code looks like this.

  1. var imgLoader:Loader = new Loader();
  2. imgLoader.contentLoaderInfo.addEventListner(Event.COMPLETE,
  3. loaderCompleteHandler);
  4. imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
  5. preloaderHandler);
  6.  
  7. function loaderCompleteHandler(e:Event):void{
  8. trace('Image has loaded.');
  9. }
  10.  
  11. function preloaderhandler(e:ProgressEvent):void{
  12. trace('bytesLoaded:  ' + e.bytesLoaded);
  13. trace('bytesTotal:  ' + e.bytesTotal);
  14. trace('percentage loaded:  ' +
  15. Math.round((e.bytesLoaded/e.bytesTotal)*100) + "%");
  16. }
  17.  
  18. imgLoader.load(new URLRequest('image.jpg'));

Enjoy. I'll write a post soon on how to integrate this preloader script with a simple animation.

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..

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.



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.

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,

SEO Powered by Platinum SEO from Techblissonline