Search Tutorials
select the PM and AM using the shift key. press Ctrl+G to make them a group. double click on the new group, and you will be taken to a new editing screen for the AM and PM, which will now be separated. Select PM and press F8. name the symbol PM and set behavior to movie clip. do the same with the AM text, naming it AM. right click on AM, and select actions from the context menu. Copy in the following code: onClipEvent (load) {
time = new Date();
ampm = time.getHours();
}
onClipEvent (enterFrame) {
if (ampm>=12) {
setProperty(this, _visible, false);
}
}
CODE EXPLAINED: In the next part, when the frame is entered, we create a loop, or conditional statement. All this says is if ampm (the current hour of the day) is greater than or equal to 12, the AM movie clip is invisible, so all we see is PM. The first part is easy to understand, we use 12 because if on a 24hr clock, the hour is greater than or equal to 12, it is PM, therefore, we do not need the AM clip. The next part under the code is what happens if the if statement is true. setProperty is just telling flash that we want to change a certain property of a certain movieclip. the parameters within the brackets, (&) are as follows: this is the target path of the clip we want to alter. since we are applying the script directly to the clip, we can just write this. the next part is telling flash the property we want to change. in this case, it is the visibility of our clip. we use _visible to tell flash the property we want to change. the final part is the value we want to change the property to. Visibility can have one of two values, true or false. these are known as boolean values. they can also be represented as a 0 or 1. We want to make the clip invisible, so we say its visibility is false.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||
|