Karl, I'm not sure how to benchmark memory in AS 2. I think that what you
might want to benchmark here is cpu performance, anyway.

In this particular case, I don't think you can benchmark much, though.
Basically, all performance benchmarks I've seen are based on getTimer (two
simple calls to getTimer, one before running the code you're interested in,
and one after; the difference is very roughly how much your code took to
run; there are more sophisticated suites (like Grant Skinner's), but to my
knowledge, all are based on the same principle).

The problem here is that what seems to be taking too long is an internal
mechanism of the player (managing and dispatching onChanged, for instance).
Can't think of a way of timing that off the top of my head.

If one the methods runs your fan wild and the other one doesn't, though, you
have a clear winner already!

Cheers
Juan Pablo Califano


2010/6/16 Karl DeSaulniers <k...@designdrumm.com>

> On that note, what would be a good way to get a benchmark for this?
> Any pointers?
>
> Karl
>
>
> On Jun 16, 2010, at 3:47 PM, Karl DeSaulniers wrote:
>
> Ahh.. let me try that.
>> I am sure you are correct.
>> That way it only checks to see if that textField is changing when focus is
>> on it.
>> And being that onChanged was less memory intensive than onEnterFrame
>> that makes sense. But my tests are not finite.
>> I do not have a benchmark result or anything stating
>> how much memory my swf is using while in the browser.
>> But it would seem the onSetFocus/onKillFocus keeps any extra memory from
>> being used in either case.
>> Thanks again Juan.
>>
>>
>> Karl
>>
>>
>> On Jun 16, 2010, at 8:09 AM, Juan Pablo Califano wrote:
>>
>> Not really. In theory, onChanged should be less intensive, I think. But,
>>> from your description it seems it isn't, so go figure...
>>>
>>> I'd go with the onSetFocus / onKillFocus then, but I'd do another test,
>>> just
>>> out of curiosity. Instead of setting an enterframe when you get focus and
>>> nulling it when focus is lost, what happens is you use the onChanged
>>> event
>>> instead?
>>>
>>> I mean, something like:
>>>
>>> textbox.onSetFocus = function() {
>>>   textbox.onChanged = etc...;
>>> };
>>> textbox.onKillFocus = function() {
>>>   textbox.onChanged = null;
>>> }
>>> Cheers
>>> Juan Pablo Califano
>>>
>>> 2010/6/16 Karl DeSaulniers <k...@designdrumm.com>
>>>
>>> Hi Juan,
>>>> Interesting enough, it seems your solution also runs my fan a bit wild
>>>> too.
>>>> Not as bad, I'd say about half as much.
>>>> I know its the form because I have tested many times. Every time I close
>>>> the browser window that has the form, my fan slows to a stop almost
>>>> immediately.
>>>> I chose the onFocus mainly because I knew that it was the onEnterFrame
>>>> that
>>>> was taking up memory, so I wanted it to fire only when someone was
>>>> typing.
>>>> It looks like my suggestion does just that. The fan never kicks on.
>>>>
>>>> My purpose for this is to set up a flash site that takes little to no
>>>> memory usage.
>>>> Am I right in assuming that this is memory usage by the code that makes
>>>> my
>>>> fan kick in.
>>>> I've been nulling any onEnterFrames, removing listeners, etc.
>>>> Any thoughts as to why the onChanged eats memory too?
>>>> TIA
>>>>
>>>> Karl
>>>>
>>>>
>>>> On Jun 15, 2010, at 9:56 PM, Juan Pablo Califano wrote:
>>>>
>>>>  It seems like you don't really need to bother about gaining or losing
>>>>
>>>>> focus
>>>>> here. Just listening to the change event will do the job and you could
>>>>> remove the enter_frame.
>>>>>
>>>>>
>>>>> commentxt_mc.onChanged = function(tf:TextField):Void {
>>>>>      var numChar:Number = 650 - tf.length;
>>>>>      if (numChar == 0) {
>>>>>              maxChar = "Max Characters Reached";
>>>>>      } else {
>>>>>              maxChar = "Max Char: " + numChar.toString(); //Have
>>>>> another
>>>>> text box with the var maxChar to display the results while typing.
>>>>>      }
>>>>> };
>>>>>
>>>>> The equivalent in AS 3.0 is very similar, though a bit more verbose (as
>>>>> usual!):
>>>>>
>>>>> commentxt_mc.addEventListener(Event.CHANGE,handleTextChange);
>>>>>
>>>>> function handleTextChange(e:Event):void {
>>>>> var tf:TextField = e.target as TextField;
>>>>> if(!tf) {
>>>>> return;
>>>>> }
>>>>> var numChar:Number = 650 - tf.length;
>>>>> var maxChar:String = "";
>>>>> if (numChar == 0) {
>>>>> maxChar = "Max Characters Reached";
>>>>> } else {
>>>>> maxChar = "Max Char: " + numChar.toString(); //Have another text box
>>>>> with
>>>>> the var maxChar to display the results while typing.
>>>>> }
>>>>> }
>>>>>
>>>>> Cheers
>>>>> Juan Pablo Califano
>>>>>
>>>>> 2010/6/15 Karl DeSaulniers <k...@designdrumm.com>
>>>>>
>>>>> PERFECTO!
>>>>>
>>>>>>
>>>>>> Thanks Amol,
>>>>>>
>>>>>> For anyone who might want this. I have made a script that will read
>>>>>> the
>>>>>> length of a text field and display the number of characters left while
>>>>>> someone was typing.
>>>>>> The reason for the code I was seeking with this request was because
>>>>>> the
>>>>>> code previously would eat up a lot of memory. It made my computer fan
>>>>>> run
>>>>>> wild if the form sat in my browser.
>>>>>> Now it does not thanks to Amol.  :))
>>>>>>
>>>>>> Here is the code competed. Again, it is as2, but would love to see an
>>>>>> as3
>>>>>> conversion.
>>>>>> I might get to that later, but welcome any comers.
>>>>>>
>>>>>> //commentxt_mc is the textfield name, 650 is the number of characters
>>>>>> allowed. You will also want to set the text box max characters to this
>>>>>> when
>>>>>> creating your text box.
>>>>>> var numChar;
>>>>>> commentxt_mc.onSetFocus = function() {
>>>>>>  onEnterFrame = function() {
>>>>>>      numChar = 650 - commentxt_mc.length;
>>>>>>      if (numChar == 0) {
>>>>>>              maxChar = "Max Characters Reached";
>>>>>>      } else {
>>>>>>              maxChar = "Max Char: " + numChar.toString(); //Have
>>>>>> another
>>>>>> text box with the var maxChar to display the results while typing.
>>>>>>      }
>>>>>>  }
>>>>>> };
>>>>>> commentxt_mc.onKillFocus = function() {
>>>>>>  onEnterFrame = null;
>>>>>> };
>>>>>>
>>>>>> Best,
>>>>>>
>>>>>> Karl
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Jun 15, 2010, at 1:34 AM, Amol wrote:
>>>>>>
>>>>>>  Hi,
>>>>>>
>>>>>>
>>>>>>> use set fouse  for text ,
>>>>>>>
>>>>>>> sample_txt.onSetFocus = sample1_txt.onSetFocus = function ()
>>>>>>> {
>>>>>>>  this.border = true;
>>>>>>>  this.borderColor = 13683368;
>>>>>>>  this.background = true;
>>>>>>>  this.backgroundColor = 13683368;
>>>>>>> };
>>>>>>> sample_txt.onKillFocus = sample1_txt.onKillFocus = function ()
>>>>>>> {
>>>>>>>  this.border = true;
>>>>>>>  this.borderColor = 0;
>>>>>>>  this.background = true;
>>>>>>>  this.backgroundColor = 0;
>>>>>>> };
>>>>>>>
>>>>>>>
>>>>>>> Regards amol
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ----- Original Message ----- From: "Karl DeSaulniers" <
>>>>>>> k...@designdrumm.com>
>>>>>>> To: "Flash List" <flashcoders@chattyfig.figleaf.com>
>>>>>>> Sent: Tuesday, June 15, 2010 9:51 AM
>>>>>>> Subject: [Flashcoders] Text area focus
>>>>>>>
>>>>>>>
>>>>>>>  Hello,
>>>>>>>
>>>>>>> I have a text box or area on a form that I would like to know when a
>>>>>>>>  user has put the cursor in it or not.
>>>>>>>> Wither it has focus or not. I am working in AS2. Please don't grit
>>>>>>>>  your
>>>>>>>> teeth too much :-)
>>>>>>>> For some reason I am not able to get the focus of my text area.
>>>>>>>> Anyone have this code in their scrap files?.. lol
>>>>>>>> TIA
>>>>>>>> Karl DeSaulniers
>>>>>>>> Design Drumm
>>>>>>>> http://designdrumm.com
>>>>>>>> _______________________________________________
>>>>>>>> Flashcoders mailing list
>>>>>>>> Flashcoders@chattyfig.figleaf.com
>>>>>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>>>>>
>>>>>>>>  _______________________________________________
>>>>>>>>
>>>>>>>> Flashcoders mailing list
>>>>>>> Flashcoders@chattyfig.figleaf.com
>>>>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>>>>
>>>>>>>
>>>>>>> Karl DeSaulniers
>>>>>> Design Drumm
>>>>>> http://designdrumm.com
>>>>>>
>>>>>> _______________________________________________
>>>>>> Flashcoders mailing list
>>>>>> Flashcoders@chattyfig.figleaf.com
>>>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>>>
>>>>>> _______________________________________________
>>>>>>
>>>>> Flashcoders mailing list
>>>>> Flashcoders@chattyfig.figleaf.com
>>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>>
>>>>>
>>>> Karl DeSaulniers
>>>> Design Drumm
>>>> http://designdrumm.com
>>>>
>>>> _______________________________________________
>>>> Flashcoders mailing list
>>>> Flashcoders@chattyfig.figleaf.com
>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>
>>>> _______________________________________________
>>> Flashcoders mailing list
>>> Flashcoders@chattyfig.figleaf.com
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>
>> Karl DeSaulniers
>> Design Drumm
>> http://designdrumm.com
>>
>> _______________________________________________
>> Flashcoders mailing list
>> Flashcoders@chattyfig.figleaf.com
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to