why click does't work on target cpp

hello, I don't know why i could't click when i target my app to cpp, if i do that the app will display a error and then close by itself [b] class Main { static public function main() { var stage = Lib.current.stage; stage.scaleMode = S…

Viewing 1 to 19 (19 Total)
why click does't work on target cpp

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

hello, I don't know why i could't click when i target my app to cpp,
if i do that the app will display a error and then close by itself

class Main
{

static public function main()
{
var stage = Lib.current.stage;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
// entry point
stage.addEventListener(KeyboardEvent.KEY_DOWN, ControlManager.getIns().keyDownProcessor);
stage.addEventListener(MouseEvent.CLICK, ControlManager.getIns().keyDownProcessor);
}

}

/**
* å¤çKeyDown
*
* @param e
*/
public function keyDownProcessor(e:KeyboardEvent):Void {
switch (e.keyCode) {
case KeyCode.LEFT: trace("fuck");
}
trace(Lib.getTimer());
trace("fuck");
}


these is the main code
please help me thxsmiling

Tags:
Posted on June 08, 2012 at 12:16 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

Does this work for you?

import nme.events.MouseEvent;
import nme.Lib;

class Main {

public function new () {

Lib.current.stage.addEventListener (MouseEvent.MOUSE_DOWN, stage_onMouseDown);

}

private function stage_onMouseDown (event:MouseEvent):Void {

trace ("It works!");

}

}

Posted on June 08, 2012 at 1:40 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

I'm sorry
I had test it
it works well in target flash
but it doesn't work in cpp
in cpp: when I click the app's main window nothing has display ....is this a bug?

Posted on June 08, 2012 at 9:00 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

It's possible that you aren't seeing trace messages.

How about this?

import nme.events.MouseEvent;
import nme.Lib;

class Main {

public function new () {

Lib.current.stage.addEventListener (MouseEvent.MOUSE_DOWN, stage_onMouseDown);

}

private function stage_onMouseDown (event:MouseEvent):Void {

graphics.beginFill (0xFF0000);
graphics.drawRect (0, 0, 100, 100);

}

}

Posted on June 08, 2012 at 9:02 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

sorry the code may be:
Lib.current.graphics.beginFill (0xFF0000);
Lib.current.graphics.drawRect (0, 0, 100, 100);
and it also work on cpp
may the bug is trace message can't display on cpp
also I don't know why when I move the mouse in cpp app's main window
the mouse still flicker then if I stop the mouse the mouse will become disappear

Posted on June 08, 2012 at 9:13 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

What operating system and version are you using?

Posted on June 08, 2012 at 9:15 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

winXP sp2
I'm sorry I now had a new problem : I don't know why the filed named "keyCode" of nme.event.KeyboardEvent return a UInt which doesn't same as the nme api said return a Int when i target to flash
so if i want target to flash it must be a UInt
if target to cpp it is Int
it's so strange.....

Posted on June 08, 2012 at 9:35 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

sorry it's sp3

Posted on June 08, 2012 at 9:37 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

If you treat them both like they are an Int, I think you should be fine.

Flash has both Int and UInt types, just how it is designed. NME (and Haxe) do not change the behavior of Flash Player in this sense. When you are running on the Flash target, "nme event.KeyboardEvent" is actually "flash.event.KeyboardEvent"

Most of Haxe's targets do not include a UInt type, either for efficiency, simplicity, or because the target language does not support it.

Posted on June 08, 2012 at 9:38 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

so now if i want compare nme.event.KeyboardEvent.keyCode.A with MyKeyCode.A
then when I target to flash i must change MyKeyCode.A's type to UInt
then when I target to flash I must change it to Int
right?

Posted on June 08, 2012 at 9:50 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

I'm not sure why you would do that?

Wouldn't you usually want to do something like...

if (event.keyCode == 27) {

...or...

if (event.keyCode == nme.ui.Keyboard.A) {

?

Posted on June 08, 2012 at 9:59 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

well when I use nme.ui.Keyboard.Z the FlashDevelop IDE report an error:
"Accessing this field require flash version 10.1 (use -swf-version 10.1)"
but I don't know how to change the set to target to 10.1flash in FD
oh i'm so stupidsmiling

Posted on June 08, 2012 at 10:07 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

Oh, okay.

I apologize for the trouble! Perhaps we'll bump up the default Flash Player version, now that Flash 10.1 has increased in users.

Open your NMML file, and add this:

<app swf-version="10.1" />

Also, if you haven't seen it already, the "Pirate Pig" sample may be useful for you, as well as the "KeyBinding" library:

http://www.joshuagranick.com/blog/2012/04/12/html5-pirate-pig-sampl...
http://gist.github.com/1830627

Posted on June 08, 2012 at 10:11 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

ok thxsmiling
but......
sorry I don't know why i had a new problem now.........
the Keyboard.UP is work but Keyboard.Z is not......
class Main
{
public function new () {

Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
//Lib.current.stage.addEventListener (KeyboardEvent.KEY_DOWN, ControlManager.getIns().keyDownProcessor);
//Lib.current.stage.addEventListener (KeyboardEvent.KEY_UP, ControlManager.getIns().keyUpProcessor);
}

static public function main()
{
new Main();
}

private function stage_onKeyDown (event:KeyboardEvent):Void {
if (event.keyCode == Keyboard.UP) {
Lib.current.graphics.beginFill (0xFF0000);
Lib.current.graphics.drawRect (0, 0, 100, 100);
}
}
}

when I target it to cpp it worked but if i change the Keyboard.UP to Z it doesn't (also X,V ,A and so on is....)

Posted on June 08, 2012 at 10:28 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

the Keyboard.Z worked well on flash but not cpp

Posted on June 08, 2012 at 10:33 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

Okay, I'll look into seeing if that's something we can fix. I bet it might have something to do with keyboard layouts, since the numbers might be hard-coded for a standard English keyboard layout.

I just looked up what I was using in the KeyBinding library to get key codes. Perhaps this will help?

public static function getKeyCode (key:String):Int {

#if (cpp || neko)

return key.toLowerCase ().charCodeAt (0);

#else

return key.toUpperCase ().charCodeAt (0);

#end

}


You could use it like this:

if (event.keyCode == getKeyCode ("A")) {

Posted on June 08, 2012 at 10:41 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

ok... but what I really want is you can fix the bug if u are free
oh I really like nme and i want it to be strong and i want to make my game with it too.....

Posted on June 08, 2012 at 10:57 PM

wdl7770016

wdl7770016
Total Posts: 34
Joined: May 20, 2012

Re: why click does't work on target cpp

hello now i had use the getKeyCode(key:String):Int to work but the problem is still exist
the getKeyCode return an Int but I could compare it with KeyboardEvent.keyCode when i target on flash
which i had talked before:
and your answer is

Wouldn't you usually want to do something like...

if (event.keyCode == 27) {

...or...

if (event.keyCode == nme.ui.Keyboard.A) {

?

but now first solution is hardcode... and the later is down work well
so when i target to cpp or flash may different
...

Posted on June 09, 2012 at 12:33 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: why click does't work on target cpp

Maybe you could just use something like this for now, so you can move forward past key codes ;)

#if flash
var keyCode:UInt;
#else
var keyCode:Int;
#end

Posted on June 09, 2012 at 12:44 AM