Click to See Complete Forum and Search --> : HELP!!! ActionScript 2.0 vs ActionScript 3.0
BlymMedia
01-17-2008, 04:18 PM
Good day all,
I created a countdown timer in FLASH CS3 using actionscript 2.0 but I want to use actionscript 3.0
Below is my actionscript 2.0 code.
this.onEnterFrame = function() {
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date(currentYear,2,10);
var targetTime = targetDate.getTime();
var timeLeft = targetTime - currentTime;
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
var hrs = Math.floor(min/60);
var days = Math.floor(hrs/24);
sec = string(sec % 60);
if (sec.length < 2){
sec = "0" + sec;
}
min =string(min % 60);
if (min.length < 2){
min = "0" + min;
}
hrs = string(hrs % 24);
if (hrs.length < 2){
hrs = "0" + hrs;
}
days = string(days)
var counter:String = days + ":" + hrs + ":" + min + ":" + sec;
time_txt.text = counter;
}
Does anyone know what I need to add to my code in order for it to work in FLASH CS3 using actionscript 3.0.
Any help would be greatly appreciated.
Thanks,
BlymMedia
webdreamer
01-17-2008, 04:37 PM
Tag your code please
BlymMedia
01-17-2008, 05:05 PM
I'm sorry what do you mean by "Tag your code"?
Thanks,
BlymMedia
Hurdarr
01-17-2008, 05:30 PM
Wrap your code with the [.code][/code] tags.
BlymMedia
01-17-2008, 06:34 PM
Sorry gents, I'm new to the whole Flash Actionscript 3.0.....Any chance you could add the "TAGS" to my code so I know what the code looks like which in turn will help me understand what you mean by "TAG" your code.
Cheers,
BlymMedia
kortex
01-17-2008, 06:48 PM
Did this for work. Check the imports as this went through a few revisions and this is an older version. They may not all me needed.
View:
/**
* ...
* @author Default
* @version 0.1
*/
package {
import com.myyearbook.timers.CountDown;
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
public class CountDownClip extends MovieClip {
private var textFormat:TextFormat
private var countDown:CountDown;
private var _timer:Timer;
public function CountDownClip() {
this.textFormat = new TextFormat();
this.textFormat.font = "College";
this.textFormat.bold = true;
this.countDown = new CountDown(new Date(2008,0,20,8,0,0,0));
//trigger the update event on creation so that the time is not blank until the first timer event.
this.updateCountDown(new TimerEvent(TimerEvent.TIMER));
this._timer= new Timer(1000);
this._timer.addEventListener(TimerEvent.TIMER, updateCountDown);
this._timer.start();
}
public function updateCountDown(evt:TimerEvent) {
var timer:CountDown = this.countDown.getCountDown();
var seconds:String = String(timer.seconds);
var minutes:String = String(timer.minutes);
var hours:String = String(timer.hours);
var days:String = String(timer.days);
if (seconds.length < 2) {
seconds = "0" + seconds;
}
if (minutes.length < 2) {
minutes = "0" + minutes;
}
if (hours.length < 2) {
hours = "0" + hours;
}
if (days.length < 2) {
days = "0" + days;
}
this.daysText.text = days;
this.hoursText.text = hours;
this.minutesText.text = minutes;
this.secondsText.text = seconds;
this.daysText.setTextFormat(this.textFormat)
this.hoursText.setTextFormat(this.textFormat)
this.minutesText.setTextFormat(this.textFormat)
this.secondsText.setTextFormat(this.textFormat)
}
}
}
Model:
/**
* ...
* @author Default
* @version 0.1
*/
package com.myyearbook.timers {
public class CountDown{
private var countDownTo:Date;
private var _days:Number
private var _hours:Number
private var _minutes:Number
private var _seconds:Number
public function CountDown(countDownTo:Date) {
this.countDownTo = countDownTo;
}
public function getCountDown() {
var currentDate:Date = new Date();
var timeLeft:Number = (this.countDownTo.getTime() - currentDate.getTime());
var seconds:Number = Math.floor(timeLeft/1000);
var minutes:Number = Math.floor(seconds/60);
var hours:Number = Math.floor(minutes/60);
var days:Number = Math.floor(hours / 24);
this._seconds = seconds % 60;
this._minutes = minutes % 60;
this._hours = hours % 24;
this._days = days;
//trace("days " +this._days+ " hours " +this._hours+ " Minutes " +this._minutes+ " Seconds " + this._seconds)
}
public function get seconds() {
return this._seconds;
}
public function get minutes () {
return this._minutes;
}
public function get hours() {
return this._hours;
}
public function get days() {
return this._days;
}
}
}
BlymMedia
01-18-2008, 09:44 AM
Thanks for your help Kortex but that’s seems like it would be a lot of work compared to actionscript 2.0. Does anyone know a simpler way of recreating this code in actionscript 3.0?
Thanks again,
BlymMedia
webdreamer
01-18-2008, 09:51 AM
Thanks for your help Kortex but that’s seems like it would be a lot of work compared to actionscript 2.0. Does anyone know a simpler way of recreating this code in actionscript 3.0?
Thanks again,
BlymMedia
Hey dude thats the code. There is no easy way of doing AS3. I have been coding for the best part of 6 years and i am still not looking forward to having to look at it.
fx.barrett
01-18-2008, 10:02 AM
Thanks for your help Kortex but that’s seems like it would be a lot of work compared to actionscript 2.0. Does anyone know a simpler way of recreating this code in actionscript 3.0?
Thanks again,
BlymMedia
Dude, that code is simple as hell... If you find that one hard then I have no idea what do you understand by "easy"... and regarding the work, I don't think that any of us is here to work instead of you, Kortex provided really helpful information there, can't handle it, then you should reconsider your job...
Yeah, I'm rude but I can't stand it when I see people running around and saying "it would be a lot of work compared to actionscript 2.0", that only points out that you have no idea what you are talking about ( AS 2.0 is baby poop compared to AS 3.0 ) and "Does anyone know a simpler way of recreating this code in actionscript 3.0?" - not sure if anyone does, but if we would, and post you the code, would you share your salary with us... because I think we'd deserve it more then you...
I just hate people who don't take the time to learn something or to actually give a **** about their work... carry on
PS: the forum is for posting questions and filling in some gaps in your knowledge, if you want others to do your job instead of you, then you missed the forum, try the Freelance forum instead... instead of thanking Kortex because he tried to help ( in the best way possible ), you whine about the code and ask for a complete solution ( another solution )... do you feel that as being normal ? I don't...
PPS: If you really want to learn AS 3.0, then start by picking up a book and stop posting your code hopping that someone will come along and rewrite it for you.
kortex
01-18-2008, 10:02 AM
While that may look like a lot of work, now that I have done that, I can literately create a new countdown movie in as long as it takes to visually create the interface. I should probably mention that in the posted implementation, it assumes the view is attached to a library item via the linkage dialog and the clip that it is attached to contains text fields with the appropriate instance names.
With these two classes I can create basically unlimited count down interfaces. All i have to do is create a movieclip with the appropriate textfields and link the class to it.
If you want to see what this particular movie looks like:
http://www.myyearbook.com/?mysession=YWR2ZXJ0aXNpbmdfYnJpbmdpdG9uL3dpZGdldA= =
Cortana
01-18-2008, 12:48 PM
Wow you seem like such a grumpy old man PC lol! Most people who deal with Flash aren't programmers and so code like the one provided may seem a little bit complicated compared to the simple stuff they're used to. I completely understand your view point and I also dislike people always looking for a 'quick fix'. But still...
kortex
01-18-2008, 01:19 PM
Well it is something new to learn. Even after having programmed in AS2 for 4 years, switching to AS3 has a bit of a learning curve, but as I get used to it, I a liking it more and more.
What I find odd is that I posted the code. Copy and paste does not seem like a lot of work to me ;)
kortex
01-22-2008, 02:25 PM
UPDATE: Since the date of the countdown has passed for the SWF we created that uses the posted classes, we took a look at this today and noticed that coutdown starts displaying negative numbers. Hence we amended the code to start counting up (time passed since target date) after the date passes. To do this simply change the following in the in the getCountDown function in the Countdown class.
var seconds:Number = Math.floor(timeLeft/1000);
to
var seconds:Number = Math.abs(Math.floor(timeLeft/1000));
flashkit.com
Copyright Internet.com Inc., All Rights Reserved.