No method working - js.html - (Haxe 3.0)

265 views
Skip to first unread message

SrMouraSilva

unread,
Aug 24, 2013, 9:08:25 PM8/24/13
to haxe...@googlegroups.com
I apologize for using the google translate :P

Hello guys!
I'm new here in Haxe, both in the community, as this programming language.

Googling around I found this language. I was excited about the possibility of javascript programming as if it was Java (OOP structure)

After installing Haxe 3.0, I followed the examples of the doc and I ran into a problem. Simply no method of a class contained in js.html worked for me :/

Example code:
package slideview.getImage;

class FactoryGetImage {

   
static function main() : Void {
       
new FactoryGetImage();
   
}

   
static function new(?idTagContainer : String, ?callback) : Void {
        trace
(js.html.Document.getElementById('teste'));
   
}
}


But the following error is generated:
src/slideview/getImage/FactoryGetImage.hx:21: characters 8-39 : js.html.#Document has no field getElementById


I went looking in HaxeToolkit\haxe\std\js\html\Document.hx and realized that all methods are public, but not static.


I then tried
var doc = new js.html.Document();
doc
.getElementById('teste');

But the error was generated.
src/slideview/getImage/FactoryGetImage.hx:21: characters 12-34 : js.html.Document does not have a constructor


Concludes the following:
  1. Attempt: There are static, so I do not have access. I will then instantiate a new object to access methods
  2. Attempt: It has no constructor. So it was for the methods being 'static'?

I put static, performed and...
Compiled!

But, when compiled, the following error appeared in the browser console:

(Firefox 24.0 beta)
   
TypeError: Document.getElementById is not a function
     console
.log(Document.getElementById("teste"));

'Document'?!? It was to be 'document'!


Again, in Document.hx try:

Line 41 @:native("Document")
 
for
Line 41 @:native("document")
Compiled! And working! \o/


But ... what did I do wrong? I'll have to change all the libraries that I am using?!

Looking at the documentation has realized that 'js.Lib' instead of 'js.html'. Concluded that the documentation is outdated ...


Could anyone help me?

Another doubt. If I want to use my class 'slideview.getImage.FactoryGetImage' other js codes, how do? Example:

<script src="SlideView.js"></script><!-- slideview.getImage.FactoryGetImage.hx compiled to JS -->

<script>
var myObj = new slideview.getImage.FactoryGetImage();
</script>

Note:

  • OS - Windows 7
  • Haxe 3.0.0
  • GUI - Eclipse
  • Navigator - Firefox 24 Beta

j...@justinfront.net

unread,
Aug 24, 2013, 10:25:22 PM8/24/13
to haxe...@googlegroups.com
SrMouraSilva

Just did a quick test in some code of a project, for clarity you need some html something like...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor='#E5E5E5'>
    <div id="test"></div>
    <script type="text/javascript" src="MyHaxe.js"></script>
</body>

Then something along the lines of

class MyHaxe
{
    static function main(){ new MyHaxe(); } public function new()
    {
js.Browser.document.getElementById("test").innerHTML = 'test';
    }
}




--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

SrMouraSilva

unread,
Aug 24, 2013, 10:48:34 PM8/24/13
to haxe...@googlegroups.com
Oops! In haXe 3 is 'js.Browser' and not 'js.Lib' nor 'js.html' ¬¬'

I here a note on page migration 2.x to 3.x
http://haxe.org/manual/haxe3/migration#javascript-api-changes

Just wanted documentation of the first steps to say something about...

Thanks @JLM for giving me attention

Good night!

j...@justinfront.net

unread,
Aug 24, 2013, 11:18:50 PM8/24/13
to haxe...@googlegroups.com
SrMournaSilva

Well my experiments with JS are here and maybe useful:

Also try looking here:
for instance flambe html stuff..

There is lots more around.

Best Justin
Reply all
Reply to author
Forward
0 new messages