Archive

Archive for the ‘ActionScript 2.0’ Category

Scaling a dynamic background image in proportion using flash

August 13th, 2009 11 comments

Recently I was playing around with scaling background images and had issues with how the scaling behaved and image quality.  When scaling an image in proportion you want to make sure that the image container is centered to the movie clip it belongs to.

My example below is the scaling code within a stage listener which will re size the background image according to the stage width & height.

  1. Stage.align = "TL";
  2. Stage.scaleMode = "noScale";
  3.  
  4. //Get Background Image Container Movie Clip Name (instance)
  5. var backgroundImage:movieClip = "MovieClip Instance Name"
  6.  
  7. // Create an object for the stage listener
  8. stageListener:Object = new Object();
  9.  
  10. // Create a function for the event you want to listen for
  11. stageListener.onResize = function() {
  12.  
  13. //Get the  stage width & height
  14. var sw:Number = Stage.width;
  15. var sh:Number = Stage.height;
  16.  
  17. //Check to see if image width or height needs adjusting
  18. if ((sh / sw) > (backgroundImage._height / backgroundImage._width)) {
  19.  
  20. //get image width and adjust height to fit
  21. scale = backgroundImage._width / backgroundImage._height;
  22. backgroundImage._height = sh;
  23. backgroundImage._width = sh * scale;
  24. } else {
  25.  
  26. //get image height and adjust width to fit
  27. scale =backgroundImage._height / backgroundImage._width;
  28. backgroundImage_width = sw;
  29. backgroundImage._height = sw * scale;
  30. }
  31.  
  32. //Center the background Image
  33. backgroundImage._x = (sw - backgroundImage._width) / 2;
  34. backgroundImage._y = (sh - backgroundImage._height) / 2;
  35.  
  36. };
  37. // Add listener for the Stage object
  38. Stage.addListener(stageListener);

Now the the simple line of code that makes this work so well is the quality preservation part. Just add this after your dynamic image has loaded.

  1. backgroundImage.forceSmoothing = true;

An actionscript 3 version would not be much different to this and should be fairly easy to workout. If your struggling just let me know.

Buy great image scaling software after you learn the roulette slang and online roulette history you need to beat roulette at CasinoBonus.org!

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!

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,

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.

Disable all buttons in flash or disable 1 button in flash

February 3rd, 2009 3 comments

Recently I needed to disable all buttons on my flash site. I trawled the net looking for answers but all I got was what I already knew. Which is disabling each button 1 by 1 using an array like so:

  1.  
  2. //an array of button instance names
  3. var buttonInstanceNames:Array = new Array("button1","button2",
  4. "button3", "button4");
  5.  
  6. //function that sets the buttons enabled state
  7. function enableButtons(e){
  8. for(var i=0;i<buttons.length;i++){>
  9. this[buttonInstanceNames[i]].enabled = e;
  10. }
  11. }
  12.  
  13. //call function and assign enabled state
  14. enableButtons(false);

This is all good if you have a few buttons but what if your site is complex like the 1 I was working on and you wanted to disable all button interactivity without knowing buttons instance names.

Solution
Basically place a movie clip button over the entire movie or just over the area where your buttons are with _alpha set to 0. Remember to set the movie clip with a onRollOver, or onRelease event. Just set the blocking movie clip's _visible state to false when you want interactivity back.

Here is the code I used to get this working.

  1.  
  2. //The instance name of my blocker movieclip is "mcBlocker"
  3. //show or hide the button blocker
  4. function enableButtons(e){
  5. mcBlocker._visible = e;
  6.   mcBlocker.onRollOver = doNothing;
  7.  }
  8.  
  9. //do nothing when the blocker active
  10. function doNothing(){}
  11.  
  12. //just enable or disable the blocker
  13. enableButtons(false);
  14.  

Hope this helps..

Making the first letter in a textfield Uppercase

March 19th, 2008 No comments
  1. var myKeyListener = new Object();
  2. myKeyListener.onKeyUp = function() {
  3. var myString = myTextfield.text;
  4. var firstLetter = (myString.charAt(0)).toUpperCase();
  5. var remainderLetters = (myString.substring(1)).toLowerCase();
  6. var myNewString = firstLetter+remainderLetters;
  7. myTextfield.text = myNewString;
  8. };
  9. Key.addListener(myKeyListener);

Using special characters in flash

February 17th, 2008 1 comment

Use encoding to ensure that variables are passed correctly.The example below illustrates how special characters can be retained using URL encoding:

A text file containing the following variable value:

Cost=+85
Will read into Flash as ‘Cost= 85′, dropping the + character.

However, using URL encoding to replace the + character the original text:

Cost=%2b85
Will result in Flash displaying ‘Cost= +85′ correctly.

Use this URL Encoding table for special characters:

backspace %08
tab %09
linefeed %0A
return %0D
space %20
! %21
%22
# %23
$ %24
% %25
& %26
%27
* %2A
+ %2B
, %2C
- %2D
. %2E
/ %2F
< %3C
= %3D
> %3E
? %3F
@ %40
[ %5B
\ %5C
] %5D
^ %5E
_ %5F
` %60
{ %7B
   
| %7C
} %7D
~ %7E
¢ %A2
£ %A3
¥ %A5
| %A6
§ %A7
« %AB
¬ %AC
¯ %AD
º %B0
± %B1
ª %B2
, %B4
µ %B5
» %BB
¼ %BC
½ %BD
¿ %BF
À %C0
Á %C1
 %C2
à %C3
Ä %C4
Å %C5
Æ %C6
Ç %C7
È %C8
É %C9
   
Ê %CA
Ë %CB
Ì %CC
Í %CD
Î %CE
Ï %CF
Ð %D0
Ñ %D1
Ò %D2
Ó %D3
Ô %D4
Õ %D5
Ö %D6
Ø %D8
Ù %D9
Ú %DA
Û %DB
Ü %DC
Ý %DD
Þ %DE
ß %DF
à %E0
á %E1
â %E2
ã %E3
ä %E4
å %E5
æ %E6
ç %E7
è %E8
   
é %E9
ê %EA
ë %EB
ì %EC
í %ED
î %EE
ï %EF
ð %F0
ñ %F1
ò %F2
ó %F3
ô %F4
õ %F5
ö %F6
÷ %F7
ø %F8
ù %F9
ú %FA
û %FB
ü %FC
ý %FD
þ %FE
ÿ %FF
   

Additional information
The TAB character (URL encoded with %09) is not supported in Flash or HTML. In Flash and HTML, the TAB key is reserved for switching focus between form fields.

Textfield Listener

February 14th, 2008 No comments
  1. //construct the listener object
  2. myListenerObject = new Object();
  3.  
  4. myListenerObject.onChanged = function(txt) {
  5. //perform this when textfield value has changed
  6. execute();
  7. }
  8.  
  9. //call the TextField.addListener method to register the object
  10. Textfield.addListener(myListenerObject);
SEO Powered by Platinum SEO from Techblissonline