untyped __js__

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

untyped __js__

slenkar
when some javascript magic code runs in my program an error message appears:__js__ is not defined


I am trying to add text to a text area with javascript
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

MarcWeber
Excerpts from slenkar's message of Wed Aug 04 18:53:11 +0200 2010:
>
> when some javascript magic code runs in my program an error message
> appears:__js__ is not defined
> I am trying to add text to a text area with javascript

How do you expect others to help you without you pasting the relevant
code?

Have a look at the std code. It should contain many examples about how
to use __js__.

But from looking at that code:


  __js__("for( var k in o ) { ");
    [...]
  __js__("}");

It seems that you can't do much things wrong.
So you can you copy the .hx code you wrote and the lines found in
Output.js  ?
If you can't find the lines add some dummy var such as

var dummy = "findme"
and look for that string.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

MarcWeber
Excerpts from Marc Weber's message of Wed Aug 04 19:16:11 +0200 2010:
> Excerpts from slenkar's message of Wed Aug 04 18:53:11 +0200 2010:
> >
> > when some javascript magic code runs in my program an error message
> > appears:__js__ is not defined
> > I am trying to add text to a text area with javascript
Also make sure that you use the haxe cmopiler flags telling it that you
target javascript!

Example:

-main Main --js-namespace optional-namespace -js Output.js

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

Benjamin Dasnois
Hello,

Slenkar, don't take it bad but people want to have some code to look at to help you (unless the problem is more with a situation than with some code, in which case you should carefully and precisely describe the situation).

From the error you get, I think you forgot that __js__ (as all "magic functions") must be used inside an untyped block. So writing something like

untyped __js__("myJSCode"); should work.

Regards,

On Wed, Aug 4, 2010 at 7:18 PM, Marc Weber <[hidden email]> wrote:
Excerpts from Marc Weber's message of Wed Aug 04 19:16:11 +0200 2010:
> Excerpts from slenkar's message of Wed Aug 04 18:53:11 +0200 2010:
> >
> > when some javascript magic code runs in my program an error message
> > appears:__js__ is not defined
> > I am trying to add text to a text area with javascript
Also make sure that you use the haxe cmopiler flags telling it that you
target javascript!

Example:

-main Main --js-namespace optional-namespace -js Output.js

Marc Weber

--
haXe - an open source web programming language
http://haxe.org



--
DASNOIS Benjamin
http://www.benjamindasnois.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

slenkar
heres my code:
untyped __js__("var myTextField = document.getElementById('textarea1');myTextField.value ="+ text+";");

it compiles but throws the error when it is called
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

Lars Madson
Le 04/08/2010 22:53, slenkar a écrit :
> heres my code:
> untyped __js__("var myTextField =
> document.getElementById('textarea1');myTextField.value ="+ text+";");
>
> it compiles but throws the error when it is called
>    

Maybe you could write that code directly in haxe:

var myTextField = js.Lib.document.getElementById( 'textarea1' );
myTextField.value = text;

Or are you using the __js__ for a reason I don't know ?

Laurent

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

MarcWeber
In reply to this post by slenkar
You clearly identified something one could call a bug.
But a bug in finding programmer errors only:

Can you review the quotes? It does not compile for me:
> untyped __js__("var myTextField =
> document.getElementById('textarea1');myTextField.value ="+ text+";");

Where does text come from? What should this line do?
Var names are preserved (AFAIK). So this should do what you want:
> document.getElementById('textarea1');myTextField.value = text;");

You don't have to define the myTextField as local var. You could just
use:

untyped __js__("document.getElementById('textarea1'].value = text;");

You can get around this without untyped:

    var f:js.Dom.FormElement = cast(js.Lib.document.getElementById("id"));
    f.value = "foo";

Don't know whether there is a better way.

I tried
    cast(js.Lib.document.getElementById("id"), js.Dom.FormElement).value = "foo"

But that yields: Test.hx|15 col 4| : Cast type must be a class or an enum

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

Nicolas Cannasse
Marc Weber a écrit :
> You clearly identified something one could call a bug.

This is not a bug : __js__ only accept constant strings because it will
directly put the string as JS code in the generated .js file

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: untyped __js__

MarcWeber
Excerpts from Nicolas Cannasse's message of Thu Aug 05 10:00:38 +0200 2010:
> This is not a bug : __js__ only accept constant strings because it will
> directly put the string as JS code in the generated .js file

So the parser fails to parse a constant string and will fall back to
calling untyped a_func_which_happens_to_be___js__(arg) ?

Sorry then. Its a case where the compile can guide the user - but
doesn't have to.

Sorry about my false statement.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org