Javascript functions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Javascript functions

Jim Norris
In FlexJS, is there a way to call a Javascript function from ActionScript?

 

I did not see an obvious way to do it but I may have missed something.

 

 

 

 

 

Thanks,

 

Jim

Reply | Threaded
Open this post in threaded view
|

Re: Javascript functions

piotrz
Hi Jim,

Yes we can, but you have to assume that your library is part of your loaded
webpage. [1] - In this html template you can see that material.min.js is
included. We are doing calls of JS functions from AS in MDL module. Example
is UpgradeElement bead (method: upgradeElement) which just gets object from
window and calls on it some existing function [2]

[1]
https://github.com/apache/flex-asjs/blob/develop/examples/flexjs/MDLExample/src/main/resources/mdl-js-index-template.html
[2]
https://github.com/apache/flex-asjs/blob/develop/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/UpgradeElement.as

Let me know it it is enough understandable.

Piotr


2017-08-23 15:40 GMT+02:00 Jim Norris <[hidden email]>:

> In FlexJS, is there a way to call a Javascript function from ActionScript?
>
>
>
> I did not see an obvious way to do it but I may have missed something.
>
>
>
>
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jim
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Javascript functions

Olaf Krueger
Piotr, whats about just creating some TypeDefs?

Olaf
Reply | Threaded
Open this post in threaded view
|

Re: Javascript functions

Harbs
Typedefs makes the signatures known, but the javascript needs to be loaded.

Generally, loaded javascript is in the global space and is attached to the window.

If you have typedefs defined you can just access the global MyFoo.doSomething() directly. If you don’t have typedefs defined, you can do the same things like this:

window["MyFoo"]["doSomething"]()

What I’ve found is that defining typedefs is worhtwhile when you are doing extensive integration. Otherwise, bracket access to the window object gets you to where you want to be very quickly…

HTH,
Harbs

> On Aug 23, 2017, at 7:53 PM, Olaf Krueger <[hidden email]> wrote:
>
> Piotr, whats about just creating some TypeDefs?
>
> Olaf
>
>
>
> --
> View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Javascript-functions-tp63954p63956.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.