|
-
Designs Required ask BlymMedia
HELP!!! ActionScript 2.0 vs ActionScript 3.0
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 ate = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate ate = 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
-
AKA [ Paul Bainbridge]
-
Designs Required ask BlymMedia
I'm sorry what do you mean by "Tag your code"?
Thanks,
BlymMedia
-
Wrap your code with the [.code][/code] tags.
-
Designs Required ask BlymMedia
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
-
OOP is one letter from OOPS
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:
Code:
/**
* ...
* @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:
Code:
/**
* ...
* @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;
}
}
}
-
Designs Required ask BlymMedia
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
-
AKA [ Paul Bainbridge]
 Originally Posted by BlymMedia
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.
Last edited by webdreamer; 01-18-2008 at 11:03 AM.
-
trace("AKA: Biro Barna");
 Originally Posted by BlymMedia
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.
Last edited by fx.barrett; 01-18-2008 at 11:18 AM.

| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
OOP is one letter from OOPS
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...9uL3dpZGdldA==
-
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...
-
OOP is one letter from OOPS
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
-
OOP is one letter from OOPS
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));
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|