I'm setting up an analog clock with adjustable hour and minute hands that can be manipulated in a separate frame. I'm used NumericStepper components so that I can set the hour and minute of the clock. The goal is for the hour and minute hands to be set to the values listed in the NumericStepper components.
I already got the clock to display the current computer time:
time = new Date();
seconds = time.getSeconds();
minutes = time.getMinutes();
hours = time.getHours();
hours = hours + (minutes/60);
seconds = seconds*6;
minutes = minutes*6;
hours = hours*30;
sec._rotation = seconds;
min._rotation = minutes;
hour._rotation = hours;
And here's the form: Picture of the form on screen
Update: I was finally able to make the form and output the value of the NumericStepper to some text boxes, so I think I'm in the right direction:
var palletteArray = new Array();
palleteArray = ["0x7FAAD4", "0xFFDF7F"];
function setTheme() {
_global.style.setStyle("themeColor", palleteArray[0]);
_global.style.setStyle("backgroundColor", palleteArray[1]);
_global.style.setStyle("fontSize", 11);
_global.style.setStyle("fontWeight", "bold");
_global.style.setStyle("color", palleteArray[0]);
}
setTheme();
var stepsListener = new Object();
stepsListener.change = function() {
populateTextBoxes();
};
stepperHour.addEventListener("change", stepsListener);
stepperMin.addEventListener("change", stepsListener);
function populateTextBoxes() {
TextBox1.text = stepperHour.value;
TextBox2.text = stepperMin.value;
}
So. The problem can be decomposed into these sub-problems:
Let's start with the №4. In AS2 there is a _global object, it is visible from any context and can be used to share data between separate parts of code. It goes as following:
Well, in order to have it initialized at any place, but not overwrite it, you need to check if it is already in place first. Put this to the both places you are working with:
Good. Now, how to have your analog clock always in sync with it? The onEnterFrame handler fires every frame and is intended to keep your display updated by code. I'll just copy and modify what you have there:
Then, the last part. You need to update the shared data upon user interaction. I assume that code of yours is correct, so I am going only to add the update the shared data bit into your existing function:
It was 15 years since I used AS2 and I am kind of not fluent (well, who is?), but the general idea should be correct and I believe you'll figure it out from here on.