Re: [Flashcoders] array.indexOf problem

2009-06-16 Thread Todd Kerpelman
It sounds like your array is full of button objects, but you're
searching for a string (the button name), and an object and a string
don't match.

Remove the .name from the key you're searching for, and I believe it
should work.

-T



On 6/16/09, Isaac Alves  wrote:
> Hi fellows,
> Cannot solve this problem:
>
> function buttonClicked(e:Event):void {
>  trace (buttonsArray.indexOf(e.target.name));
>
> It always  traces "-1". This code should trace the index of the Array
> element right? for ex: 0, 1, 2 or 3.
>
> If i do this, it will trace the correct name of the element.
>
> function buttonClicked(e:Event):void {
>  trace (e.target.name);
>
> If I do this, it will trace the name of the second element:
>
> function buttonClicked(e:Event):void {
>  trace (buttonsArray[1].name);
>
> Why indexOf doesn´t work properly?
>
> Thanks a lot!
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>

-- 
Sent from my mobile device

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] array.indexOf problem

2009-06-16 Thread Steven Sacks

Your sample doesn't show how you build the Array.

So the answer to your incomplete question is nothing different than  
what Flash is telling you.


The reason it returns -1 is because indexOf couldn't find a STRICT  
EQUALITY match for e.target.name in your array.


If you posted how you built buttonsArray, you'd probably solve your  
own problem by looking at the code you wrote more closely.



On Jun 16, 2009, at 12:48 PM, Isaac Alves wrote:


Hi fellows,
Cannot solve this problem:

   function buttonClicked(e:Event):void {
trace (buttonsArray.indexOf(e.target.name));

It always  traces "-1". This code should trace the index of the Array
element right? for ex: 0, 1, 2 or 3.

If i do this, it will trace the correct name of the element.

   function buttonClicked(e:Event):void {
trace (e.target.name);

If I do this, it will trace the name of the second element:

   function buttonClicked(e:Event):void {
trace (buttonsArray[1].name);

Why indexOf doesn´t work properly?

Thanks a lot!
___
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


Re: [Flashcoders] array.indexOf problem

2009-06-16 Thread Keith H

trace (buttonsArray.indexOf(e.target.name));


Looking at the aboveyour "buttonsArray"  is  an  Array containing 
Objects.

And you are using the "indexOf" method looking for a String.

Take off the ".name" property and you should see a difference.


-- Keith H --
www.keith-hair.net





Isaac Alves wrote:

Hi fellows,
Cannot solve this problem:

function buttonClicked(e:Event):void {
 trace (buttonsArray.indexOf(e.target.name));

It always  traces "-1". This code should trace the index of the Array
element right? for ex: 0, 1, 2 or 3.

If i do this, it will trace the correct name of the element.

function buttonClicked(e:Event):void {
 trace (e.target.name);

If I do this, it will trace the name of the second element:

function buttonClicked(e:Event):void {
 trace (buttonsArray[1].name);

Why indexOf doesn´t work properly?

Thanks a lot!
___
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


Re: [Flashcoders] array.indexOf problem

2009-06-16 Thread Juan Pablo Califano
Hi,

Perhaps you're storing a reference to the button in buttonsArray?

In that case, you should do:

buttonsArray.indexOf(e.target);


Cheers
Juan Pablo Califano


2009/6/16, Isaac Alves :
>
> Hi fellows,
> Cannot solve this problem:
>
>function buttonClicked(e:Event):void {
> trace (buttonsArray.indexOf(e.target.name));
>
> It always  traces "-1". This code should trace the index of the Array
> element right? for ex: 0, 1, 2 or 3.
>
> If i do this, it will trace the correct name of the element.
>
>function buttonClicked(e:Event):void {
> trace (e.target.name);
>
> If I do this, it will trace the name of the second element:
>
>function buttonClicked(e:Event):void {
> trace (buttonsArray[1].name);
>
> Why indexOf doesn´t work properly?
>
> Thanks a lot!
> ___
> 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


Re: [Flashcoders] array.indexOf problem

2009-06-16 Thread Glen Pike

Try e.currentTarget ??

Isaac Alves wrote:

Hi fellows,
Cannot solve this problem:

function buttonClicked(e:Event):void {
 trace (buttonsArray.indexOf(e.target.name));

It always  traces "-1". This code should trace the index of the Array
element right? for ex: 0, 1, 2 or 3.

If i do this, it will trace the correct name of the element.

function buttonClicked(e:Event):void {
 trace (e.target.name);

If I do this, it will trace the name of the second element:

function buttonClicked(e:Event):void {
 trace (buttonsArray[1].name);

Why indexOf doesn´t work properly?

Thanks a lot!
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


  


--

Glen Pike
01326 218440
www.glenpike.co.uk 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders