A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS3 function conflicting with another..Please help

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    3

    AS3 function conflicting with another..Please help

    Hello people I have been creating a flash front page using CS5 and AS3, I am new to AS3 so please be patient with me.

    I created a typewriter style effect using this AS3:
    Code:
    var myString2:String = "                                                                      Forums";
    var myArray2:Array = myString2.split("");
    addEventListener(Event.ENTER_FRAME, frameLooper2);
    function frameLooper2(event:Event):void {
    	if (myArray2.length > 0) {
    	  tf2.appendText(myArray2.shift());
    	} else {
    	  removeEventListener(Event.ENTER_FRAME, frameLooper2);
    	}
    }
    This code works fine at this point...... I then add this section of code to add a countdown timer:

    Code:
    this.onEnterFrame = function() {
        
    //Set the variables:
    var today:Date = new Date();
    var currentYear = today.getFullYear();
    var currentTime = today.getTime();
    
    
    //Now, here is where you can set the countdown date.
    
    //The format for dates in flash are: Year, Month (0-11, 0 being January), Day.
    //To countdown to the current year, use 'CurrentYear' or for a specific year, use '2011', '2012' etc.
    var targetDate:Date = new Date(currentYear,11,25);
    var targetTime = targetDate.getTime();
    
    //Here's all the maths. Don't edit this unless you know what you're doing!
    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;
    
    }
    This code also works fine by itself but not together, please can someone help locate the conflicting issue.

    I have uploaded the fla to http://www.tempfiles.net/download/20...385/index.html as it is too big to attach.

    Thanks in advance!

  2. #2
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    1. First one is as3 second one is as2.

    2. Both are firing on the same event.
    [SIGPIC][/SIGPIC]

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks for the reply, with regard to the event i take is that is the ENTER_FRAME event?. So how would i go about allowing the countdown to run alongside the typewrite text?. thanks in advance

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    I've managed to sort it all out now, thanks. I changed the second block of code to be as3 compliant and changed some embedding options, now it runs sweet as nut.... cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center