You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Carlos Rovira <ca...@apache.org> on 2017/01/19 12:01:22 UTC

[FlexJS] How to call external JS function from AS3 class (and first make it compile)

Hi,

while we already need to solve how to make dialog polyfill work, I found a
new problem that hope you guys have already managed.

I need to put the following lines in my Dialog MDL component:

if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}

I have dialog var in my AS3 so this is ok, but I don't have
"dialogPolyfill" var
So the question is...how make FlexJS aware of "dialogPolyfil" that is setup
by the JS loaded as an external resource so I can compile my AS3 class and
make it work in the browser?


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

Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Josh Tynjala <jo...@gmail.com>.
The use case is that you want to get something up and running quickly that
the compiler won't complain about, even if there's no type-checking. If I
were to do something like this in one of my own projects, it would be
temporary so that I could focus on something else first, and I'd come back
and flesh things out later.

Another use case I should think is obvious: there's an actual global
variable or function loaded from a <script> tag or something that you want
to use in ActionScript:

package
{
    /**
     * @externs
     */
    public function globalFunction(param1:String, param2:Number):Boolean {}
}

- Josh

On Thu, Jan 19, 2017 at 1:23 PM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 1/19/17, 10:27 AM, "Josh Tynjala" <jo...@gmail.com> wrote:
>
> >Is it only supported on classes? Is it possible to add it to variables or
> >functions in packages too? As an example, I think something like this will
> >be a common quick-and-dirty workaround for accessing JS globals.
> >
> >package
> >{
> >    /**
> >     * @externs
> >     */
> >    public var myGlobal:Object;
> >}
>
> I didn't test it on anything other than a class.   Feel free to try it and
> maybe even fix it if it doesn't work.
>
> I'm not sure I understand this particular use case though.  If you are
> accessing a third-party library, usually there is more than just a global
> object in the APIs.  Are you just trying to prevent renaming on something?
>
> -Alex
>
>

Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Alex Harui <ah...@adobe.com>.

On 1/19/17, 10:27 AM, "Josh Tynjala" <jo...@gmail.com> wrote:

>Is it only supported on classes? Is it possible to add it to variables or
>functions in packages too? As an example, I think something like this will
>be a common quick-and-dirty workaround for accessing JS globals.
>
>package
>{
>    /**
>     * @externs
>     */
>    public var myGlobal:Object;
>}

I didn't test it on anything other than a class.   Feel free to try it and
maybe even fix it if it doesn't work.

I'm not sure I understand this particular use case though.  If you are
accessing a third-party library, usually there is more than just a global
object in the APIs.  Are you just trying to prevent renaming on something?

-Alex


Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Josh Tynjala <jo...@gmail.com>.
Is it only supported on classes? Is it possible to add it to variables or
functions in packages too? As an example, I think something like this will
be a common quick-and-dirty workaround for accessing JS globals.

package
{
    /**
     * @externs
     */
    public var myGlobal:Object;
}

- Josh

On Thu, Jan 19, 2017 at 10:20 AM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 1/19/17, 9:53 AM, "carlos.rovira@gmail.com on behalf of Carlos Rovira"
> <carlos.rovira@gmail.com on behalf of carlos.rovira@codeoscopic.com>
> wrote:
>
> >Thanks for the various responses. Very helpful! :)
> >
> >I'm just downloading Alex changes, so, If I understand ok with that
> >changes, the way to use dialog polyfill from MDL swc should be to add in
> >Dialog.as something like:
> >
> >@extern
> >var dialogPolyfill;
> >
> >as other var? maybe with public?
>
> Unfortunately, there is more to it than that.  The @extern goes on a
> class.  I pushed examples to the flex-tourjs repo and am in the process of
> writing up a blurb on it.
>
> -Alex
>
>

Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Alex Harui <ah...@adobe.com>.

On 1/19/17, 9:53 AM, "carlos.rovira@gmail.com on behalf of Carlos Rovira"
<carlos.rovira@gmail.com on behalf of carlos.rovira@codeoscopic.com> wrote:

>Thanks for the various responses. Very helpful! :)
>
>I'm just downloading Alex changes, so, If I understand ok with that
>changes, the way to use dialog polyfill from MDL swc should be to add in
>Dialog.as something like:
>
>@extern
>var dialogPolyfill;
>
>as other var? maybe with public?

Unfortunately, there is more to it than that.  The @extern goes on a
class.  I pushed examples to the flex-tourjs repo and am in the process of
writing up a blurb on it.

-Alex


Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Carlos Rovira <ca...@codeoscopic.com>.
Thanks for the various responses. Very helpful! :)

I'm just downloading Alex changes, so, If I understand ok with that
changes, the way to use dialog polyfill from MDL swc should be to add in
Dialog.as something like:

@extern
var dialogPolyfill;

as other var? maybe with public?

Thanks!



