00:00
00:00
Newgrounds Background Image Theme

TheADHX just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS3 help please 2013-04-26 14:50:24


var options:Array = [[Option1, New, true], [Option2, Load, false], [Option3, Exit, true]]

addEventListener(MouseEvent.MOUSE_OVER, MouseHandler)
addEventListener(MouseEvent.MOUSE_OUT, MouseHandler)
addEventListener(MouseEvent.CLICK, MouseHandler)

private function MouseHandler(e:MouseEvent) {
			if (e.target == Check()[0] && Check()[2]) {
				if (e.type == MouseEvent.MOUSE_OVER) {e.target.filters = null}
				if (e.type == MouseEvent.MOUSE_OUT) {e.target.filters = [filter]}
				if (e.type == MouseEvent.CLICK) {Check()[1]()}
			}
			
			function Check() {for(var i:int = 0; i < options.length; i++) {if (e.target == options[i][0]) {return options[i]}}}
		}

I get the error
"TypeError: Error #1010: A term is undefined and has no properties.
at Menus::MainM/MouseHandler()"
whenever one of the 3 eventslistener's events are dispatched

and when I replace "e.target == Check()[0]" with "(e.target == Option1 || e.target == Option2 || e.target == Option3)" I don't get the error.

Response to AS3 help please 2013-04-26 14:52:03


After all the debugging I did I came to a conslucion that the problem is exactly with "e.target == Check()[0]", anyone has an idea why is that?

Response to AS3 help please 2013-04-26 15:08:10


At 4/26/13 02:52 PM, NecroBlight wrote: After all the debugging I did I came to a conslucion that the problem is exactly with "e.target == Check()[0]", anyone has an idea why is that?

Type your functions. Tell the code that the function returns an array. Also, you should make a new class to hold the information you're sticking in that array to organize it. 2D arrays are pretty bad unless you're doing tile-based stuff.

Response to AS3 help please 2013-04-26 15:19:55


At 4/26/13 03:08 PM, MSGhero wrote:
At 4/26/13 02:52 PM, NecroBlight wrote: After all the debugging I did I came to a conslucion that the problem is exactly with "e.target == Check()[0]", anyone has an idea why is that?
Type your functions. Tell the code that the function returns an array. Also, you should make a new class to hold the information you're sticking in that array to organize it. 2D arrays are pretty bad unless you're doing tile-based stuff.

Can't do that, the function is void, it only returns a value when the conditions are met. and its only 1 small array, wouldn't make sense to create a whole class just for that array. and why 2D arrays are bad? is there a better alternative?

Response to AS3 help please 2013-04-26 15:49:47


At 4/26/13 03:19 PM, NecroBlight wrote: Can't do that, the function is void, it only returns a value when the conditions are met. and its only 1 small array, wouldn't make sense to create a whole class just for that array. and why 2D arrays are bad? is there a better alternative?

Yes you can, just return null otherwise. You can't have a void function that returns something; you have it as a wildcard function, basically saying you don't know what it'll do.

It's more organized if you made a class and didn't use a 1D array. You have 3 random values inside each array element instead of only ints or only strings or something that makes sense. It's purely from an organizational point of view (slightly performance), but it just looks nicer and makes more sense with an array of 1 class.

Response to AS3 help please 2013-04-26 16:02:41


At 4/26/13 03:49 PM, MSGhero wrote:
Yes you can, just return null otherwise. You can't have a void function that returns something; you have it as a wildcard function, basically saying you don't know what it'll do.

Well, tried it, but as I thought, it didn't work. still gives the same error,

Response to AS3 help please 2013-04-26 16:41:24


Also I can add that with the code that gives the error it still works exactly as intended, so I really can't see the cause of the error.

Response to AS3 help please 2013-04-26 17:18:59


Maybe e.target does not match any of your Options, then Check() wouldn't return an array and Check()[0] would give you an error.


You forgot to use code tags, didn't you?

Response to AS3 help please 2013-04-26 17:26:59


At 4/26/13 05:18 PM, theCodeCat wrote: Maybe e.target does not match any of your Options, then Check() wouldn't return an array and Check()[0] would give you an error.

Maybe, try e.currentTarget instead.

Response to AS3 help please 2013-04-26 17:44:48


At 4/26/13 05:18 PM, theCodeCat wrote: Maybe e.target does not match any of your Options, then Check() wouldn't return an array and Check()[0] would give you an error.

damn, why didn't I think of that, thanks for the tip, fixed the problem.