Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-22-2012, 11:45 PM   #1
daz1761
Senior Member
 
Join Date: Sep 2010
Posts: 165
Default Can't trace an index of an array

I'm not sure if its just getting to late in the day, but basically I copied some code over to a similar function, which traces out the array index number using indexof(e.target). For some reason I'm getting the usual undefined property errors, but it is tracing other properties in the array using e.target?

Heres my code in the document class:

ActionScript Code:
var _soloButtons:Array;             _soloButtons = new Array();             var count3:uint = 4;                         var _soloIndex:soloButton;             for (var iii:int = 0; iii < count2; iii++)             {                 _soloIndex = new soloButton();                 _soloIndex.x = soloPosX;                 _soloIndex.y = soloPosY;                 _soloIndex.addEventListener(MouseEvent.CLICK, soloTrack);                 soloPosY = soloPosY + 34.9;                 _soloIndex.soloONOFF = soloONOFF;                 _soloButtons.push(_soloIndex);                 addChild(_soloIndex);             }

And function:

ActionScript Code:
public function soloTrack(e:MouseEvent):void         {             trace("solo");             trace(e.target.soloONOFF);             trace(_soloButtons.indexOf(e.target)); //this is the line it rejects??         }

Thanks
daz1761 is offline   Reply With Quote
Old 03-23-2012, 12:00 AM   #2
PBFrO
Senior Member
 
Join Date: Jan 2007
Location: Orange County, CA
Posts: 573
Default

Instead of e.target, try e.currentTarget and see if it works. Current target applies to the item that has the event listener.
__________________
My Portfolio
PBFrO is offline   Reply With Quote
Old 03-23-2012, 12:01 AM   #3
adaminaudio
Member
 
Join Date: Jan 2012
Posts: 62
Default

Hi,

It might be possible that your event.target is not in your array. Your movieclip might have children that are becoming event.target.

What happens when you trace event.currentTarget ?

Maybe try adding the handlers via the array

ActionScript Code:
for(var i:uint =0; i<_soloButtons.length; i++){            var soloButton:SoloButton = _soloButtons[i] as SoloButton;      soloButton.addEventListener(MouseEvent.CLICK, soloTrack);    //a for-each could also work  }

just a thought maybe....not sure if that would even help. You're right, it is late I'll just wait til the smarter guys give you a better answer...

-ADam
adaminaudio is offline   Reply With Quote
Old 03-23-2012, 09:14 AM   #4
daz1761
Senior Member
 
Join Date: Sep 2010
Posts: 165
Default

Thanks guys

I've tried some of your suggestions but no luck sadly, I don't understand as the other 2 trace statements are tracing ok. Even the e.target.soloONOFF, which is simple a boolean property. And I'm using the exact same process near enough in my other custom class I'm using and it works a treat.

The error is 1120: Access of undefined property _soloButtons?

Cheers
daz1761 is offline   Reply With Quote
Old 03-23-2012, 09:20 AM   #5
Poony
Senior Member
 
Poony's Avatar
 
Join Date: Aug 2011
Location: Sweden
Posts: 387
Default

An other approach would be to give all items a variable called e.g "myId".

And when you create the objects just assign it, also set mouseChildren to false to avoid any children becoming the e.target:
ActionScript Code:
_soloIndex.myId = i; _soloIndex.mouseChildren = false;

Then you would just trace
ActionScript Code:
e.target.myId

Hope it helps!
Poony is offline   Reply With Quote
Old 03-23-2012, 10:17 AM   #6
daz1761
Senior Member
 
Join Date: Sep 2010
Posts: 165
Default

This has escalated even further now...

I can't get anywhere near my array index for properties, I just keep getting 1120 access of undefined property of _muteButtons and _soloButtons!!

Also, I'm getting an error flashing up quickly saying migration error or something before the .swf file loads after adding gotoAndPlay???

This is what I'm trying to trace and change to test if the function is working:

Document class:

ActionScript Code:
_muteButtons = new Array();             var count2:uint = 4;             var _muteIndex:muteButton;             for (var ii:int = 0; ii < count2; ii++)             {                 _muteIndex = new muteButton();                 with (_muteIndex)                 {                     x = mutePosX;                     y = mutePosY;                     buttonMode = true;                     gotoAndStop("1"); //migration error                     addEventListener(MouseEvent.CLICK, muteTrack);                 }                 mutePosY = mutePosY + 34.9;                 _muteIndex.muteONOFF = muteONOFF;                 _muteButtons.push(_muteIndex);                 addChild(_muteIndex);             }             var _soloButtons:Array;             _soloButtons = new Array();             var count3:uint = 4;             var _soloIndex:soloButton;             for (var iii:int = 0; iii < count2; iii++)             {                 _soloIndex = new soloButton();                 with (_soloIndex)                 {                     x = soloPosX;                     y = soloPosY;                     buttonMode = true;                     gotoAndStop("start"); //migration error??                     addEventListener(MouseEvent.CLICK, soloTrack);                 }                 soloPosY = soloPosY + 34.9;                 _soloIndex.soloONOFF = soloONOFF;                 _soloButtons.push(_soloIndex);                 addChild(_soloIndex);             }         }         public function muteTrack(e:MouseEvent):void         {             if (e.target.muteONOFF == true)             {                 _muteButtons[0].trackVolume = 0; //doesnt work                 trace("mute");                 trace(e.target.muteONOFF);             }             else             {                 trace("no luck");             }         }         public function soloTrack(e:MouseEvent):void         {             trace("solo");             trace(e.target.soloONOFF);             trace(_soloButtons.indexOf(e.currentTarget)); //doesnt work         }     }

The buttons are MovieClip symbols to and they trace fine at the end of each for loop

ActionScript Code:
[object soloButton],[object soloButton] [object soloButton],[object soloButton],[object soloButton] [object soloButton],[object soloButton],[object soloButton],[object soloButton]

Last edited by daz1761; 03-23-2012 at 10:46 AM.
daz1761 is offline   Reply With Quote
Old 03-23-2012, 12:13 PM   #7
northmantif
dont Re Member
 
Join Date: May 2009
Location: Poland
Posts: 737
Default

did you declare your _soloButtons and _muteButtons array object outside constructor?Other way these two dies as fast as running code exits constructor's {} curly braces.
From provided piece of code your _soloButtons variable is a local variable which does exactly what I wrote above.
northmantif is offline   Reply With Quote
Old 03-23-2012, 01:38 PM   #8
daz1761
Senior Member
 
Join Date: Sep 2010
Posts: 165
Default

Hi, yes I've just realised I didn't declare them outside of the constructor grr stupid me

I'm still getting a wierd error flashing up quickly within the output window for my gotoAndStop methods? It's working but I don't like the fact that there is 2 errors popping up saying something about migration? Am I not quite directing the method to the right distination?

Thanks for spotting the obvious error

Here is my document class if it helps:

ActionScript Code:
package {     import flash.display.*;     import flash.events.*;     import fl.controls.*;     public class documentClass extends MovieClip     {         var _tracks:Array = new Array();         var _muteButtons:Array = new Array();         var _soloButtons:Array = new Array();         var _muteIndex:muteButton;         var _soloIndex:soloButton;         var muteONOFF:Boolean = true;         var soloONOFF:Boolean = true;         var count:uint = 4;         var count2:uint = 4;         var count3:uint = 4;         var PosY:uint = 10;         var comboY:uint = 30;         var volDownY:uint = 41;         var volUpY:uint = 38;         var panLeftY:uint = 30;         var panRightY:uint = 47;         var mutePosX:Number = 350;         var mutePosY:Number = 32;         var soloPosX:Number = 375;         var soloPosY:Number = 32;         public function documentClass()         {             // constructor code             trace("its working");             for (var i:int = 0; i < count; i++)             {                 var _trackIndex:_channelStrip = new _channelStrip(390,PosY,20,comboY,260,volDownY,277,volUpY,155,panLeftY,159,panRightY);                 PosY = PosY + 35;                 comboY = comboY + 35.2;                 volDownY = volDownY + 35;                 volUpY = volUpY + 35;                 panLeftY = panLeftY + 35;                 panRightY = panRightY + 35;                 _tracks.push(_trackIndex);                 addChild(_trackIndex);                 trace(_tracks);             }             for (var ii:int = 0; ii < count2; ii++)             {                 _muteIndex = new muteButton();                 with (_muteIndex)                 {                     x = mutePosX;                     y = mutePosY;                     buttonMode = true;                     gotoAndStop("1"); // Errors                     addEventListener(MouseEvent.CLICK, muteTrack);                 }                 mutePosY = mutePosY + 34.9;                 _muteIndex.muteONOFF = muteONOFF;                 _muteButtons.push(_muteIndex);                 addChild(_muteIndex);                 trace(_muteButtons);             }             for (var iii:int = 0; iii < count2; iii++)             {                 _soloIndex = new soloButton();                 with (_soloIndex)                 {                     x = soloPosX;                     y = soloPosY;                     buttonMode = true;                     gotoAndStop("start"); // Errors                     addEventListener(MouseEvent.CLICK, soloTrack);                 }                 soloPosY = soloPosY + 34.9;                 _soloIndex.soloONOFF = soloONOFF;                 _soloButtons.push(_soloIndex);                 addChild(_soloIndex);                 trace(_soloButtons);             }         }         public function muteTrack(e:MouseEvent)         {             if (e.target.muteONOFF == true)             {                 trace(_muteButtons.indexOf(e.target));                 trace("mute");                 trace(e.target.muteONOFF);             }             else             {                 trace("no luck");             }         }         public function soloTrack(e:MouseEvent)         {             trace("solo");             trace(e.target.soloONOFF);             //trace(_soloButtons.indexOf(e.target));         }     } }
daz1761 is offline   Reply With Quote
Old 03-23-2012, 07:55 PM   #9
northmantif
dont Re Member
 
Join Date: May 2009
Location: Poland
Posts: 737
Default

does gotoAndStop("1"); where "1" is a string name for the frame label or you rather want to gotoAndStop(1)... I just glimpsed at the code, so I can be wrong, just a thought...
northmantif is offline   Reply With Quote
Old 03-23-2012, 08:49 PM   #10
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

I would get rid of 'with'. That's one of those keyword that sounds awesome but turn out in many cases to be just plain evil. Never use it or be prepared for a whole lot of headaches.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:33 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.