You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Hugo Ferreira <hf...@gmail.com> on 2020/10/04 23:37:51 UTC

Externs JS call Royale/AS

Hi,

Using externs, it's possible to call JS functions from Royale/AS code
(Royale AS > JS).
However I need now the oposite (JS > Royale AS).
This JS libraries that I'm using have events that I need to send to to
Royale/AS level (save data for example).

Is this currently possible ?

Re: Externs JS call Royale/AS

Posted by Hugo Ferreira <hf...@gmail.com>.
Hi Carlos,

Solved.
Thank you.

Carlos Rovira <ca...@apache.org> escreveu no dia segunda, 5/10/2020
à(s) 09:11:

> Hi Hugo,
>
> of course. Take into account that you can always go low level with
> COMPILE::JS
> for example check Jewel TextInput.as
>
> in TextInputBase.as we have:
>
> COMPILE::JS
> public function get input():HTMLInputElement
>
> then in TextInput.as
>
> COMPILE::JS
> override protected function createElement():WrappedHTMLElement
> {
> input = addElementToWrapper(this,'input') as HTMLInputElement;
>
> ...
>
> //attach input handler to dispatch royale change event when user write in
> textinput
> input.addEventListener("input", textChangeHandler)
> input.addEventListener("keypress", enterEventHandler, true);
>
> then in the AS3 handler we are dispatching an AS3 event.
>
> protected function textChangeHandler(event:Event):void
> {
> ...
> dispatchEvent(new Event(Event.CHANGE));
> }
>
> or you could again dispatch a JS event at that point
>
> You should try to always abstract it in AS3 when possible so users of your
> library have complete control from AS3 (Royale).
>
> El lun., 5 oct. 2020 a las 1:38, Hugo Ferreira (<hf...@gmail.com>)
> escribió:
>
> > Hi,
> >
> > Using externs, it's possible to call JS functions from Royale/AS code
> > (Royale AS > JS).
> > However I need now the oposite (JS > Royale AS).
> > This JS libraries that I'm using have events that I need to send to to
> > Royale/AS level (save data for example).
> >
> > Is this currently possible ?
> >
>
>
> --
> Carlos Rovira
> http://about.me/carlosrovira
>

Re: Externs JS call Royale/AS

Posted by Carlos Rovira <ca...@apache.org>.
Hi Hugo,

of course. Take into account that you can always go low level with
COMPILE::JS
for example check Jewel TextInput.as

in TextInputBase.as we have:

COMPILE::JS
public function get input():HTMLInputElement

then in TextInput.as

COMPILE::JS
override protected function createElement():WrappedHTMLElement
{
input = addElementToWrapper(this,'input') as HTMLInputElement;

...

//attach input handler to dispatch royale change event when user write in
textinput
input.addEventListener("input", textChangeHandler)
input.addEventListener("keypress", enterEventHandler, true);

then in the AS3 handler we are dispatching an AS3 event.

protected function textChangeHandler(event:Event):void
{
...
dispatchEvent(new Event(Event.CHANGE));
}

or you could again dispatch a JS event at that point

You should try to always abstract it in AS3 when possible so users of your
library have complete control from AS3 (Royale).

El lun., 5 oct. 2020 a las 1:38, Hugo Ferreira (<hf...@gmail.com>)
escribió:

> Hi,
>
> Using externs, it's possible to call JS functions from Royale/AS code
> (Royale AS > JS).
> However I need now the oposite (JS > Royale AS).
> This JS libraries that I'm using have events that I need to send to to
> Royale/AS level (save data for example).
>
> Is this currently possible ?
>


-- 
Carlos Rovira
http://about.me/carlosrovira