How to send an argument from a MouseEventManager

23 views
Skip to first unread message

JustGabe

unread,
Dec 13, 2015, 7:43:53 AM12/13/15
to HaxeFlixel
Basically I have 5 command buttons, and instead of making 5 separate functions, I want to know how to send an Int to that function. If i try it this way it will send me this error:
source/BattleMenu.hx:34: characters 44-74 : Void should be Null<flixel.FlxSprite -> Void>
source/BattleMenu.hx:34: characters 44-74 : Void should be flixel.FlxSprite -> Void
source/BattleMenu.hx:34: characters 44-74 : For optional function argument 'OnMouseUp'

MouseEventManager.add(skillsButton, null, mouseReleased(skillsButton, 2), onMouseOver, onMouseOut);

 private function mouseReleased(Sprite:FlxSprite, command:Int):Void
 
{
 
Testing01.menuClicked = true;
 
switch(command)
 
{
 
case 0: trace(command + " button clicked");
 
case 1: trace(command + " button clicked");
 
case 2: trace(command + " button clicked");
 
case 3: trace(command + " button clicked");
 
case 4: trace(command + " button clicked");
 
}
 
}

Ashiq A.

unread,
Dec 13, 2015, 8:39:27 AM12/13/15
to haxef...@googlegroups.com
I never figured out a way to do this. I ended up using the sprite as the input parameter (and changing the action based on which sprite it was).

Not a great solution, albeit a functional one.

Alternatively, you can probably add additional mouse-down/mouse-up events and set your parameters there.

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to the Google Groups "HaxeFlixel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxeflixel+...@googlegroups.com.
Visit this group at https://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/06d433fd-71a1-49e4-9745-1699c1eb4dff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dlean Jeans

unread,
Dec 13, 2015, 10:14:43 AM12/13/15
to HaxeFlixel
Try to replace the first parameter `Sprite:FlxSprite` to a parameter of a button: `button:YourButtonType` and try to read the button text (only work if your buttons have different text) or try to add a property `name:String` to the button class and give those buttons different name.

function mouseReleased(button:YourButtonType) {
if (button.text = "Level 1")
startLevel1
();
else if (button.text == "Level 2")
startLevel2
();
}

Gama11

unread,
Dec 13, 2015, 10:15:00 AM12/13/15
to HaxeFlixel
Use Function Binding:

MouseEventManager.add(skillsButton, null, mouseReleased.bind(_, 2), onMouseOver, onMouseOut);

On Sunday, December 13, 2015 at 2:39:27 PM UTC+1, Ashiq A. wrote:
I never figured out a way to do this. I ended up using the sprite as the input parameter (and changing the action based on which sprite it was).

Not a great solution, albeit a functional one.

Alternatively, you can probably add additional mouse-down/mouse-up events and set your parameters there.
On Sun, Dec 13, 2015 at 7:43 AM, JustGabe <gabrie...@gmail.com> wrote:
Basically I have 5 command buttons, and instead of making 5 separate functions, I want to know how to send an Int to that function. If i try it this way it will send me this error:
source/BattleMenu.hx:34: characters 44-74 : Void should be Null<flixel.FlxSprite -> Void>
source/BattleMenu.hx:34: characters 44-74 : Void should be flixel.FlxSprite -> Void
source/BattleMenu.hx:34: characters 44-74 : For optional function argument 'OnMouseUp'

MouseEventManager.add(skillsButton, null, mouseReleased(skillsButton, 2), onMouseOver, onMouseOut);

 private function mouseReleased(Sprite:FlxSprite, command:Int):Void
 
{
 
Testing01.menuClicked = true;
 
switch(command)
 
{
 
case 0: trace(command + " button clicked");
 
case 1: trace(command + " button clicked");
 
case 2: trace(command + " button clicked");
 
case 3: trace(command + " button clicked");
 
case 4: trace(command + " button clicked");
 
}
 
}

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to the Google Groups "HaxeFlixel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxeflixel+unsubscribe@googlegroups.com.

JustGabe

unread,
Dec 13, 2015, 4:37:28 PM12/13/15
to HaxeFlixel
Thank you Gama11! It worked!
Reply all
Reply to author
Forward
0 new messages