0
votes

I am trying to get a time that is in a text document to become a variable in a Flash CS6 AS3 project. I can't seem to find where the problem is and the error messages aren't really helping. The highlighted parts are the changed lines.

Here is the newest code:

this.onEnterFrame = function()

{

var StartTime:URLLoader = new URLLoader();

StartTime.dataFormat=URLLoaderDataFormat.VARIABLES;

StartTime.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(e:Event):void {

}

StartTime.load(new URLRequest("ResponseTime.txt"));

var today:Date = new Date();

var currentTime = today.getTime();

var targetDate:Date = new Date();

var timeLeft = e.data - currentTime;

var sec = Math.floor(timeLeft/1000);

var min = Math.floor(sec/60);

sec = String(sec % 60);

if(sec.length < 2){

sec = "0" + sec;

}

min = String(min % 60);

if(min.length < 2){

min = "0" + min;

}

if(timeLeft > 0 ){

var counter:String = min + ":" + sec;

time_txt.text = counter;

}else{

    var newTime:String = "00:00";

    time_txt.text = newTime;

    delete (this.onEnterFrame);

}

}

Newest Error:

1120: Access of undefined property e. (Line 17).

1
I dont't think this.onEnterFrame works in AS3, after that you try to use a URLLoader as a Number ... you speak about an error what error ?Benjamin BOUFFIER
The errors are: 1067: Implicit coercion of a value of type String to an unrelated type flash.net:URLRequest. (Line 13) 1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type flash.net:URLRequest. (Line 13) 1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type Number. (Line 19)user3506608

1 Answers

0
votes

First of all, this does nothing :

var StartTime();

It's not correct AS3 code.

Then, AS3 loaders being asynchronous, you must way for the loader to finish load so you can get your variable. I mean that all your code after StartTime.load(...) must be inside the function onLoaded.

This way, when the loader finish loading, you'll have you variable.

That say, URLVariable is NOT a loader. It is an object you can use to put your variable into, and feed them to a loader.

If you want to download some file, use URLLoader (with URLRequest). On this page, there is a good example on how you can do that (skip the part about the dataFormat, though). The date you're requesting will be available in the data property of the event, eg :

 var timeLeft = e.data - currentTime;

I'm not asking where currentTime is from, since it's out of the scope of that question.

Good luck.