2017-01-19 17:20 GMT+01:00 Josh Tynjala <jo...@gmail.com>:

> Looking forward to it, Alex. If people can write them in ActionScript
> directly instead of converting Closure externs or TypeScript definitions,
> that's going to be way easier!
>
> - Josh
>
> On Thu, Jan 19, 2017 at 8:14 AM, Alex Harui <ah...@adobe.com> wrote:
>
> > And you could cheat a little bit and add it to missing.js in
> > flex-typedefs/js if you don't want to bother setting up a whole new
> > typedef SWC.
> >
> > BTW, I will be checking in changes to Falcon that make it really easy to
> > use AS to generate typedefs.
> >
> > -Alex
> >
> > On 1/19/17, 7:33 AM, "Josh Tynjala" <jo...@gmail.com> wrote:
> >
> > >If you don't mind the string property reference, that would be the
> easiest
> > >way to access it. :)
> > >
> > >- Josh
> > >
> > >On Thu, Jan 19, 2017 at 7:21 AM, Harbs <ha...@gmail.com> wrote:
> > >
> > >> window[“dialogPolyfill”].registerDialog(dialog) should do it.
> > >>
> > >> > On Jan 19, 2017, at 2:01 PM, Carlos Rovira <carlosrovira@apache.org
> >
> > >> wrote:
> > >> >
> > >> > Hi,
> > >> >
> > >> > while we already need to solve how to make dialog polyfill work, I
> > >>found
> > >> a
> > >> > new problem that hope you guys have already managed.
> > >> >
> > >> > I need to put the following lines in my Dialog MDL component:
> > >> >
> > >> > if (! dialog.showModal) {
> > >> > dialogPolyfill.registerDialog(dialog);
> > >> > }
> > >> >
> > >> > I have dialog var in my AS3 so this is ok, but I don't have
> > >> > "dialogPolyfill" var
> > >> > So the question is...how make FlexJS aware of "dialogPolyfil" that
> is
> > >> setup
> > >> > by the JS loaded as an external resource so I can compile my AS3
> class
> > >> and
> > >> > make it work in the browser?
> > >> >
> > >> >
> > >> > --
> > >> > Carlos Rovira
> > >> > http://about.me/carlosrovira
> > >>
> > >>
> >
> >
>



-- 

Carlos Rovira
Director General
M: +34 607 22 60 05
http://www.codeoscopic.com
http://www.avant2.es

Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si ha recibido este mensaje por
error, le rogamos que nos lo comunique inmediatamente por esta misma vía y
proceda a su destrucción.

De la vigente Ley Orgánica de Protección de Datos (15/1999), le comunicamos
que sus datos forman parte de un fichero cuyo responsable es CODEOSCOPIC
S.A. La finalidad de dicho tratamiento es facilitar la prestación del
servicio o información solicitados, teniendo usted derecho de acceso,
rectificación, cancelación y oposición de sus datos dirigiéndose a nuestras
oficinas c/ Paseo de la Habana 9-11, 28036, Madrid con la documentación
necesaria.

Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Josh Tynjala <jo...@gmail.com>.
Looking forward to it, Alex. If people can write them in ActionScript
directly instead of converting Closure externs or TypeScript definitions,
that's going to be way easier!

- Josh

On Thu, Jan 19, 2017 at 8:14 AM, Alex Harui <ah...@adobe.com> wrote:

> And you could cheat a little bit and add it to missing.js in
> flex-typedefs/js if you don't want to bother setting up a whole new
> typedef SWC.
>
> BTW, I will be checking in changes to Falcon that make it really easy to
> use AS to generate typedefs.
>
> -Alex
>
> On 1/19/17, 7:33 AM, "Josh Tynjala" <jo...@gmail.com> wrote:
>
> >If you don't mind the string property reference, that would be the easiest
> >way to access it. :)
> >
> >- Josh
> >
> >On Thu, Jan 19, 2017 at 7:21 AM, Harbs <ha...@gmail.com> wrote:
> >
> >> window[“dialogPolyfill”].registerDialog(dialog) should do it.
> >>
> >> > On Jan 19, 2017, at 2:01 PM, Carlos Rovira <ca...@apache.org>
> >> wrote:
> >> >
> >> > Hi,
> >> >
> >> > while we already need to solve how to make dialog polyfill work, I
> >>found
> >> a
> >> > new problem that hope you guys have already managed.
> >> >
> >> > I need to put the following lines in my Dialog MDL component:
> >> >
> >> > if (! dialog.showModal) {
> >> > dialogPolyfill.registerDialog(dialog);
> >> > }
> >> >
> >> > I have dialog var in my AS3 so this is ok, but I don't have
> >> > "dialogPolyfill" var
> >> > So the question is...how make FlexJS aware of "dialogPolyfil" that is
> >> setup
> >> > by the JS loaded as an external resource so I can compile my AS3 class
> >> and
> >> > make it work in the browser?
> >> >
> >> >
> >> > --
> >> > Carlos Rovira
> >> > http://about.me/carlosrovira
> >>
> >>
>
>

Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Alex Harui <ah...@adobe.com>.
And you could cheat a little bit and add it to missing.js in
flex-typedefs/js if you don't want to bother setting up a whole new
typedef SWC.

