Skip to main content
June 16, 2010
Answered

Timer Method and if statements?

  • June 16, 2010
  • 1 reply
  • 785 views

I am interested in have a dynamic text field display three quotes at different intervals.

I thought I could use the Timer to trigger these quotes by loading them into the dynamic TextField.

However, I cannot seem to get it going.

I try to attach a number from the timer but that throws an error /1176: Comparison between a value with static type flash.utils:Timer and a possibly unrelated type int.�

First is this a good way to approach it?

If so this is my current code:

import flash.utils.Timer;
import flash.events.TimerEvent;

var timer:Timer=new Timer(1000,0);

timer.addEventListener(TimerEvent.TIMER, goQuotes);

timer.start();

function goQuotes(e:TimerEvent):void {

    var reqA:URLRequest=new URLRequest("suzukiRules/ruleA.txt");

    var loaderA:URLLoader = new URLLoader();

    loaderA.addEventListener(Event.COMPLETE, textLoadedB);

    loaderA.load(reqA);

    function textLoadedB(event:Event):void {

        ruleLoaderA.text=loaderA.data;

       

        if (timer>1000) {

            var reqB:URLRequest=new URLRequest("suzukiRules/ruleB.txt");

            var loaderB:URLLoader = new URLLoader();

            loaderB.addEventListener(Event.COMPLETE, textLoadedC);

            loaderB.load(reqB);

            function textLoadedC(event:Event):void {


                ruleLoaderA.text=loaderB.data;
                //if(timer>1000){


            }
        }

    }
}
This topic has been closed for replies.
Correct answer kglad

use the currentCount property of your timer and don't repeatedly load the same thing:

    function textLoadedB(event:Event):void {

         ruleLoaderA.text=loaderA.data;

       

        if (timer.currentCount==2) {

             var reqB:URLRequest=new URLRequest("suzukiRules/ruleB.txt");

             var loaderB:URLLoader = new URLLoader();

             loaderB.addEventListener(Event.COMPLETE, textLoadedC);

             loaderB.load(reqB);

            function  textLoadedC(event:Event):void {


                 ruleLoaderA.text=loaderB.data;
                 //if(timer>1000){


            }
        }


1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 16, 2010

use the currentCount property of your timer and don't repeatedly load the same thing:

    function textLoadedB(event:Event):void {

         ruleLoaderA.text=loaderA.data;

       

        if (timer.currentCount==2) {

             var reqB:URLRequest=new URLRequest("suzukiRules/ruleB.txt");

             var loaderB:URLLoader = new URLLoader();

             loaderB.addEventListener(Event.COMPLETE, textLoadedC);

             loaderB.load(reqB);

            function  textLoadedC(event:Event):void {


                 ruleLoaderA.text=loaderB.data;
                 //if(timer>1000){


            }
        }


June 16, 2010

You're awesome.

Thanks that was it.

I was not aware of current count

kglad
Community Expert
Community Expert
June 16, 2010

you're welcome.