AS3: using button script functions
- Started
- Last post
- 10 Responses
- CyBrainX
I have a button function for click. I'd like to also use it as a normal function aside from when the target object is clicked.
Here's a sample of the relevant code. My quandry begins on line 16. I'd like to test if any of the objects in my array are already enlarged and reduce them if they are.
I could rewrite the same function but I'm sure there's a better practice way of doing it. I've done this before by changing reduce(e:MouseEvent) to reduce(e:Event) but I don't remember what else I did.
Thanks in advance.
- CyBrainX0
Sorry, forgot to post the link to the code. http://pastebin.com/4eZXDCYn
- I love that BrainFuck is a code formatting option on this site.CyBrainX
- CyBrainX0
Memory has returned. You can pass null as an event.
reduce(null);
to call the function
function reduce(e:Event):void {
}
but I'll have to do work some boolean jiggery-pokery in the function to replace the e.target references.
- Aa770
you are running the 'reduce' function as if it was triggered by an event.
Instead, you want to pass a reference to the image_array[i] value inside the parenthesis instead...so line 27 should be more like this:
function reduce(reference:Object):void {
- PonyBoy0
use the same function - just pass a boolean to it verifying if the button was clicked and add an 'if()' statement to the function that is triggered only if that boolean is true
- rounce0
As you can tell from my previous post, I'm fucking retarded.
- rounce0
http://pastebin.com/87QTD2BA - I saw scope issues in your future.
- NONEIS0
You should also avoid adding and removing listeners the way you are in reduce as much as humanly possible...
- rounce0
Event handlers really shouldn't be doing any real execution logic, only redirecting calls to the appropriate functions. Mine was pretty dirty and should've been split into about 2 or 3 more.