Heartbroken / flash-to-directx

Automatically exported from code.google.com/p/flash-to-directx
0 stars 0 forks source link

Problems with callback functions #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I may be misunderstanding the usage of the Call and Callback functions, but 
they don't seem to be working correctly.

My main concern is the callbacks, considering I need them to react to 
button presses in the flash app. I have a function AS3 in the .swf file 
called onMouseClick and I attempted to attached a callback to it like so 
ASInterface::AddCallback(L"onMouseClick", &GUIHandler::OnMouseClick); 

I had visual output proving that the button was being pressed and the 
function I was seeking to bind to was being called, but my callback 
function was never triggered. 

I could get around the callbacks if I could get a hold of ActionScript 
variables, but the IFlashDXPlayer functions GetVariable and SetVariable 
don't seem to work in the way I thought. I have an AS3 variable called 
"counter." If I call IFlashDXPlayer::GetVariable(L"counter"), I get an 
unhandled exception. If I perform SetVariable first, then GetVariable 
returns the value I just set it to, but my AS3 variable remains unchanged.

My last problem was with the ASInterface::Call function. I debugged it 
during my own tests and in the "Function call example" within GUI.cpp and 
this function: "m_flashInterface->raw_CallFunction(_bstr_t(request), 
&response)" always returns E_FAIL.

If you can give me some guidance on these issues, I may be able to resolve 
them myself. I just don't have the background interfacing with Flash to 
know where to start.

Original issue reported on code.google.com by roytu...@gmail.com on 3 Apr 2010 at 10:01

GoogleCodeExporter commented 9 years ago
Callbacks are set on function call made from AS3, like:
C++ ->

  m_flashInterface->AddCallback(L"SteamRelease", *this, &CSteamGame::SteamRelease);

AS3 ->

  SteamReleaseControlButton.addEventListener(MouseEvent.MOUSE_DOWN, SteamMouseEventDown);
  SteamReleaseControlButton.addEventListener(MouseEvent.MOUSE_UP, SteamMouseEventUp);
  function SteamMouseEventDown(event:MouseEvent) : void
  {
    ExternalInterface.call("SteamRelease", true);
  }

  function SteamMouseEventUp(event:MouseEvent) : void
  {
    ExternalInterface.call("SteamRelease", false);
  }

Original comment by max.dyac...@gmail.com on 23 Apr 2010 at 3:49

GoogleCodeExporter commented 9 years ago
For variables it looks like you are trying to Get() variable in different 
context.
That's why Set() before Get() works for you. You need to ask some AS3 guru 
about this.

Original comment by max.dyac...@gmail.com on 23 Apr 2010 at 3:52

GoogleCodeExporter commented 9 years ago
Calls works for me like:
C++ ->

  m_flashInterface->Call(L"SetPowerIndicator", (f32)m_locoControl->GetUIPower());

AS3 ->

  function SetPowerIndicator(power : Number) : void
  {
    PowerLevel.y = PowerLevelControlButton.y + (1 - power) *
PowerLevelControlButton.height;
  }
  ExternalInterface.addCallback("SetPowerIndicator", SetPowerIndicator);

Original comment by max.dyac...@gmail.com on 23 Apr 2010 at 3:54

GoogleCodeExporter commented 9 years ago
Sorry for late replies, for some reason defects editing doesn't provide me with
e-mail notification. =)

Original comment by max.dyac...@gmail.com on 23 Apr 2010 at 3:55

GoogleCodeExporter commented 9 years ago
Ok, so I've fixed e-mail notifications by now.

Original comment by max.dyac...@gmail.com on 23 Apr 2010 at 3:59