Abdul Qabiz 
<[EMAIL PROTECTED]> to flexcoders
 More options  Apr 23
Hi,

>However, I'm still unable to do the following:
>Call a setInterval within a class. Have the setInterval pass over a
>number. And the function called increment that number. Pass this new
>number to a textfield object.
>If I call:
>setInterval(this,"somefunction", 1000, 5)
>function somefunction ( e : Number) {
> e++
>mx.controls.Alert.show(e)
>// shows 6
>}

I think, it would trace "6" repeatedly over the interval. And I feel that
there is no reason it won't work.

I just created a sample to verify if my feelings are right :)

This sample is demonstrating setInterval(..) inside a class. Look at the
attached files or code later in this mail.

Hope that helps...

-abdul


1) ##Counter.as##

import mx.core.UIObject;

[Event("start")]
[Event("increment")]
[Event("stop")]

class Counter extends UIObject
{

   var counterIntervalId:Number;
   var __delay:Number = 50;
   var __min:Number = 0;
   var __max:Number = 100;
   var __count:Number = 0;
   var running:Boolean = false;

   function Counter(delay:Number, min:Number, max:Number)
   {

       __min = min ? min : 0;
       __max = max ? max : 100;
       __delay = delay ? delay : 50;
   }

   function startCounter():Void
   {

       __count = 0;
       running = true;
       dispatchEvent({type:"start"});
       counterIntervalId = setInterval(this,"incrementCou
nt", __delay,
__min);

       //you can also do this:
       //counterIntervalId =
setInterval(mx.utils.Delegate.create(this,incrementCount), __delay, __min);

   }

   function incrementCount(num):Void
   {
         if(__count < __max)
         {

           //un-comment the following to see setInterval (..) passes same
number agian and again
          // mx.controls.Alert.show(num.toString());
           __count++;
           dispatchEvent({type:"increment"});
         }
         else
         {
             stopCounter();
         }

   }

   function stopCounter():Void
   {
       clearInterval(counterIntervalId);
       __count = 0;
       running = false
       dispatchEvent({type:"stop"});
   }

   function get min():Number
   {
       return __min;
   }
   function set min(newValue:Number):Void
   {
       __min = newValue;
   }

   function get max():Number
   {
       return __max;
   }
   function set max(newValue:Number):Void
   {
       __max = newValue;
   }
   function get value():Number
   {
       return __count;
   }

}



2) ##setIntervalExample.mxml##

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application width="800" height="600"
xmlns:mx=" http://www.macromedia.com/2003/mxml"  initialize="onAppInit()">

   <mx:Script>
       <![CDATA[

           import Counter;
           import mx.utils.Delegate;

           var counter:Counter;

           function onAppInit()
           {
               counter = new Counter();
               changeLimit();

               counter.addEventListener("start", Delegate.create(this,
onCounterStart));
               counter.addEventListener("increment", Delegate.create(this,
onCounterIncrement));
               counter.addEventListener("stop", Delegate.create (this,
onCounterStop));
           }

           function onCounterStart(event)
           {
               _ta.text +="Counter started..\n";
           }
           function onCounterIncrement(event)
           {
               _ta.text += event.target.value + "\n";
           }
           function onCounterStop(event)
           {
               _ta.text += "Counter stopped...\n";
           }

           function changeLimit()
           {
               counter.min = slider.values[0];
               counter.max = slider.values[1];
           }


       ]]>
   </mx:Script>
   <mx:HBox>
       <mx:Label text="Count:"/><mx:TextArea id="_ta" width="300"
height="150" />
   </mx:HBox>
   <mx:HBox>

       <mx:Button label="Start Counter" click="counter.startCounter();"
enabled="{!counter.running}"/>
       <mx:Button label="Stop Counter" click="counter.stopCounter ();"
enabled="{counter.running}"/>

   </mx:HBox>
   <mx:HSlider id="slider"
              toolTipPlacement="top"

              thumbCount="2"
              labels="['min', 'max']"
              values="[0, 100]"
              snapInterval="1"
              change="changeLimit();"
              allowTrackClick="true"
              maximum="1000"
              minimum="0"/>
</mx:Application>



On 5/25/05, Erik Westra <[EMAIL PROTECTED]> wrote:
The documentation seems not correct here:

setInterval(objectName:Object, methodName:Function, interval:Number [,
param1:Object, param2, ..., paramN]) : Number

I thought methodName should be of type string when using an object as
1th parameter.


Greetz Erik

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com ] On
Behalf Of loveewind
Sent: woensdag 25 mei 2005 13:52
To: flexcoders@yahoogroups.com
Subject: [flexcoders] how to use the setInterval() in flex actionscript
?

the code run normally in swf,

ActionScript:
function checkOut()
{
     TextToCheck = spellCheck_txt.text;
     url_string = "_javascript_:SpellCheck();";
     getURL(url_string, "");
     checkOut_interval = setInterval(function ()
     {
          if (spellResult != undefined)
          {
               spellCheck_txt.text = spellResult;
               clearInterval(checkOut_interval);
          } // end if
     }, 100);
}




and how to use setInterval() in flex actionscript

as referred in flex actionscript reference:

setInterval(functionName:Function, interval:Number [, param1:Object,
param2, ..., paramN]) : Number setInterval(objectName:Object,
methodName:Function, interval:Number [, param1:Object, param2, ...,
paramN]) : Number Parameters functionName A function name or a reference
to an anonymous function.

interval The time in milliseconds between calls to the functionName or
methodName parameter.

param1, param2, ..., paramN Optional parameters passed to the
functionName or methodName parameter.

objectName An object containing the method methodName. You must include
this parameter when using setInterval() in an <mx:Script> block in Flex
applications.



thanks




Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/






Yahoo! Groups Links

Reply via email to