BTW, I will be checking in changes to Falcon that make it really easy to
use AS to generate typedefs.

-Alex

On 1/19/17, 7:33 AM, "Josh Tynjala" <jo...@gmail.com> wrote:

>If you don't mind the string property reference, that would be the easiest
>way to access it. :)
>
>- Josh
>
>On Thu, Jan 19, 2017 at 7:21 AM, Harbs <ha...@gmail.com> wrote:
>
>> window[“dialogPolyfill”].registerDialog(dialog) should do it.
>>
>> > On Jan 19, 2017, at 2:01 PM, Carlos Rovira <ca...@apache.org>
>> wrote:
>> >
>> > Hi,
>> >
>> > while we already need to solve how to make dialog polyfill work, I
>>found
>> a
>> > new problem that hope you guys have already managed.
>> >
>> > I need to put the following lines in my Dialog MDL component:
>> >
>> > if (! dialog.showModal) {
>> > dialogPolyfill.registerDialog(dialog);
>> > }
>> >
>> > I have dialog var in my AS3 so this is ok, but I don't have
>> > "dialogPolyfill" var
>> > So the question is...how make FlexJS aware of "dialogPolyfil" that is
>> setup
>> > by the JS loaded as an external resource so I can compile my AS3 class
>> and
>> > make it work in the browser?
>> >
>> >
>> > --
>> > Carlos Rovira
>> > http://about.me/carlosrovira
>>
>>


Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Josh Tynjala <jo...@gmail.com>.
If you don't mind the string property reference, that would be the easiest
way to access it. :)

- Josh

On Thu, Jan 19, 2017 at 7:21 AM, Harbs <ha...@gmail.com> wrote:

> window[“dialogPolyfill”].registerDialog(dialog) should do it.
>
> > On Jan 19, 2017, at 2:01 PM, Carlos Rovira <ca...@apache.org>
> wrote:
> >
> > Hi,
> >
> > while we already need to solve how to make dialog polyfill work, I found
> a
> > new problem that hope you guys have already managed.
> >
> > I need to put the following lines in my Dialog MDL component:
> >
> > if (! dialog.showModal) {
> > dialogPolyfill.registerDialog(dialog);
> > }
> >
> > I have dialog var in my AS3 so this is ok, but I don't have
> > "dialogPolyfill" var
> > So the question is...how make FlexJS aware of "dialogPolyfil" that is
> setup
> > by the JS loaded as an external resource so I can compile my AS3 class
> and
> > make it work in the browser?
> >
> >
> > --
> > Carlos Rovira
> > http://about.me/carlosrovira
>
>

Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Harbs <ha...@gmail.com>.
window[“dialogPolyfill”].registerDialog(dialog) should do it.

> On Jan 19, 2017, at 2:01 PM, Carlos Rovira <ca...@apache.org> wrote:
> 
> Hi,
> 
> while we already need to solve how to make dialog polyfill work, I found a
> new problem that hope you guys have already managed.
> 
> I need to put the following lines in my Dialog MDL component:
> 
> if (! dialog.showModal) {
> dialogPolyfill.registerDialog(dialog);
> }
> 
> I have dialog var in my AS3 so this is ok, but I don't have
> "dialogPolyfill" var
> So the question is...how make FlexJS aware of "dialogPolyfil" that is setup
> by the JS loaded as an external resource so I can compile my AS3 class and
> make it work in the browser?
> 
> 
> -- 
> Carlos Rovira
> http://about.me/carlosrovira


Re: [FlexJS] How to call external JS function from AS3 class (and first make it compile)

Posted by Josh Tynjala <jo...@gmail.com>.
For any JS libraries that you load with <script> in the HTML, you need to
make a typedef SWC and reference it on the external-library-path to expose
the APIs to ActionScript.

- Josh

On Jan 19, 2017 4:01 AM, "Carlos Rovira" <ca...@apache.org> wrote:

> Hi,
>
> while we already need to solve how to make dialog polyfill work, I found a
> new problem that hope you guys have already managed.
>
> I need to put the following lines in my Dialog MDL component:
>
> if (! dialog.showModal) {
> dialogPolyfill.registerDialog(dialog);
> }
>
> I have dialog var in my AS3 so this is ok, but I don't have
> "dialogPolyfill" var
> So the question is...how make FlexJS aware of "dialogPolyfil" that is setup
> by the JS loaded as an external resource so I can compile my AS3 class and
> make it work in the browser?
>
>
> --
> Carlos Rovira
> http://about.me/carlosrovira
>