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:
var myDate:Date = newDate();
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:
var myDate:Date = newDate();
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..
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.
var total:Number = 30; //total number of bubblevar sw:Number = Stage.width; //stage widthvar sh:Number = Stage.height; //stage heightfor(var i=0;i<total;i++){var bubble:MovieClip = this.attachMovie("mcBubble",
"mcBubble"+i,this.getNextHighestDepth());
// set the initial random speed
bubble.yspeed = random(500) + 3;
// set the initial random position
bubble._y = sh;
bubble._x = random(sw);
// set the initial wobble factor (the X movement)
bubble.xspeed = random(3);
if(random(2)eq1){
bubble.xspeed = -bubble.xspeed;
}
bubble.onEnterFrame = function(){// the bubble movementthis._y = this._y - this.yspeed;
// check if the bubble is out of the top of the screenif(this._y <= -15){// then reset to the bottomthis._y = sh;
this._x = random(sw);
this.yspeed = random(5) + 3;
// now to randomise the scale of the bubble so// we get a few wee ones too
scale = 2 + (random(8));
this._width = scale;
this._height = scale;
// set the initial wobble factor (the X movement)this.xspeed = random(3);
if(random(2)eq1){this.xspeed = -this.xspeed;
}}// change the X value of the bubblethis._x = this._x + this.xspeed;
// the bounce code for either the left or right of the// margin for the bubbleif(this._x > 100 or this._x < 50){this.xspeed = -this.xspeed;
}}}
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!
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:
//an array of button instance namesvar buttonInstanceNames:Array = newArray("button1","button2",
"button3", "button4");
//function that sets the buttons enabled statefunction enableButtons(e){for(var i=0;i<buttons.length;i++){>
this[buttonInstanceNames[i]].enabled = e;
}}//call function and assign enabled state
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.
//The instance name of my blocker movieclip is "mcBlocker"//show or hide the button blockerfunction enableButtons(e){
mcBlocker._visible = e;
mcBlocker.onRollOver = doNothing;
}//do nothing when the blocker activefunction doNothing(){}//just enable or disable the blocker
enableButtons(false);