[GitHub] hcsuk commented on issue #325: Adding support for ExternalInterface

2018-10-25 Thread GitBox
hcsuk commented on issue #325: Adding support for ExternalInterface
URL: https://github.com/apache/royale-asjs/pull/325#issuecomment-433143444
 
 
   Thanks - so I will update this to define it as mx.core.ExternalInterface; I 
might try looking into the @externs thing although there are a few more 
pressing issues to sort out still!
   
   Yes I agree it's better practise to have your JavaScript functionality 
encapsulated into 'packages'. And it's feasible to create this sort of wrapper 
between ActionScript and JavaScript without too much hassle.. probably a wiki 
entry on this might be useful..!
   
   I guess in the meantime, this pull request can be closed/ignored..
   Thanks


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] hcsuk commented on issue #325: Adding support for ExternalInterface

2018-10-25 Thread GitBox
hcsuk commented on issue #325: Adding support for ExternalInterface
URL: https://github.com/apache/royale-asjs/pull/325#issuecomment-433014968
 
 
   Hmmm. Tagging a class as @externs has its own issues. Firstly the transpiler 
still generates the functionality into the js-debug folder, it just puts the 
@externs tag at the top of the file. So this means we have empty functions 
causing confusion when trying to debug (and I had a 'trace' statement in my 
function which really caused some issues due to the results goog.require 
call...). Secondly however, this is causing a problem in the release builds, as 
there isn't a "goog.provide" call, so the class that's importing this then 
faces an issue.
   
   This looks like it's the same with the barcode scanner that you pointed me 
at; I've copied that into my own simple project. The js-debug version compiles 
- and leaves me with an empty function for the 'scan' method - but when I ask 
for a release build, I then get this closure compiler error. I noticed that the 
build.xml file for this component has got "-debug" hardcoded into it so perhaps 
this hasn't been tried before (or it was 2 years ago..?)
   
   So I have a kind of solution which is a bit simpler than having to do the 
whole ExternalInterface class definition, although it borrows a bit from this 
in terms of the callback.. 
   
   If we define our API in a normal class (i.e. forgetting about @externs) and 
add the glue directly in here to call our JavaScript functions:
   `public static function addNumbers(a:int,b:int):int { return 
window["addNumbers"](a,b); } `
   then we can call out using this e.g. if the class was called "extAPI" then 
we call
   `val result : int = extAPI.addNumbers(3, 4);`
   
   To get a callback working, we need to define an extra function in our extAPI 
class:
   `public static function registerCallback(fncName : String, methodClosure : 
Function) : void
   { extAPI[fncName] = methodClosure; }`
   and this we then set up from our ActionScript:
   `extAPI.registerCallback("myFunction", runCallback);`
   and our external JavaScript can call it simply with:
   `extAPI.myFunction("999");`
   
   So that all works and perhaps is an alternative to needing the 
ExternalInterface class. Although I still think it might be worth having this 
in the RoyaleMX package perhaps, to aid in migration..!
   
   Let me know what you think.
   Thanks


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] hcsuk commented on issue #325: Adding support for ExternalInterface

2018-10-25 Thread GitBox
hcsuk commented on issue #325: Adding support for ExternalInterface
URL: https://github.com/apache/royale-asjs/pull/325#issuecomment-432967118
 
 
   One quick comment having looked at the barcode scanner example: the 
"@externs" tag is on the class comment. It looks like (from 
PackageHeaderEmitter.java) the tag is only checked for classes and interfaces; 
I'm looking at a top-level package with just a function inside it. Might see if 
I can fool it by also defining an empty class... otherwise I'm looking at the 
compiler code to see if it could also check package-level comments/markup for 
this.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] hcsuk commented on issue #325: Adding support for ExternalInterface

2018-10-25 Thread GitBox
hcsuk commented on issue #325: Adding support for ExternalInterface
URL: https://github.com/apache/royale-asjs/pull/325#issuecomment-432966030
 
 
   Great, thanks for those ... will take a look and update here when I've got 
this working...


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] hcsuk commented on issue #325: Adding support for ExternalInterface

2018-10-25 Thread GitBox
hcsuk commented on issue #325: Adding support for ExternalInterface
URL: https://github.com/apache/royale-asjs/pull/325#issuecomment-432929781
 
 
   The idea of defining the API in ActionScript and keeping the type 
information sounds good.
   I couldn't see any examples of using @externs in ActionScript anywhere, the 
only thing I could see is a file-level directive within some JavaScript files. 
I've been trying to get this to work with an AS file but if it's at file scope, 
it just gets ignored, and if I add it to a function then I get a closure 
compiler internal error. I'm assuming that this is actually the Royale 
transpiler that should be removing the function definition when transpiling, so 
presumably it shouldn't actually create a .js file for it?
   
   I'm slightly unclear how to get the external JavaScript code to call a 
method within the Royale application still; we would still need to register a 
callback somehow I guess, or else we'd just have to call the qualified function 
but without any 'this' parameter. To keep it working with a method closure I 
believe the "registering a callback" approach is required so we need to define 
a function somewhere for this - perhaps this then needs to be added to the AS 
externs code (but without the @extern tag..)
   
   Presumably all of this approach works just for when we compile our apps into 
JavaScript/HTML, and the application becomes responsible for the compile-switch 
between JS and SWF and then continues to use flash.external.ExternalInterface 
in a COMPILE::SWF block...
   
   thanks


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services