hi guys
thanks for reading and here is the problem im facing
i have a clock, and a background
the background contains an animated ocean (100 frames)
there are four sky themes which change on the appropriate hour to night-time, morning, sunset, sunrise (could just use alpha to show another here although maybe processor intensive)
ok so the ocean could animate on its own and only the sky would need to change, that would be the easy part
but when it gets to night-time the ocean needs to jump to the night-time version of itself
so if the user presses the hour button, and the ocean is on daytime at frame 80, how would i say play night version at frame 81
so that the ocean doesnt skip animation??
thanks in advance
fonzio
hi peter
sorry for the late reply, ive been trying to get this to work the logic is certainly there
so i have an MC called sea_mc
inside this are all versions of the sea, with frame labels denoting daysea, nightsea and so on
i need to say something like
if (hours == 9){
sea_mc.gotoAndPlay("nightsea".currentFrame + 1);
}
but it gives me an error
wondering any ideas?
thanks
fonzio
If you have labels as you indicate then chances are you only need to specify them alone...
if (hours == 9){
sea_mc.gotoAndPlay("nightsea");
}
What you were otherwise trying to do with that label will most likely produce an error. Anytime you get errors you should include the complete error message in your posting.
hi thx ned
that seems to work
only problem now is, i need it to continue animating which is why i need to say
currentFrame +1.
at the moment its running daysea on a loop to frame 100 and then it says gotoandPlay(1);
now if i add
if (hours == 9){
sea_mc.gotoAndPlay("nightsea");
}
the nightsea animation will begin at the start of its looped animation
which is why i need to say get currentFrame of daysea, play nightsea and add +1, so that the animation wont seem to jump, any way of doing this??
thanks
Fonzio
ok sea_mc, contains 100 image frames of animation (waves),
each 100 frames contains a label so we have daytime_sea and nightime_sea
at the end of each 100 frames i tell it to start at the beginning of the animation, and so we have a looped ocean of 100 frames for daytime and 100 frames for nighttime
so i need to tell flash
while playing daytime sea
if hours == 9
get daytime sea (currentframe)
play nighttime sea at the next frame
so that the animation will jump to the appropriate frame and not appear to skip
i hope that is more clear
thanks
fonzio
No, it is not clear. You start off saying sea_mc contains 100 frames. Then you talk as if there are a couple of sets of 100 frames, meaning there might be 200 frames. So if you can clear that explanation up, that will be helpful... if you include a screenshot of your timeline that might even be more helpful.
wow daytime_sea and sunset_sea are labels, not separate movieclips?
then your code should look like this (if timeline you showed us belongs to one names "sea_mc"
if (hours == 9){
sea_mc.gotoAndPlay(sea_mc.currentFrame + 101);
}
If you jumped 100 frames forward, you'd be in the exact frame of night sea, so you want to add (100 + 1) frames.
There are ways to get the frame number on which the label is, if you want to use labels and not exact numbers (in case you make your animation shorter or longer..)
import flash.display.FrameLabel;
import flash.display.MovieClip;
if(hours == 9) {
switchToNight();
}
else if(hours == 1) { // whatever time you want
switchToDay();
}
function switchToNight():void {
var nightSeaFrame:int = getLabelFrameNumber(sea_mc, "sunset_sea");
sea_mc.gotoAndPlay(nightSeaFrame + sea_mc.currentFrame + 1);
}
function switchToDay():void {
var nightSeaFrame:int = getLabelFrameNumber(sea_mc, "sunset_sea");
sea_mc.gotoAndPlay(sea_mc.currentFrame - nightSeaFrame + 1);
}
/* UTILS */
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
thanks peter that did the job perfectly except for one thing,
everything is fine, i get to 1800 and the sea turns to nighttime mode (excellent)
however if i go back to 1700 the sea remains in nighttime mode
how can i tell it to revert back to daytime_sea??
i thought i had fixed the problem by using the following
however now when i reach 1700 the daytime_sea skips again
if(hours == 18) {
switchToNight();
}
else if(hours == 17) { // whatever time you want
switchToDay();
}
else if(hours == 6) { // whatever time you want
switchToDay();
}
else if(hours == 5) { // whatever time you want
switchToNight();
}
hope you can help
thanks in advance
fonzio
this is original code before i tried the above fix
//////////////////////////////////////////
if(hours == 18) {
switchToNight();
}
else if(hours == 6) {
switchToDay();
}
function switchToNight():void {
var nightSeaFrame:int = getLabelFrameNumber(sea_mc, "nighttime_sea");
sea_mc.gotoAndPlay(nightSeaFrame + sea_mc.currentFrame + 1);
}nighttime_sea
function switchToDay():void {
var nightSeaFrame:int = getLabelFrameNumber(sea_mc, "nighttime_sea");
sea_mc.gotoAndPlay(sea_mc.currentFrame - nightSeaFrame + 1);
}
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
You need to define intervals, let's say:
0 - 7: night
7 - 18: day
18 - 24: night
then your code should look like:
if(hours < 7 || hours > 18) {
shitchToNight();
}
else {
switchToDay();
}
You should improve your methods so you don't jump to nightmode when already in night mode.
function switchToNight():void {
if(sea_mc.currentLabel == "sunset_sea") return;
var nightSeaFrame:int = getLabelFrameNumber(sea_mc, "sunset_sea");
sea_mc.gotoAndPlay(nightSeaFrame + sea_mc.currentFrame + 1);
}
function switchToDay():void {
if(sea_mc.currentLabel != "sunset_sea") return;
var nightSeaFrame:int = getLabelFrameNumber(sea_mc, "sunset_sea");
sea_mc.gotoAndPlay(sea_mc.currentFrame - nightSeaFrame + 1);
}
I didn't test it since I wrote it in notepad ![]()
Let me know if it works. I believe the code is quite self-explanatory and you should be able to modify the hours easily. Note that the labels in PHASES Array are names of your frame labels so you should modify them accordingly. Also the fact that each phase has the same ammount of frames stays unchanged.
i
mport flash.display.FrameLabel;
import flash.display.MovieClip;
const PHASES:Array = [
{
hour: 20,
label: "night"
},
{
hour: 19,
label: "sunset"
},
{
hour: 7,
label: "day"
},
{
hour: 6,
label: "sunrise"
},
{
hour: 0,
label: "night"
}
];
// you call this function whenewer you want to test hour and possibly change day time
function checkPhase(hour:Number):void {
for(var i:int = 0; i < PHASES.length; i++) {
if(PHASES[i].hour < hour) {
showPhase(PHASES[i].label);
return;
}
}
trace("Something went wrong, this line shouldn't execute.")
}
function showPhase(phase:String):void {
if(phase == sea_mc.currentLabel) return;
var currentPhaseStart:int = getLabelFrameNumber(sea_mc.currentLabel);
var frameOffset:int = sea_mc.currentFrame - currentPhaseStart;
var newPhaseStart:int = getLabelFrameNumber(phase);
sea_mc.gotoAndPlay(newPhaseStart + frameOffset);
}
/* UTILS */
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
wow totally into notepad?, damn i hope to have those kind of skills someday, the code is beyond me, everything works, no errors except the sea remains in daytime whatever the time
i have changed the numbers to the times i would like each to show and put in the correct labels
wondering could the problem be hour?, been checking by hours you see, although it comes up as a keyword if i try to change it here, i suppose i could change hours to hour throughout the code and see if that works, anyway let me know what you think and i will change if you say i should. Also is there a reason label "nighttime_sea" is listed twice?, there is no zero in my code as it becomes 24 and then moves to 1.
thanks in advance
great job btw
fonzio
const PHASES:Array = [
{
hour: 19,
label: "nighttime_sea"
},
{
hour: 17,
label: "sunset_sea"
},
{
hour: 8,
label: "daytime_sea"
},
{
hour: 6,
label: "dawn_sea"
},
{
hour: 2,
label: "nighttime_sea"
}
];
// you call this function whenewer you want to test hour and possibly change day time
function checkPhase(hour:Number):void {
for(var i:int = 0; i < PHASES.length; i++) {
if(PHASES[i].hour < hour) {
showPhase(PHASES[i].label);
return;
}
}
trace("Something went wrong, this line shouldn't execute.")
}
function showPhase(phase:String):void {
if(phase == sea_mc.currentLabel) return;
var currentPhaseStart:int = getLabelFrameNumber(sea_mc.currentLabel);
var frameOffset:int = sea_mc.currentFrame - currentPhaseStart;
var newPhaseStart:int = getLabelFrameNumber(phase);
sea_mc.gotoAndPlay(newPhaseStart + frameOffset);
}
/* UTILS */
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
wow totally into notepad?, damn i hope to have those kind of skills someday, the code is beyond me, everything works, no errors except the sea remains in daytime whatever the time
i have changed the numbers to the times i would like each to show and put in the correct labels
the numbers and labels are fine
wondering could the problem be hour?, been checking by hours you see, although it comes up as a keyword if i try to change it here, i suppose i could change hours to hour throughout the code and see if that works, anyway let me know what you think and i will change if you say i should.
the "hour" in my code is just input parameter in function. you have to call the function checkPhase and pass your "hours". Just add this line:
checkPhase(hours);
Also is there a reason label "nighttime_sea" is listed twice?, there is no zero in my code as it becomes 24 and then moves to 1.
Yes, as you can see the algorithm for finding the right day phase goes from the first element in array (highest hour) and goes to the last one (lowest hour). If you put 24 inside, it will finish right at the first item, because 24 > 20 and the phase will be night. If you pass 1, it will finish at the last item, because only 1 > 0. The reason night is mentioned twice is, that hours overflow at night (24) and begin from 0 again, so night is both at the highest and at the lowest hour.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-307()
at wholesite2_fla::gametwo_mc_65/hoursrules()
at wholesite2_fla::gametwo_mc_65/frame1()
at flash.display::MovieClip/gotoAndPlay()
at wholesite2_fla::games_mc_39/frame3()
at flash.display::MovieClip/gotoAndPlay()
at MethodInfo-64()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
hmm here is complete code im thinking that maybe some other code is conflicting:
stop();
import flash.display.FrameLabel;
import flash.display.MovieClip;
var mygame2timer:Timer;
var mygame2timer2:Timer;
var mycounter:Number=0;
var correct:Number=0;
var wrongtries:Number=0;
var tries:Number=0;
var hours:Number=12;
var minutes:Number=00;
ampm_txt.text=" PM";
mytime_txt.text=(hours < 10 ? "0" : "")+hours + ":" + (minutes < 10 ? "0" : "") + minutes + ampm_txt.text;
ampm_txt.visible=false;
randomtime();
//minutes_txt.text="00";
hoursrules();
//sea_mc.gotoAndPlay("daytime_sea");
btns_mc.btn_min_less.buttonMode=true;
btns_mc.btn_min_more.buttonMode=true;
btns_mc.btn_5_min_less.buttonMode=true;
btns_mc.btn_5_min_more.buttonMode=true;
btns_mc.btn_10_min_less.buttonMode=true;
btns_mc.btn_10_min_more.buttonMode=true;
btns_mc.btn_15_min_less.buttonMode=true;
btns_mc.btn_15_min_more.buttonMode=true;
btns_mc.btn_30_min_less.buttonMode=true;
btns_mc.btn_30_min_more.buttonMode=true;
btns_mc.btn_hr_less.buttonMode=true;
btns_mc.btn_hr_more.buttonMode=true;
btns_mc.btn_check_mc.buttonMode=true;
btns_mc.btn_min_less.mouseChildren=false;
btns_mc.btn_min_more.mouseChildren=false;
btns_mc.btn_5_min_less.mouseChildren=false;
btns_mc.btn_5_min_more.mouseChildren=false;
btns_mc.btn_10_min_less.mouseChildren=false;
btns_mc.btn_10_min_more.mouseChildren=false;
btns_mc.btn_15_min_less.mouseChildren=false;
btns_mc.btn_15_min_more.mouseChildren=false;
btns_mc.btn_30_min_less.mouseChildren=false;
btns_mc.btn_30_min_more.mouseChildren=false;
btns_mc.btn_hr_less.mouseChildren=false;
btns_mc.btn_hr_more.mouseChildren=false;
//button listeners
btns_mc.btn_min_less.addEventListener(MouseEvent.CLICK, minless);
btns_mc.btn_min_less.addEventListener(MouseEvent.MOUSE_OVER, minlessOver);
btns_mc.btn_min_less.addEventListener(MouseEvent.MOUSE_OUT, minlessOut);
btns_mc.btn_min_more.addEventListener(MouseEvent.CLICK, minmore);
btns_mc.btn_min_more.addEventListener(MouseEvent.MOUSE_OVER, minmoreOver);
btns_mc.btn_min_more.addEventListener(MouseEvent.MOUSE_OUT, minmoreOut);
btns_mc.btn_5_min_less.addEventListener(MouseEvent.CLICK, fiveminless);
btns_mc.btn_5_min_less.addEventListener(MouseEvent.MOUSE_OVER, fiveminlessOver);
btns_mc.btn_5_min_less.addEventListener(MouseEvent.MOUSE_OUT, fiveminlessOut);
btns_mc.btn_5_min_more.addEventListener(MouseEvent.MOUSE_OVER, fiveminmoreOver);
btns_mc.btn_5_min_more.addEventListener(MouseEvent.MOUSE_OUT, fiveminmoreOut);
btns_mc.btn_5_min_more.addEventListener(MouseEvent.CLICK, fiveminmore);
btns_mc.btn_10_min_less.addEventListener(MouseEvent.CLICK, tenminless);
btns_mc.btn_10_min_less.addEventListener(MouseEvent.MOUSE_OVER, tenminlessOver);
btns_mc.btn_10_min_less.addEventListener(MouseEvent.MOUSE_OUT, tenminlessOut);
btns_mc.btn_10_min_more.addEventListener(MouseEvent.CLICK, tenminmore);
btns_mc.btn_10_min_more.addEventListener(MouseEvent.MOUSE_OVER, tenminmoreOver);
btns_mc.btn_10_min_more.addEventListener(MouseEvent.MOUSE_OUT, tenminmoreOut);
btns_mc.btn_15_min_less.addEventListener(MouseEvent.CLICK, fifteenminless);
btns_mc.btn_15_min_less.addEventListener(MouseEvent.MOUSE_OVER, fifteenminlessOver);
btns_mc.btn_15_min_less.addEventListener(MouseEvent.MOUSE_OUT, fifteenminlessOut);
btns_mc.btn_15_min_more.addEventListener(MouseEvent.CLICK, fifteenminmore);
btns_mc.btn_15_min_more.addEventListener(MouseEvent.MOUSE_OVER, fifteenminmoreOver);
btns_mc.btn_15_min_more.addEventListener(MouseEvent.MOUSE_OUT, fifteenminmoreOut);
btns_mc.btn_30_min_less.addEventListener(MouseEvent.CLICK, thirtyminless);
btns_mc.btn_30_min_less.addEventListener(MouseEvent.MOUSE_OVER, thirtyminlessOver);
btns_mc.btn_30_min_less.addEventListener(MouseEvent.MOUSE_OUT, thirtyminlessOut);
btns_mc.btn_30_min_more.addEventListener(MouseEvent.CLICK, thirtyminmore);
btns_mc.btn_30_min_more.addEventListener(MouseEvent.MOUSE_OVER, thirtyminmoreOver);
btns_mc.btn_30_min_more.addEventListener(MouseEvent.MOUSE_OUT, thirtyminmoreOut);
btns_mc.btn_hr_less.addEventListener(MouseEvent.CLICK, hrless);
btns_mc.btn_hr_less.addEventListener(MouseEvent.MOUSE_OVER, hrlessOver);
btns_mc.btn_hr_less.addEventListener(MouseEvent.MOUSE_OUT, hrlessOut);
btns_mc.btn_hr_more.addEventListener(MouseEvent.CLICK, hrmore);
btns_mc.btn_hr_more.addEventListener(MouseEvent.MOUSE_OVER, hrmoreOver);
btns_mc.btn_hr_more.addEventListener(MouseEvent.MOUSE_OUT, hrmoreOut);
btns_mc.btn_check_mc.addEventListener(MouseEvent.CLICK, checker);
//button functions
function minlessOver(event:MouseEvent):void {
btns_mc.btn_min_less.gotoAndPlay("minover");
}
function minlessOut(event:MouseEvent):void {
btns_mc.btn_min_less.gotoAndStop("minout");
}
function minmoreOver(event:MouseEvent):void {
btns_mc.btn_min_more.gotoAndPlay("minover");
}
function minmoreOut(event:MouseEvent):void {
btns_mc.btn_min_more.gotoAndStop("minout");
}
function fiveminlessOver(event:MouseEvent):void {
btns_mc.btn_5_min_less.gotoAndPlay("minover");
}
function fiveminlessOut(event:MouseEvent):void {
btns_mc.btn_5_min_less.gotoAndStop("minout");
}
function fiveminmoreOver(event:MouseEvent):void {
btns_mc.btn_5_min_more.gotoAndPlay("minover");
}
function fiveminmoreOut(event:MouseEvent):void {
btns_mc.btn_5_min_more.gotoAndStop("minout");
}
function tenminlessOver(event:MouseEvent):void {
btns_mc.btn_10_min_less.gotoAndPlay("minover");
}
function tenminlessOut(event:MouseEvent):void {
btns_mc.btn_10_min_less.gotoAndStop("minout");
}
function tenminmoreOver(event:MouseEvent):void {
btns_mc.btn_10_min_more.gotoAndPlay("minover");
}
function tenminmoreOut(event:MouseEvent):void {
btns_mc.btn_10_min_more.gotoAndStop("minout");
}
function fifteenminlessOver(event:MouseEvent):void {
btns_mc.btn_15_min_less.gotoAndPlay("minover");
}
function fifteenminlessOut(event:MouseEvent):void {
btns_mc.btn_15_min_less.gotoAndStop("minout");
}
function fifteenminmoreOver(event:MouseEvent):void {
btns_mc.btn_15_min_more.gotoAndPlay("minover");
}
function fifteenminmoreOut(event:MouseEvent):void {
btns_mc.btn_15_min_more.gotoAndStop("minout");
}
function thirtyminlessOver(event:MouseEvent):void {
btns_mc.btn_30_min_less.gotoAndPlay("minover");
}
function thirtyminlessOut(event:MouseEvent):void {
btns_mc.btn_30_min_less.gotoAndStop("minout");
}
function thirtyminmoreOver(event:MouseEvent):void {
btns_mc.btn_30_min_more.gotoAndPlay("minover");
}
function thirtyminmoreOut(event:MouseEvent):void {
btns_mc.btn_30_min_more.gotoAndStop("minout");
}
function hrlessOver(event:MouseEvent):void {
btns_mc.btn_hr_less.gotoAndPlay("minover");
}
function hrlessOut(event:MouseEvent):void {
btns_mc.btn_hr_less.gotoAndStop("minout");
}
function hrmoreOver(event:MouseEvent):void {
btns_mc.btn_hr_more.gotoAndPlay("minover");
}
function hrmoreOut(event:MouseEvent):void {
btns_mc.btn_hr_more.gotoAndStop("minout");
}
//clicks
function minless(event:MouseEvent):void {
minuteHand_mc.rotation-=6;
if (minutes<1) {
minutes=minutes+59;
hourHand_mc.rotation-=30;
hours=hours-=1;
} else {
minutes=minutes-1;
}
if (hours<1) {
hours=hours+24;
}
hoursrules();
}
function minmore(event:MouseEvent):void {
minuteHand_mc.rotation+=6;
if (minutes>=59) {
minutes=minutes-59;
hourHand_mc.rotation+=30;
hours=hours+=1;
} else {
minutes=minutes+1;
}
if (hours==0) {
hours=hours+12;
}
if (hours>24) {
hours=hours-24;
}
hoursrules();
}
function fiveminless(event:MouseEvent):void {
minuteHand_mc.rotation-=30;
if (minutes<5) {
minutes=minutes+55;
hours=hours-=1;
hourHand_mc.rotation-=30;
} else {
minutes=minutes-5;
}
if (hours<1) {
hours=hours+24;
}
hoursrules();
}
function fiveminmore(event:MouseEvent):void {
minuteHand_mc.rotation+=30;
if (minutes>=55) {
hourHand_mc.rotation+=30;
hours=hours+=1;
minutes=minutes-55;
} else {
minutes=minutes+5;
}
if (hours==0) {
hours=hours+12;
}
if (hours>24) {
hours=hours-24;
}
hoursrules();
}
function tenminless(event:MouseEvent):void {
minuteHand_mc.rotation-=60;
if (minutes<10) {
minutes=minutes+50;
hours=hours-=1;
hourHand_mc.rotation-=30;
} else {
minutes=minutes-10;
}
if (hours<1) {
hours=hours+24;
}
hoursrules();
}
function tenminmore(event:MouseEvent):void {
minuteHand_mc.rotation+=60;
if (minutes>=50) {
hourHand_mc.rotation+=30;
hours=hours+=1;
minutes=minutes-50;
} else {
minutes=minutes+10;
}
if (hours==0) {
hours=hours+12;
}
if (hours>24) {
hours=hours-24;
}
hoursrules();
}
function fifteenminless(event:MouseEvent):void {
minuteHand_mc.rotation-=90;
if (minutes<15) {
minutes=minutes+45;
hours=hours-=1;
hourHand_mc.rotation-=30;
} else {
minutes=minutes-15;
}
if (hours<1) {
hours=hours+24;
}
hoursrules();
}
function fifteenminmore(event:MouseEvent):void {
minuteHand_mc.rotation+=90;
if (minutes>=45) {
hourHand_mc.rotation+=30;
hours=hours+=1;
minutes=minutes-45;
} else {
minutes=minutes+15;
}
if (hours==0) {
hours=hours+12;
}
if (hours>24) {
hours=hours-24;
}
hoursrules();
}
function thirtyminless(event:MouseEvent):void {
minuteHand_mc.rotation-=180;
if (minutes<30) {
hourHand_mc.rotation-=30;
hours=hours-=1;
minutes=minutes+30;
} else {
minutes=minutes-30;
}
if (hours<1) {
hours=hours+24;
}
hoursrules();
}
function thirtyminmore(event:MouseEvent):void {
minuteHand_mc.rotation+=180;
if (minutes>=30) {
hourHand_mc.rotation+=30;
hours=hours+=1;
minutes=minutes-30;
} else {
minutes=minutes+30;
}
if (hours==0) {
hours=hours+12;
}
if (hours>24) {
hours=hours-24;
}
hoursrules();
}
function hrless(event:MouseEvent):void {
hourHand_mc.rotation-=30;
hours--;
if (hours<1) {
hours=hours+24;
}
hoursrules();
}
function hrmore(event:MouseEvent):void {
hourHand_mc.rotation+=30;
hours++;
if (hours>24) {
hours=hours-24;
}
hoursrules();
}
function hoursrules():void {
checkPhase(hours);
if (hours<12) {
ampm_txt.text=" AM";
}
if (hours>12) {
ampm_txt.text=" PM";
}
if (hours==24) {
ampm_txt.text=" AM";
}
if (hours==12) {
ampm_txt.text=" PM";
}
const PHASES:Array = [
{
hour: 19,
label: "nighttime_sea"
},
{
hour: 17,
label: "sunset_sea"
},
{
hour: 8,
label: "daytime_sea"
},
{
hour: 6,
label: "dawn_sea"
},
{
hour: 24,
label: "nighttime_sea"
}
];
// you call this function whenewer you want to test hour and possibly change day time
function checkPhase(hour:Number):void {
for(var i:int = 0; i < PHASES.length; i++) {
if(PHASES[i].hour < hour) {
showPhase(PHASES[i].label);
return;
}
}
trace("Something went wrong, this line shouldn't execute.")
}
function showPhase(phase:String):void {
if(phase == sea_mc.currentLabel) return;
var currentPhaseStart:int = getLabelFrameNumber(sea_mc.currentLabel);
var frameOffset:int = sea_mc.currentFrame - currentPhaseStart;
var newPhaseStart:int = getLabelFrameNumber(phase);
sea_mc.gotoAndPlay(newPhaseStart + frameOffset);
}
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
mytime_txt.text=(hours < 10 ? "0" : "")+hours + ":" + (minutes < 10 ? "0" : "") + minutes+ (ampm_txt.text);
}
// create an Array with numbers 0:00 - 23:59 in minutes, then randomise it
//mytimes_txt.text = mytime_txt.text
function randomtime():void {
function generateRandomTimeList():Array {
var array:Array = new Array();
for (var i:uint = 0, end:uint = 60*24 - 1; i < end; i++) {
array.push(i);
}
return myarray(array);
}
// Array randomising algorithm
function myarray(a:Array):Array {
var b:Array=new Array(a.length);
b[0]=a[0];
for (var i:uint = 1, n:uint = a.length; i < n; i++) {
var j:uint=Math.round(Math.random()*i);
b[i]=b[j];
b[j]=a[i];
}
return b;
}
// convert number to time formatted string
function timeFormat(n:uint):String {
var hour:uint=Math.floor(n/60);
var minute:uint=n-hour*60;
return (hour == 0 ? 24 : hour < 10 ? "0" : "") +hour + ":" + (minute < 10 ? "0" : "") + minute+ (randomTimeList[i] < 60*12 ? " AM" : " PM");
}
// trace 10 random time
var randomTimeList:Array=generateRandomTimeList();
for (var i:uint = 0; i < 1; i++) {
myrandomtime_txt.text=(timeFormat(randomTimeList[i]));
}
}
//on btn
function checker(event:MouseEvent):void {
if (mytime_txt.text==myrandomtime_txt.text) {
MovieClip(parent.parent).e_mc.cap_talk_txt.text="Well Done!!";
clockreset();
// true or false
} else {
hours=12;
minutes=00;
ampm_txt.text=" PM";
mytime_txt.text=(hours < 10 ? "0" : "")+hours + ":" + (minutes < 10 ? "0" : "") + minutes+ ampm_txt.text;
hourHand_mc.rotation=0;
minuteHand_mc.rotation=0;
MovieClip(parent.parent).e_mc.cap_talk_txt.text="Wrong try again!";
MovieClip(parent.parent).scoreminus();
sea_mc.gotoAndPlay("daytime_sea");
randomtime();
wrongtries++;
tries++;
mycounter++;
}
function clockreset():void {
hours=12;
minutes=00;
ampm_txt.text=" PM";
mytime_txt.text=(hours < 10 ? "0" : "")+hours + ":" + (minutes < 10 ? "0" : "") + minutes + ampm_txt.text;
hourHand_mc.rotation=0;
minuteHand_mc.rotation=0;
randomtime();
MovieClip(parent.parent).scoreplus();
sea_mc.gotoAndPlay("daytime_sea");
correct++;
mycounter++;
}
if (tries==3) {
MovieClip(parent.parent).e_mc.cap_talk_txt.text="Click "+" "+"for instructions!";
MovieClip(parent.parent).e_mc.helpicon_mc.visible=true;
tries=tries-3;
} else {
MovieClip(parent.parent).e_mc.helpicon_mc.visible=false;
}
if (mycounter==5) {
removegame2listeners();
if (correct>wrongtries) {
MovieClip(parent.parent).e_mc.helpicon_mc.visible=false;
MovieClip(parent.parent).e_mc.cap_talk_txt.text="Well done, you got "+correct+" correct and "+wrongtries+" wrong this round, lets see how you do in the next game!!";
endgame();
}
if (correct<wrongtries) {
MovieClip(parent.parent).e_mc.helpicon_mc.visible=false;
MovieClip(parent.parent).e_mc.cap_talk_txt.text="Hmm not bad, you got "+correct+" correct and "+wrongtries+" wrong this round, lets see how you do in the next game!!";
endgame();
}
function endgame():void {
mygame2timer=new Timer(5000,1);
mygame2timer.addEventListener(TimerEvent.TIMER, mygame2timerdone);
mygame2timer.start();
function mygame2timerdone(e:TimerEvent):void {
MovieClip(parent.parent).e_mc.gotoAndPlay("explan_out");
mygame2timer.stop();
mygame2timer.removeEventListener(TimerEvent.TIMER, mygame2timerdone);
mygame2timer2=new Timer(5000,1);
mygame2timer2.addEventListener(TimerEvent.TIMER, mygame2timer2done);
mygame2timer2.start();
function mygame2timer2done(e:TimerEvent):void {
mygame2timer2.stop();
mygame2timer2.removeEventListener(TimerEvent.TIMER, mygame2timer2done);
MovieClip(parent).gotoAndPlay("intro");
}
}
}
}
}
function removegame2listeners():void {
btns_mc.btn_min_less.removeEventListener(MouseEvent.CLICK, minless);
btns_mc.btn_min_less.removeEventListener(MouseEvent.MOUSE_OVER, minlessOver);
btns_mc.btn_min_less.removeEventListener(MouseEvent.MOUSE_OUT, minlessOut);
btns_mc.btn_min_more.removeEventListener(MouseEvent.CLICK, minmore);
btns_mc.btn_min_more.removeEventListener(MouseEvent.MOUSE_OVER, minmoreOver);
btns_mc.btn_min_more.removeEventListener(MouseEvent.MOUSE_OUT, minmoreOut);
btns_mc.btn_5_min_less.removeEventListener(MouseEvent.CLICK, fiveminless);
btns_mc.btn_5_min_less.removeEventListener(MouseEvent.MOUSE_OVER, fiveminlessOver);
btns_mc.btn_5_min_less.removeEventListener(MouseEvent.MOUSE_OUT, fiveminlessOut);
btns_mc.btn_5_min_more.removeEventListener(MouseEvent.MOUSE_OVER, fiveminmoreOver);
btns_mc.btn_5_min_more.removeEventListener(MouseEvent.MOUSE_OUT, fiveminmoreOut);
btns_mc.btn_5_min_more.removeEventListener(MouseEvent.CLICK, fiveminmore);
btns_mc.btn_10_min_less.removeEventListener(MouseEvent.CLICK, tenminless);
btns_mc.btn_10_min_less.removeEventListener(MouseEvent.MOUSE_OVER, tenminlessOver);
btns_mc.btn_10_min_less.removeEventListener(MouseEvent.MOUSE_OUT, tenminlessOut);
btns_mc.btn_10_min_more.removeEventListener(MouseEvent.CLICK, tenminmore);
btns_mc.btn_10_min_more.removeEventListener(MouseEvent.MOUSE_OVER, tenminmoreOver);
btns_mc.btn_10_min_more.removeEventListener(MouseEvent.MOUSE_OUT, tenminmoreOut);
btns_mc.btn_15_min_less.removeEventListener(MouseEvent.CLICK, fifteenminless);
btns_mc.btn_15_min_less.removeEventListener(MouseEvent.MOUSE_OVER, fifteenminlessOver);
btns_mc.btn_15_min_less.removeEventListener(MouseEvent.MOUSE_OUT, fifteenminlessOut);
btns_mc.btn_15_min_more.removeEventListener(MouseEvent.CLICK, fifteenminmore);
btns_mc.btn_15_min_more.removeEventListener(MouseEvent.MOUSE_OVER, fifteenminmoreOver);
btns_mc.btn_15_min_more.removeEventListener(MouseEvent.MOUSE_OUT, fifteenminmoreOut);
btns_mc.btn_30_min_less.removeEventListener(MouseEvent.CLICK, thirtyminless);
btns_mc.btn_30_min_less.removeEventListener(MouseEvent.MOUSE_OVER, thirtyminlessOver);
btns_mc.btn_30_min_less.removeEventListener(MouseEvent.MOUSE_OUT, thirtyminlessOut);
btns_mc.btn_30_min_more.removeEventListener(MouseEvent.CLICK, thirtyminmore);
btns_mc.btn_30_min_more.removeEventListener(MouseEvent.MOUSE_OVER, thirtyminmoreOver);
btns_mc.btn_30_min_more.removeEventListener(MouseEvent.MOUSE_OUT, thirtyminmoreOut);
btns_mc.btn_hr_less.removeEventListener(MouseEvent.CLICK, hrless);
btns_mc.btn_hr_less.removeEventListener(MouseEvent.MOUSE_OVER, hrlessOver);
btns_mc.btn_hr_less.removeEventListener(MouseEvent.MOUSE_OUT, hrlessOut);
btns_mc.btn_hr_more.removeEventListener(MouseEvent.CLICK, hrmore);
btns_mc.btn_hr_more.removeEventListener(MouseEvent.MOUSE_OVER, hrmoreOver);
btns_mc.btn_hr_more.removeEventListener(MouseEvent.MOUSE_OUT, hrmoreOut);
btns_mc.btn_check_mc.removeEventListener(MouseEvent.CLICK, checker);
btns_mc.btn_min_less.buttonMode=false;
btns_mc.btn_min_more.buttonMode=false;
btns_mc.btn_5_min_less.buttonMode=false;
btns_mc.btn_5_min_more.buttonMode=false;
btns_mc.btn_10_min_less.buttonMode=false;
btns_mc.btn_10_min_more.buttonMode=false;
btns_mc.btn_15_min_less.buttonMode=false;
btns_mc.btn_15_min_more.buttonMode=false;
btns_mc.btn_30_min_less.buttonMode=false;
btns_mc.btn_30_min_more.buttonMode=false;
btns_mc.btn_hr_less.buttonMode=false;
btns_mc.btn_hr_more.buttonMode=false;
btns_mc.btn_check_mc.buttonMode=false;
}
hope you can help
thanks
fonzio
I don't know what's problem exactly (maybe constant in a function).
Anyways, the code I gave you wasn't meant to be inside a function. Put all my code outside the function hoursrules() and leave only checkPhase(hours) there.
Also, enable Permit debugging in Publish settings so you can paste errormessage with the exact line number.
ok moved all your code to the bottom
now i get this
symbol gametwo_mc frame 1 line 625:1067
var currentPhaseStart:int = getLabelFrameNumber(sea_mc.currentLabel);
1067: Implicit coercion of a value of type String to an unrelated type flash.display:MovieClip.
symbol gametwo_mc frame 1 line 625:1136
var currentPhaseStart:int = getLabelFrameNumber(sea_mc.currentLabel);
1136: Incorrect number of arguments. Expected 2.
symbol gametwo_mc frame 1 line 628:1067
1067: Implicit coercion of a value of type String to an unrelated type flash.display:MovieClip.
var newPhaseStart:int = getLabelFrameNumber(phase);
symbol gametwo_mc frame 1 line 628:1136
1136: Incorrect number of arguments. Expected 2.
var newPhaseStart:int = getLabelFrameNumber(phase);
the randomtime function contains hour instead of hours wondering if this may be the prob?
hope you can help,
thanks
fonzio
well it works, but im getting the trace output of something went wrong, here is what has been changed, hopefully i got them all.
i dont know what is up with my computer or maybe flash is having memory issues, but the sea sometimes flashes red, and when i test (ctrl+enter) sometimes i dont get the output window, anyway im sure its my comp, i will test it on my brothers when we stop this trace.
const PHASES:Array = [
{
hour: 19,
label: "nighttime_sea"
},
{
hour: 17,
label: "sunset_sea"
},
{
hour: 8,
label: "daytime_sea"
},
{
hour: 6,
label: "dawn_sea"
},
{
hour: 24,
label: "nighttime_sea"
}
];
// you call this function whenewer you want to test hour and possibly change day time
function checkPhase(hour:Number):void {
for(var i:int = 0; i < PHASES.length; i++) {
if(PHASES[i].hour < hour) {
showPhase(PHASES[i].label);
return;
}
}
trace("Something went wrong, this line shouldn't execute.")
}
function showPhase(phase:String):void {
if(phase == sea_mc.currentLabel) return;
var currentPhaseStart:int = getLabelFrameNumber(sea_mc, sea_mc.currentLabel);
var frameOffset:int = sea_mc.currentFrame - currentPhaseStart;
var newPhaseStart:int = getLabelFrameNumber(sea_mc, phase);
sea_mc.gotoAndPlay(newPhaseStart + frameOffset);
}
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
nearly there, thanks for all your help
fonzio
No problem. I added few comments but the code is quite self-explanatory. For more information you might need deeper understanding of classes and properties used.
You can find this information in ActionScript 3.0 language reference.
import flash.display.FrameLabel;
import flash.display.MovieClip;
// an array that defines which day phase starts at what hour
const PHASES:Array = [
{
hour: 20,
label: "night"
},
{
hour: 19,
label: "sunset"
},
{
hour: 7,
label: "day"
},
{
hour: 6,
label: "sunrise"
},
{
hour: 0,
label: "night"
}
];
// the actual function that checks what day phase it is and shows it
function checkPhase(hour:Number):void {
for(var i:int = 0; i < PHASES.length; i++) {
// find appropriate day phase
if(PHASES[i].hour < hour) {
showPhase(PHASES[i].label);
return;
}
}
trace("Something went wrong, this line shouldn't execute.")
}
// finds right frame to show
function showPhase(phase:String):void {
// if the phase is currently set, no need to set it again
if(phase == sea_mc.currentLabel) return;
// get frame number for start of current phase
var currentPhaseStart:int = getLabelFrameNumber(sea_mc, sea_mc.currentLabel);
// get number of frames the animation ran in current phase
var frameOffset:int = sea_mc.currentFrame - currentPhaseStart;
// get frame number for start of new phase
var newPhaseStart:int = getLabelFrameNumber(sea_mc, phase);
// add offset frames so the animation continues from the exact point and call gotoandplay
sea_mc.gotoAndPlay(newPhaseStart + frameOffset);
}
/* UTILS */
// self-explanatory function, uses methods and properties in flash.display.MovieClip
function getLabelFrameNumber(target:MovieClip, label:String):int {
var index:int = getLabelIndex(target, label);
if (index == -1) return -1;
return FrameLabel(target.currentLabels[index]).frame;
}
// self-explanatory function, uses methods and properties in flash.display.MovieClip
function getLabelIndex(target:MovieClip, label:String):int {
for (var i:int = 0; i < target.currentLabels.length; i++) {
if (FrameLabel(target.currentLabels[i]).name == label) {
return i;
}
}
return -1;
}
thanks peter, thats just what i needed.
Since my computer has been really slow lately and maybe affecting flash performance, i took the clock app to my brothers today, however it kept crashing his flash app when i tried to run it, he has CS5, whereas im using CS4.
could this be why?
i instead let him view the swf which worked fine although for some reason my arial text was not showing up, i assume i need to embed all arial characters and numbers?
i have done it via the text properties where it says embed characters, will this suffice? or will i need to embed it into the library?
thanks again for all your help
fonzio
The questions no longer relate to the original one so you should ask it as a new question (as a new thread) - this way you get more people to look at it. I'm not sure about the crashes. And EMBED button should suffice. You should set appropriate characters to be embed (lowercase, uppercase, numbers..).
North America
Europe, Middle East and Africa
Asia Pacific