jeash issues, possible to work around this?

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

jeash issues, possible to work around this?

tom rhodes
Hi all,

i'm back on trying to get a simple little flash thing to work in html/canvas with jeash. i'm now calling my stageResized function in the html because of Event.RESIZE not working yet in jeash. my main class is like this...

class Main 
{
static private var app:Main;
private var layoutManager:LayoutManager;
private var layout:Sprite;
private var s:Stage;
static public function main()
{
app = new Main();
}
public function new() 
{
s = Lib.current.stage;
s.scaleMode = StageScaleMode.NO_SCALE;
s.align = StageAlign.TOP_LEFT;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
s.addEventListener(Event.RESIZE, stageResized);
}
private function stageResized(?e:Event):Void 
{
s.removeChild(layout);
layout = null;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
}
}

which works perfectly in flash, redrawing my layout according to the new stage dimensions as expected. however when i run the jeash output in my browser i get an uncaught TypeError "Cannot call a method 'removeChild' of null". so i had a look at jeash's output...

Main = function(p) { if( p === $_ ) return; {
    this.s = jeash.Lib.jeashGetCurrent().GetStage();
    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
    this.s.align = jeash.display.StageAlign.TOP_LEFT;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
    this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
}}
Main.__name__ = ["Main"];
Main.app = null;
Main.main = function() {
    Main.app = new Main();
}
Main.prototype.layoutManager = null;
Main.prototype.layout = null;
Main.prototype.s = null;
Main.prototype.stageResized = function(e) {
    this.s.removeChild(this.layout);
    this.layout = null;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
}

and the line that is throwing it is "this.s.removeChild(this.layout);", now s is getting set when Main.main() is called as the last line of the jeash JS. why is it null when stageResized is called?

i've tried moving "Main,prototype.layout = null" to no effect, i also tried using an init function and waiting 1 second before calling it to see is it really was an execution order thing. i'm pretty stumped though now! i'm just seeing if i can get a simple layout engine that adapts to portrait/landscape and diff size screens going, which i'll then mirror with some html/css for those without flash or canvas support. should end up with the result that content looks nicely formatted no matter what you use to get at it. i'm getting the feeling that it's not possible right now though :(

cheers,

tom.

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

Re: jeash issues, possible to work around this?

Heinz Hölzer-2
Maybe your layoutmanager returns null in this line

this.layout = this.layoutManager.getLayout();


Am 23.02.2011 14:46, schrieb tom rhodes:
Hi all,

i'm back on trying to get a simple little flash thing to work in html/canvas with jeash. i'm now calling my stageResized function in the html because of Event.RESIZE not working yet in jeash. my main class is like this...

class Main 
{
static private var app:Main;
private var layoutManager:LayoutManager;
private var layout:Sprite;
private var s:Stage;
static public function main()
{
app = new Main();
}
public function new() 
{
s = Lib.current.stage;
s.scaleMode = StageScaleMode.NO_SCALE;
s.align = StageAlign.TOP_LEFT;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
s.addEventListener(Event.RESIZE, stageResized);
}
private function stageResized(?e:Event):Void 
{
s.removeChild(layout);
layout = null;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
}
}

which works perfectly in flash, redrawing my layout according to the new stage dimensions as expected. however when i run the jeash output in my browser i get an uncaught TypeError "Cannot call a method 'removeChild' of null". so i had a look at jeash's output...

Main = function(p) { if( p === $_ ) return; {
    this.s = jeash.Lib.jeashGetCurrent().GetStage();
    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
    this.s.align = jeash.display.StageAlign.TOP_LEFT;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
    this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
}}
Main.__name__ = ["Main"];
Main.app = null;
Main.main = function() {
    Main.app = new Main();
}
Main.prototype.layoutManager = null;
Main.prototype.layout = null;
Main.prototype.s = null;
Main.prototype.stageResized = function(e) {
    this.s.removeChild(this.layout);
    this.layout = null;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
}

and the line that is throwing it is "this.s.removeChild(this.layout);", now s is getting set when Main.main() is called as the last line of the jeash JS. why is it null when stageResized is called?

i've tried moving "Main,prototype.layout = null" to no effect, i also tried using an init function and waiting 1 second before calling it to see is it really was an execution order thing. i'm pretty stumped though now! i'm just seeing if i can get a simple layout engine that adapts to portrait/landscape and diff size screens going, which i'll then mirror with some html/css for those without flash or canvas support. should end up with the result that content looks nicely formatted no matter what you use to get at it. i'm getting the feeling that it's not possible right now though :(

cheers,

tom.


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

Re: jeash issues, possible to work around this?

tom rhodes
cheers heinz but it seems it's s, the reference to the stage that's null...

2011/2/23 Heinz Hölzer <[hidden email]>
Maybe your layoutmanager returns null in this line


this.layout = this.layoutManager.getLayout();


Am 23.02.2011 14:46, schrieb tom rhodes:
Hi all,

i'm back on trying to get a simple little flash thing to work in html/canvas with jeash. i'm now calling my stageResized function in the html because of Event.RESIZE not working yet in jeash. my main class is like this...

class Main 
{
static private var app:Main;
private var layoutManager:LayoutManager;
private var layout:Sprite;
private var s:Stage;
static public function main()
{
app = new Main();
}
public function new() 
{
s = Lib.current.stage;
s.scaleMode = StageScaleMode.NO_SCALE;
s.align = StageAlign.TOP_LEFT;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
s.addEventListener(Event.RESIZE, stageResized);
}
private function stageResized(?e:Event):Void 
{
s.removeChild(layout);
layout = null;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
}
}

which works perfectly in flash, redrawing my layout according to the new stage dimensions as expected. however when i run the jeash output in my browser i get an uncaught TypeError "Cannot call a method 'removeChild' of null". so i had a look at jeash's output...

Main = function(p) { if( p === $_ ) return; {
    this.s = jeash.Lib.jeashGetCurrent().GetStage();
    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
    this.s.align = jeash.display.StageAlign.TOP_LEFT;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
    this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
}}
Main.__name__ = ["Main"];
Main.app = null;
Main.main = function() {
    Main.app = new Main();
}
Main.prototype.layoutManager = null;
Main.prototype.layout = null;
Main.prototype.s = null;
Main.prototype.stageResized = function(e) {
    this.s.removeChild(this.layout);
    this.layout = null;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
}

and the line that is throwing it is "this.s.removeChild(this.layout);", now s is getting set when Main.main() is called as the last line of the jeash JS. why is it null when stageResized is called?

i've tried moving "Main,prototype.layout = null" to no effect, i also tried using an init function and waiting 1 second before calling it to see is it really was an execution order thing. i'm pretty stumped though now! i'm just seeing if i can get a simple layout engine that adapts to portrait/landscape and diff size screens going, which i'll then mirror with some html/css for those without flash or canvas support. should end up with the result that content looks nicely formatted no matter what you use to get at it. i'm getting the feeling that it's not possible right now though :(

cheers,

tom.


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


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

Re: jeash issues, possible to work around this?

Heinz Hölzer-2
In reply to this post by tom rhodes
Am 23.02.2011 14:46, schrieb tom rhodes:
s = Lib.current.stage;
what happens if you trace s after this line?

s = Lib.current.stage;
trace(s);


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

Re: jeash issues, possible to work around this?

Heinz Hölzer-2
In reply to this post by tom rhodes
maybe you need to call an init function as in nme/neash.

Am 23.02.2011 14:46, schrieb tom rhodes:
Hi all,

i'm back on trying to get a simple little flash thing to work in html/canvas with jeash. i'm now calling my stageResized function in the html because of Event.RESIZE not working yet in jeash. my main class is like this...

class Main 
{
static private var app:Main;
private var layoutManager:LayoutManager;
private var layout:Sprite;
private var s:Stage;
static public function main()
{
app = new Main();
}
public function new() 
{
s = Lib.current.stage;
s.scaleMode = StageScaleMode.NO_SCALE;
s.align = StageAlign.TOP_LEFT;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
s.addEventListener(Event.RESIZE, stageResized);
}
private function stageResized(?e:Event):Void 
{
s.removeChild(layout);
layout = null;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
}
}

which works perfectly in flash, redrawing my layout according to the new stage dimensions as expected. however when i run the jeash output in my browser i get an uncaught TypeError "Cannot call a method 'removeChild' of null". so i had a look at jeash's output...

Main = function(p) { if( p === $_ ) return; {
    this.s = jeash.Lib.jeashGetCurrent().GetStage();
    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
    this.s.align = jeash.display.StageAlign.TOP_LEFT;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
    this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
}}
Main.__name__ = ["Main"];
Main.app = null;
Main.main = function() {
    Main.app = new Main();
}
Main.prototype.layoutManager = null;
Main.prototype.layout = null;
Main.prototype.s = null;
Main.prototype.stageResized = function(e) {
    this.s.removeChild(this.layout);
    this.layout = null;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
}

and the line that is throwing it is "this.s.removeChild(this.layout);", now s is getting set when Main.main() is called as the last line of the jeash JS. why is it null when stageResized is called?

i've tried moving "Main,prototype.layout = null" to no effect, i also tried using an init function and waiting 1 second before calling it to see is it really was an execution order thing. i'm pretty stumped though now! i'm just seeing if i can get a simple layout engine that adapts to portrait/landscape and diff size screens going, which i'll then mirror with some html/css for those without flash or canvas support. should end up with the result that content looks nicely formatted no matter what you use to get at it. i'm getting the feeling that it's not possible right now though :(

cheers,

tom.


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

Re: jeash issues, possible to work around this?

tom rhodes

traces "Stage" as it should from the JS from the constructor in Main. traces null when i trace s out in the stageResized function.

so then i reset the reference to s, repeating the line s = Lib.current.stage; then it traces correctly BUT then jeash's removeChild function throws a "removeChild : none found?" error.

i tried an init, even with a time delay but no dice. seems something is up with Stage in jeash methinks...

2011/2/23 Heinz Hölzer <[hidden email]>
maybe you need to call an init function as in nme/neash.


Am 23.02.2011 14:46, schrieb tom rhodes:
Hi all,

i'm back on trying to get a simple little flash thing to work in html/canvas with jeash. i'm now calling my stageResized function in the html because of Event.RESIZE not working yet in jeash. my main class is like this...

class Main 
{
static private var app:Main;
private var layoutManager:LayoutManager;
private var layout:Sprite;
private var s:Stage;
static public function main()
{
app = new Main();
}
public function new() 
{
s = Lib.current.stage;
s.scaleMode = StageScaleMode.NO_SCALE;
s.align = StageAlign.TOP_LEFT;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
s.addEventListener(Event.RESIZE, stageResized);
}
private function stageResized(?e:Event):Void 
{
s.removeChild(layout);
layout = null;
var w:Int = Lib.current.stage.stageWidth;
var h:Int = Lib.current.stage.stageHeight;
layoutManager = new LayoutManager(w, h);
layout = layoutManager.getLayout();
s.addChild(layout);
}
}

which works perfectly in flash, redrawing my layout according to the new stage dimensions as expected. however when i run the jeash output in my browser i get an uncaught TypeError "Cannot call a method 'removeChild' of null". so i had a look at jeash's output...

Main = function(p) { if( p === $_ ) return; {
    this.s = jeash.Lib.jeashGetCurrent().GetStage();
    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
    this.s.align = jeash.display.StageAlign.TOP_LEFT;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
    this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
}}
Main.__name__ = ["Main"];
Main.app = null;
Main.main = function() {
    Main.app = new Main();
}
Main.prototype.layoutManager = null;
Main.prototype.layout = null;
Main.prototype.s = null;
Main.prototype.stageResized = function(e) {
    this.s.removeChild(this.layout);
    this.layout = null;
    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
    this.layoutManager = new com.LayoutManager(w,h);
    this.layout = this.layoutManager.getLayout();
    this.s.addChild(this.layout);
}

and the line that is throwing it is "this.s.removeChild(this.layout);", now s is getting set when Main.main() is called as the last line of the jeash JS. why is it null when stageResized is called?

i've tried moving "Main,prototype.layout = null" to no effect, i also tried using an init function and waiting 1 second before calling it to see is it really was an execution order thing. i'm pretty stumped though now! i'm just seeing if i can get a simple layout engine that adapts to portrait/landscape and diff size screens going, which i'll then mirror with some html/css for those without flash or canvas support. should end up with the result that content looks nicely formatted no matter what you use to get at it. i'm getting the feeling that it's not possible right now though :(

cheers,

tom.


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


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

Re: jeash issues, possible to work around this?

Niel Drummond-3
In reply to this post by Heinz Hölzer-2
I can't reproduce your example as it stands, because you haven't provided LayoutManager.  The problem is not with initialisation, if I remove the LayoutManager code, your example works. If I replace LayoutManager.getLayout with a stub, that returns an empty Sprite, it also works.

- Niel

On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:

> maybe you need to call an init function as in nme/neash.
>
> Am 23.02.2011 14:46, schrieb tom rhodes:
> >Hi all,
> >
> >i'm back on trying to get a simple little flash thing to work in
> >html/canvas with jeash. i'm now calling my stageResized function in
> >the html because of Event.RESIZE not working yet in jeash. my main
> >class is like this...
> >
> >class Main
> >{
> >static private var app:Main;
> >private var layoutManager:LayoutManager;
> >private var layout:Sprite;
> >private var s:Stage;
> >static public function main()
> >{
> >app = new Main();
> >}
> >public function new()
> >{
> >s = Lib.current.stage;
> >s.scaleMode = StageScaleMode.NO_SCALE;
> >s.align = StageAlign.TOP_LEFT;
> >var w:Int = Lib.current.stage.stageWidth;
> >var h:Int = Lib.current.stage.stageHeight;
> >layoutManager = new LayoutManager(w, h);
> >layout = layoutManager.getLayout();
> >s.addChild(layout);
> >s.addEventListener(Event.RESIZE, stageResized);
> >}
> >private function stageResized(?e:Event):Void
> >{
> >s.removeChild(layout);
> >layout = null;
> >var w:Int = Lib.current.stage.stageWidth;
> >var h:Int = Lib.current.stage.stageHeight;
> >layoutManager = new LayoutManager(w, h);
> >layout = layoutManager.getLayout();
> >s.addChild(layout);
> >}
> >}
> >
> >which works perfectly in flash, redrawing my layout according to the
> >new stage dimensions as expected. however when i run the jeash output
> >in my browser i get an uncaught TypeError "Cannot call a method
> >'removeChild' of null". so i had a look at jeash's output...
> >
> >Main = function(p) { if( p === $_ ) return; {
> >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >    this.layoutManager = new com.LayoutManager(w,h);
> >    this.layout = this.layoutManager.getLayout();
> >    this.s.addChild(this.layout);
> >  
> > this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >}}
> >Main.__name__ = ["Main"];
> >Main.app = null;
> >Main.main = function() {
> >    Main.app = new Main();
> >}
> >Main.prototype.layoutManager = null;
> >Main.prototype.layout = null;
> >Main.prototype.s = null;
> >Main.prototype.stageResized = function(e) {
> >    this.s.removeChild(this.layout);
> >    this.layout = null;
> >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >    this.layoutManager = new com.LayoutManager(w,h);
> >    this.layout = this.layoutManager.getLayout();
> >    this.s.addChild(this.layout);
> >}
> >
> >and the line that is throwing it is
> >"this.s.removeChild(this.layout);", now s is getting set when
> >Main.main() is called as the last line of the jeash JS. why is it null
> >when stageResized is called?
> >
> >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >tried using an init function and waiting 1 second before calling it to
> >see is it really was an execution order thing. i'm pretty stumped
> >though now! i'm just seeing if i can get a simple layout engine that
> >adapts to portrait/landscape and diff size screens going, which i'll
> >then mirror with some html/css for those without flash or canvas
> >support. should end up with the result that content looks nicely
> >formatted no matter what you use to get at it. i'm getting the feeling
> >that it's not possible right now though :(
> >
> >cheers,
> >
> >tom.
>

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

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

Re: jeash issues, possible to work around this?

tom rhodes
sweet! lemme check out layoutManager then...


On 23 February 2011 16:22, Niel Drummond <[hidden email]> wrote:
I can't reproduce your example as it stands, because you haven't provided LayoutManager.  The problem is not with initialisation, if I remove the LayoutManager code, your example works. If I replace LayoutManager.getLayout with a stub, that returns an empty Sprite, it also works.

- Niel

On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> maybe you need to call an init function as in nme/neash.
>
> Am 23.02.2011 14:46, schrieb tom rhodes:
> >Hi all,
> >
> >i'm back on trying to get a simple little flash thing to work in
> >html/canvas with jeash. i'm now calling my stageResized function in
> >the html because of Event.RESIZE not working yet in jeash. my main
> >class is like this...
> >
> >class Main
> >{
> >static private var app:Main;
> >private var layoutManager:LayoutManager;
> >private var layout:Sprite;
> >private var s:Stage;
> >static public function main()
> >{
> >app = new Main();
> >}
> >public function new()
> >{
> >s = Lib.current.stage;
> >s.scaleMode = StageScaleMode.NO_SCALE;
> >s.align = StageAlign.TOP_LEFT;
> >var w:Int = Lib.current.stage.stageWidth;
> >var h:Int = Lib.current.stage.stageHeight;
> >layoutManager = new LayoutManager(w, h);
> >layout = layoutManager.getLayout();
> >s.addChild(layout);
> >s.addEventListener(Event.RESIZE, stageResized);
> >}
> >private function stageResized(?e:Event):Void
> >{
> >s.removeChild(layout);
> >layout = null;
> >var w:Int = Lib.current.stage.stageWidth;
> >var h:Int = Lib.current.stage.stageHeight;
> >layoutManager = new LayoutManager(w, h);
> >layout = layoutManager.getLayout();
> >s.addChild(layout);
> >}
> >}
> >
> >which works perfectly in flash, redrawing my layout according to the
> >new stage dimensions as expected. however when i run the jeash output
> >in my browser i get an uncaught TypeError "Cannot call a method
> >'removeChild' of null". so i had a look at jeash's output...
> >
> >Main = function(p) { if( p === $_ ) return; {
> >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >    this.layoutManager = new com.LayoutManager(w,h);
> >    this.layout = this.layoutManager.getLayout();
> >    this.s.addChild(this.layout);
> >
> > this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >}}
> >Main.__name__ = ["Main"];
> >Main.app = null;
> >Main.main = function() {
> >    Main.app = new Main();
> >}
> >Main.prototype.layoutManager = null;
> >Main.prototype.layout = null;
> >Main.prototype.s = null;
> >Main.prototype.stageResized = function(e) {
> >    this.s.removeChild(this.layout);
> >    this.layout = null;
> >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >    this.layoutManager = new com.LayoutManager(w,h);
> >    this.layout = this.layoutManager.getLayout();
> >    this.s.addChild(this.layout);
> >}
> >
> >and the line that is throwing it is
> >"this.s.removeChild(this.layout);", now s is getting set when
> >Main.main() is called as the last line of the jeash JS. why is it null
> >when stageResized is called?
> >
> >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >tried using an init function and waiting 1 second before calling it to
> >see is it really was an execution order thing. i'm pretty stumped
> >though now! i'm just seeing if i can get a simple layout engine that
> >adapts to portrait/landscape and diff size screens going, which i'll
> >then mirror with some html/css for those without flash or canvas
> >support. should end up with the result that content looks nicely
> >formatted no matter what you use to get at it. i'm getting the feeling
> >that it's not possible right now though :(
> >
> >cheers,
> >
> >tom.
>

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

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


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

Re: jeash issues, possible to work around this?

tom rhodes
i'm still getting the none found error even just returning a new sprite from getLayout, here's the original LayoutManager...

class LayoutManager
{
private var layoutWidth:Int;
private var layoutHeight:Int;
private var layout:Sprite;
static inline var goldenRatio:Float = 1.618;
private var horizPadding:Int;
private var verticalPadding:Int;
private var sectionHorizPadding:Int;
private var sectionVertPadding:Int;
private var contentHeight:Int;
private var contentWidth:Int;
    public function new(w:Int, h:Int):Void 
{
layoutWidth = w;
layoutHeight = h;
layout = new Sprite();
}
public function getLayout():Sprite
{
horizPadding = getGoldenSlice(layoutWidth, 5);
verticalPadding = getGoldenSlice(layoutHeight, 5);
sectionHorizPadding = getGoldenSlice(layoutWidth, 8);
sectionVertPadding = getGoldenSlice(layoutHeight, 8);
layout.x = horizPadding;
layout.y = verticalPadding;
contentHeight = layoutHeight - (verticalPadding * 2);
contentWidth = layoutWidth - (horizPadding * 2);
drawLayout(layoutWidth > layoutHeight ? true : false);
return layout;
}    
private function drawLayout(isLandscape:Bool):Void 
{
var contentAreaWidth:Int = isLandscape ? Math.round(contentWidth / goldenRatio) - (sectionHorizPadding * 2) : contentWidth;
var contentAreaHeight:Int = isLandscape ? contentHeight : contentHeight - getGoldenSlice(Math.round(contentHeight / goldenRatio), 2);
var contentAreaX:Int = isLandscape ? contentWidth - contentAreaWidth : 0;
var contentAreaY:Int = isLandscape ? 0 : contentHeight - contentAreaHeight + sectionVertPadding;
var headerAreaWidth:Int = isLandscape ? contentAreaX - (sectionHorizPadding * 2) : contentWidth;
var headerAreaHeight:Int = isLandscape ? contentHeight - Math.round(contentHeight / goldenRatio) - sectionVertPadding : getGoldenSlice(Math.round(contentHeight / goldenRatio), 3);
var headerAreaX:Int = 0;
var headerAreaY:Int = 0;
var navAreaWidth:Int = isLandscape ? headerAreaWidth : contentWidth;
var navAreaHeight:Int = isLandscape ? contentHeight - headerAreaHeight - sectionVertPadding : Math.round(headerAreaHeight / goldenRatio) - sectionVertPadding;
var navAreaX:Int = 0;
var navAreaY:Int = isLandscape ? headerAreaHeight + sectionVertPadding : headerAreaHeight + sectionVertPadding;
var contentSectionLayout:BasicSectionLayout = new BasicSectionLayout(contentAreaWidth, contentAreaHeight);
var headerSectionLayout:BasicSectionLayout = new BasicSectionLayout(headerAreaWidth, headerAreaHeight);
var navSectionLayout:BasicSectionLayout = new BasicSectionLayout(navAreaWidth, navAreaHeight);
contentSectionLayout.drawLayout();
headerSectionLayout.drawLayout();
navSectionLayout.drawLayout();
contentSectionLayout.x = contentAreaX;
contentSectionLayout.y = contentAreaY;
layout.addChild(contentSectionLayout);
headerSectionLayout.x = headerAreaX;
headerSectionLayout.y = headerAreaY;
layout.addChild(headerSectionLayout);
navSectionLayout.x = navAreaX;
navSectionLayout.y = navAreaY;
layout.addChild(navSectionLayout);
}
private function getGoldenSlice(layoutDim:Int, numDivides:Int):Int 
{
var w:Float = cast(layoutDim);
while (numDivides-- > 0) { w /= goldenRatio; };
return Math.round(w);
}
}

all BasicSectionLayout does for now is draw a rectangle. can't see why anything in there would mess with the stage?


On 23 February 2011 16:25, tom rhodes <[hidden email]> wrote:
sweet! lemme check out layoutManager then...



On 23 February 2011 16:22, Niel Drummond <[hidden email]> wrote:
I can't reproduce your example as it stands, because you haven't provided LayoutManager.  The problem is not with initialisation, if I remove the LayoutManager code, your example works. If I replace LayoutManager.getLayout with a stub, that returns an empty Sprite, it also works.

- Niel

On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> maybe you need to call an init function as in nme/neash.
>
> Am 23.02.2011 14:46, schrieb tom rhodes:
> >Hi all,
> >
> >i'm back on trying to get a simple little flash thing to work in
> >html/canvas with jeash. i'm now calling my stageResized function in
> >the html because of Event.RESIZE not working yet in jeash. my main
> >class is like this...
> >
> >class Main
> >{
> >static private var app:Main;
> >private var layoutManager:LayoutManager;
> >private var layout:Sprite;
> >private var s:Stage;
> >static public function main()
> >{
> >app = new Main();
> >}
> >public function new()
> >{
> >s = Lib.current.stage;
> >s.scaleMode = StageScaleMode.NO_SCALE;
> >s.align = StageAlign.TOP_LEFT;
> >var w:Int = Lib.current.stage.stageWidth;
> >var h:Int = Lib.current.stage.stageHeight;
> >layoutManager = new LayoutManager(w, h);
> >layout = layoutManager.getLayout();
> >s.addChild(layout);
> >s.addEventListener(Event.RESIZE, stageResized);
> >}
> >private function stageResized(?e:Event):Void
> >{
> >s.removeChild(layout);
> >layout = null;
> >var w:Int = Lib.current.stage.stageWidth;
> >var h:Int = Lib.current.stage.stageHeight;
> >layoutManager = new LayoutManager(w, h);
> >layout = layoutManager.getLayout();
> >s.addChild(layout);
> >}
> >}
> >
> >which works perfectly in flash, redrawing my layout according to the
> >new stage dimensions as expected. however when i run the jeash output
> >in my browser i get an uncaught TypeError "Cannot call a method
> >'removeChild' of null". so i had a look at jeash's output...
> >
> >Main = function(p) { if( p === $_ ) return; {
> >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >    this.layoutManager = new com.LayoutManager(w,h);
> >    this.layout = this.layoutManager.getLayout();
> >    this.s.addChild(this.layout);
> >
> > this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >}}
> >Main.__name__ = ["Main"];
> >Main.app = null;
> >Main.main = function() {
> >    Main.app = new Main();
> >}
> >Main.prototype.layoutManager = null;
> >Main.prototype.layout = null;
> >Main.prototype.s = null;
> >Main.prototype.stageResized = function(e) {
> >    this.s.removeChild(this.layout);
> >    this.layout = null;
> >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >    this.layoutManager = new com.LayoutManager(w,h);
> >    this.layout = this.layoutManager.getLayout();
> >    this.s.addChild(this.layout);
> >}
> >
> >and the line that is throwing it is
> >"this.s.removeChild(this.layout);", now s is getting set when
> >Main.main() is called as the last line of the jeash JS. why is it null
> >when stageResized is called?
> >
> >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >tried using an init function and waiting 1 second before calling it to
> >see is it really was an execution order thing. i'm pretty stumped
> >though now! i'm just seeing if i can get a simple layout engine that
> >adapts to portrait/landscape and diff size screens going, which i'll
> >then mirror with some html/css for those without flash or canvas
> >support. should end up with the result that content looks nicely
> >formatted no matter what you use to get at it. i'm getting the feeling
> >that it's not possible right now though :(
> >
> >cheers,
> >
> >tom.
>

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

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



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

Re: jeash issues, possible to work around this?

Niel Drummond-3
The problem, I think, is to do with scoping rules and function pointer differences between flash and js. It surprises me a little that it works in flash - in js, if you pass a function pointer as a callback, you lose the context of "this", so the reference to "s" is lost when the stage resize event is called.

You can work around this by putting stageResized as a closure function, or by using haxe's "callback" keyword, or simply by referencing the stage using Lib.current.stage:

Lib.current.stage.removeChild(layout);

- Niel

On Wed, Feb 23, 2011 at 04:39:16PM +0100, tom rhodes wrote:

> i'm still getting the none found error even just returning a new sprite from
> getLayout, here's the original LayoutManager...
>
> class LayoutManager
> {
> private var layoutWidth:Int;
>  private var layoutHeight:Int;
> private var layout:Sprite;
> static inline var goldenRatio:Float = 1.618;
>  private var horizPadding:Int;
> private var verticalPadding:Int;
> private var sectionHorizPadding:Int;
>  private var sectionVertPadding:Int;
> private var contentHeight:Int;
> private var contentWidth:Int;
>      public function new(w:Int, h:Int):Void
> {
> layoutWidth = w;
>  layoutHeight = h;
> layout = new Sprite();
> }
>  public function getLayout():Sprite
> {
>  horizPadding = getGoldenSlice(layoutWidth, 5);
> verticalPadding = getGoldenSlice(layoutHeight, 5);
>  sectionHorizPadding = getGoldenSlice(layoutWidth, 8);
> sectionVertPadding = getGoldenSlice(layoutHeight, 8);
>  layout.x = horizPadding;
> layout.y = verticalPadding;
> contentHeight = layoutHeight - (verticalPadding * 2);
>  contentWidth = layoutWidth - (horizPadding * 2);
> drawLayout(layoutWidth > layoutHeight ? true : false);
>  return layout;
> }
>  private function drawLayout(isLandscape:Bool):Void
> {
>  var contentAreaWidth:Int = isLandscape ? Math.round(contentWidth /
> goldenRatio) - (sectionHorizPadding * 2) : contentWidth;
> var contentAreaHeight:Int = isLandscape ? contentHeight : contentHeight -
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 2);
>  var contentAreaX:Int = isLandscape ? contentWidth - contentAreaWidth : 0;
> var contentAreaY:Int = isLandscape ? 0 : contentHeight - contentAreaHeight +
> sectionVertPadding;
>  var headerAreaWidth:Int = isLandscape ? contentAreaX - (sectionHorizPadding
> * 2) : contentWidth;
>  var headerAreaHeight:Int = isLandscape ? contentHeight -
> Math.round(contentHeight / goldenRatio) - sectionVertPadding :
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 3);
>  var headerAreaX:Int = 0;
> var headerAreaY:Int = 0;
>  var navAreaWidth:Int = isLandscape ? headerAreaWidth : contentWidth;
> var navAreaHeight:Int = isLandscape ? contentHeight - headerAreaHeight -
> sectionVertPadding : Math.round(headerAreaHeight / goldenRatio) -
> sectionVertPadding;
>  var navAreaX:Int = 0;
> var navAreaY:Int = isLandscape ? headerAreaHeight + sectionVertPadding :
> headerAreaHeight + sectionVertPadding;
>  var contentSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(contentAreaWidth, contentAreaHeight);
>  var headerSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(headerAreaWidth, headerAreaHeight);
> var navSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(navAreaWidth, navAreaHeight);
>  contentSectionLayout.drawLayout();
> headerSectionLayout.drawLayout();
>  navSectionLayout.drawLayout();
>  contentSectionLayout.x = contentAreaX;
>  contentSectionLayout.y = contentAreaY;
> layout.addChild(contentSectionLayout);
>  headerSectionLayout.x = headerAreaX;
> headerSectionLayout.y = headerAreaY;
>  layout.addChild(headerSectionLayout);
>  navSectionLayout.x = navAreaX;
>  navSectionLayout.y = navAreaY;
> layout.addChild(navSectionLayout);
> }
>  private function getGoldenSlice(layoutDim:Int, numDivides:Int):Int
> {
>  var w:Float = cast(layoutDim);
> while (numDivides-- > 0) { w /= goldenRatio; };
>  return Math.round(w);
> }
> }
>
> all BasicSectionLayout does for now is draw a rectangle. can't see why
> anything in there would mess with the stage?
>
>
> On 23 February 2011 16:25, tom rhodes <[hidden email]> wrote:
>
> > sweet! lemme check out layoutManager then...
> >
> >
> >
> > On 23 February 2011 16:22, Niel Drummond <[hidden email]>wrote:
> >
> >> I can't reproduce your example as it stands, because you haven't provided
> >> LayoutManager.  The problem is not with initialisation, if I remove the
> >> LayoutManager code, your example works. If I replace LayoutManager.getLayout
> >> with a stub, that returns an empty Sprite, it also works.
> >>
> >> - Niel
> >>
> >> On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> >> > maybe you need to call an init function as in nme/neash.
> >> >
> >> > Am 23.02.2011 14:46, schrieb tom rhodes:
> >> > >Hi all,
> >> > >
> >> > >i'm back on trying to get a simple little flash thing to work in
> >> > >html/canvas with jeash. i'm now calling my stageResized function in
> >> > >the html because of Event.RESIZE not working yet in jeash. my main
> >> > >class is like this...
> >> > >
> >> > >class Main
> >> > >{
> >> > >static private var app:Main;
> >> > >private var layoutManager:LayoutManager;
> >> > >private var layout:Sprite;
> >> > >private var s:Stage;
> >> > >static public function main()
> >> > >{
> >> > >app = new Main();
> >> > >}
> >> > >public function new()
> >> > >{
> >> > >s = Lib.current.stage;
> >> > >s.scaleMode = StageScaleMode.NO_SCALE;
> >> > >s.align = StageAlign.TOP_LEFT;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >s.addEventListener(Event.RESIZE, stageResized);
> >> > >}
> >> > >private function stageResized(?e:Event):Void
> >> > >{
> >> > >s.removeChild(layout);
> >> > >layout = null;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >}
> >> > >}
> >> > >
> >> > >which works perfectly in flash, redrawing my layout according to the
> >> > >new stage dimensions as expected. however when i run the jeash output
> >> > >in my browser i get an uncaught TypeError "Cannot call a method
> >> > >'removeChild' of null". so i had a look at jeash's output...
> >> > >
> >> > >Main = function(p) { if( p === $_ ) return; {
> >> > >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >> > >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >> > >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >
> >> > >
> >> this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >> > >}}
> >> > >Main.__name__ = ["Main"];
> >> > >Main.app = null;
> >> > >Main.main = function() {
> >> > >    Main.app = new Main();
> >> > >}
> >> > >Main.prototype.layoutManager = null;
> >> > >Main.prototype.layout = null;
> >> > >Main.prototype.s = null;
> >> > >Main.prototype.stageResized = function(e) {
> >> > >    this.s.removeChild(this.layout);
> >> > >    this.layout = null;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >}
> >> > >
> >> > >and the line that is throwing it is
> >> > >"this.s.removeChild(this.layout);", now s is getting set when
> >> > >Main.main() is called as the last line of the jeash JS. why is it null
> >> > >when stageResized is called?
> >> > >
> >> > >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >> > >tried using an init function and waiting 1 second before calling it to
> >> > >see is it really was an execution order thing. i'm pretty stumped
> >> > >though now! i'm just seeing if i can get a simple layout engine that
> >> > >adapts to portrait/landscape and diff size screens going, which i'll
> >> > >then mirror with some html/css for those without flash or canvas
> >> > >support. should end up with the result that content looks nicely
> >> > >formatted no matter what you use to get at it. i'm getting the feeling
> >> > >that it's not possible right now though :(
> >> > >
> >> > >cheers,
> >> > >
> >> > >tom.
> >> >
> >>
> >> > --
> >> > haXe - an open source web programming language
> >> > http://haxe.org
> >>
> >> --
> >> haXe - an open source web programming language
> >> http://haxe.org
> >>
> >
> >

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

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

Re: jeash issues, possible to work around this?

tom rhodes
Hi Neil, 

i tried using Lib.current.stage to ref the stage but it still throws the "not found".

interesting you are surprised it works in flash :) setting a private var as a reference to the stage you mean? 

if you have 5 mins i can chuck you a zip of the whole thing, it's really simple. but maybe your answer to the question above might help, do you think my structure is just bound to create problems when targetting JS with jeash?


On 23 February 2011 17:11, Niel Drummond <[hidden email]> wrote:
The problem, I think, is to do with scoping rules and function pointer differences between flash and js. It surprises me a little that it works in flash - in js, if you pass a function pointer as a callback, you lose the context of "this", so the reference to "s" is lost when the stage resize event is called.

You can work around this by putting stageResized as a closure function, or by using haxe's "callback" keyword, or simply by referencing the stage using Lib.current.stage:

Lib.current.stage.removeChild(layout);

- Niel

On Wed, Feb 23, 2011 at 04:39:16PM +0100, tom rhodes wrote:
> i'm still getting the none found error even just returning a new sprite from
> getLayout, here's the original LayoutManager...
>
> class LayoutManager
> {
> private var layoutWidth:Int;
>  private var layoutHeight:Int;
> private var layout:Sprite;
> static inline var goldenRatio:Float = 1.618;
>  private var horizPadding:Int;
> private var verticalPadding:Int;
> private var sectionHorizPadding:Int;
>  private var sectionVertPadding:Int;
> private var contentHeight:Int;
> private var contentWidth:Int;
>      public function new(w:Int, h:Int):Void
> {
> layoutWidth = w;
>  layoutHeight = h;
> layout = new Sprite();
> }
>  public function getLayout():Sprite
> {
>  horizPadding = getGoldenSlice(layoutWidth, 5);
> verticalPadding = getGoldenSlice(layoutHeight, 5);
>  sectionHorizPadding = getGoldenSlice(layoutWidth, 8);
> sectionVertPadding = getGoldenSlice(layoutHeight, 8);
>  layout.x = horizPadding;
> layout.y = verticalPadding;
> contentHeight = layoutHeight - (verticalPadding * 2);
>  contentWidth = layoutWidth - (horizPadding * 2);
> drawLayout(layoutWidth > layoutHeight ? true : false);
>  return layout;
> }
>  private function drawLayout(isLandscape:Bool):Void
> {
>  var contentAreaWidth:Int = isLandscape ? Math.round(contentWidth /
> goldenRatio) - (sectionHorizPadding * 2) : contentWidth;
> var contentAreaHeight:Int = isLandscape ? contentHeight : contentHeight -
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 2);
>  var contentAreaX:Int = isLandscape ? contentWidth - contentAreaWidth : 0;
> var contentAreaY:Int = isLandscape ? 0 : contentHeight - contentAreaHeight +
> sectionVertPadding;
>  var headerAreaWidth:Int = isLandscape ? contentAreaX - (sectionHorizPadding
> * 2) : contentWidth;
>  var headerAreaHeight:Int = isLandscape ? contentHeight -
> Math.round(contentHeight / goldenRatio) - sectionVertPadding :
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 3);
>  var headerAreaX:Int = 0;
> var headerAreaY:Int = 0;
>  var navAreaWidth:Int = isLandscape ? headerAreaWidth : contentWidth;
> var navAreaHeight:Int = isLandscape ? contentHeight - headerAreaHeight -
> sectionVertPadding : Math.round(headerAreaHeight / goldenRatio) -
> sectionVertPadding;
>  var navAreaX:Int = 0;
> var navAreaY:Int = isLandscape ? headerAreaHeight + sectionVertPadding :
> headerAreaHeight + sectionVertPadding;
>  var contentSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(contentAreaWidth, contentAreaHeight);
>  var headerSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(headerAreaWidth, headerAreaHeight);
> var navSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(navAreaWidth, navAreaHeight);
>  contentSectionLayout.drawLayout();
> headerSectionLayout.drawLayout();
>  navSectionLayout.drawLayout();
>  contentSectionLayout.x = contentAreaX;
>  contentSectionLayout.y = contentAreaY;
> layout.addChild(contentSectionLayout);
>  headerSectionLayout.x = headerAreaX;
> headerSectionLayout.y = headerAreaY;
>  layout.addChild(headerSectionLayout);
>  navSectionLayout.x = navAreaX;
>  navSectionLayout.y = navAreaY;
> layout.addChild(navSectionLayout);
> }
>  private function getGoldenSlice(layoutDim:Int, numDivides:Int):Int
> {
>  var w:Float = cast(layoutDim);
> while (numDivides-- > 0) { w /= goldenRatio; };
>  return Math.round(w);
> }
> }
>
> all BasicSectionLayout does for now is draw a rectangle. can't see why
> anything in there would mess with the stage?
>
>
> On 23 February 2011 16:25, tom rhodes <[hidden email]> wrote:
>
> > sweet! lemme check out layoutManager then...
> >
> >
> >
> > On 23 February 2011 16:22, Niel Drummond <[hidden email]>wrote:
> >
> >> I can't reproduce your example as it stands, because you haven't provided
> >> LayoutManager.  The problem is not with initialisation, if I remove the
> >> LayoutManager code, your example works. If I replace LayoutManager.getLayout
> >> with a stub, that returns an empty Sprite, it also works.
> >>
> >> - Niel
> >>
> >> On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> >> > maybe you need to call an init function as in nme/neash.
> >> >
> >> > Am 23.02.2011 14:46, schrieb tom rhodes:
> >> > >Hi all,
> >> > >
> >> > >i'm back on trying to get a simple little flash thing to work in
> >> > >html/canvas with jeash. i'm now calling my stageResized function in
> >> > >the html because of Event.RESIZE not working yet in jeash. my main
> >> > >class is like this...
> >> > >
> >> > >class Main
> >> > >{
> >> > >static private var app:Main;
> >> > >private var layoutManager:LayoutManager;
> >> > >private var layout:Sprite;
> >> > >private var s:Stage;
> >> > >static public function main()
> >> > >{
> >> > >app = new Main();
> >> > >}
> >> > >public function new()
> >> > >{
> >> > >s = Lib.current.stage;
> >> > >s.scaleMode = StageScaleMode.NO_SCALE;
> >> > >s.align = StageAlign.TOP_LEFT;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >s.addEventListener(Event.RESIZE, stageResized);
> >> > >}
> >> > >private function stageResized(?e:Event):Void
> >> > >{
> >> > >s.removeChild(layout);
> >> > >layout = null;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >}
> >> > >}
> >> > >
> >> > >which works perfectly in flash, redrawing my layout according to the
> >> > >new stage dimensions as expected. however when i run the jeash output
> >> > >in my browser i get an uncaught TypeError "Cannot call a method
> >> > >'removeChild' of null". so i had a look at jeash's output...
> >> > >
> >> > >Main = function(p) { if( p === $_ ) return; {
> >> > >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >> > >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >> > >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >
> >> > >
> >> this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >> > >}}
> >> > >Main.__name__ = ["Main"];
> >> > >Main.app = null;
> >> > >Main.main = function() {
> >> > >    Main.app = new Main();
> >> > >}
> >> > >Main.prototype.layoutManager = null;
> >> > >Main.prototype.layout = null;
> >> > >Main.prototype.s = null;
> >> > >Main.prototype.stageResized = function(e) {
> >> > >    this.s.removeChild(this.layout);
> >> > >    this.layout = null;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >}
> >> > >
> >> > >and the line that is throwing it is
> >> > >"this.s.removeChild(this.layout);", now s is getting set when
> >> > >Main.main() is called as the last line of the jeash JS. why is it null
> >> > >when stageResized is called?
> >> > >
> >> > >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >> > >tried using an init function and waiting 1 second before calling it to
> >> > >see is it really was an execution order thing. i'm pretty stumped
> >> > >though now! i'm just seeing if i can get a simple layout engine that
> >> > >adapts to portrait/landscape and diff size screens going, which i'll
> >> > >then mirror with some html/css for those without flash or canvas
> >> > >support. should end up with the result that content looks nicely
> >> > >formatted no matter what you use to get at it. i'm getting the feeling
> >> > >that it's not possible right now though :(
> >> > >
> >> > >cheers,
> >> > >
> >> > >tom.
> >> >
> >>
> >> > --
> >> > haXe - an open source web programming language
> >> > http://haxe.org
> >>
> >> --
> >> haXe - an open source web programming language
> >> http://haxe.org
> >>
> >
> >

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

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


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

Re: jeash issues, possible to work around this?

MartinLindelof
maybe you could reference it a static var.

static var APP_STAGE : Stage;

-- 
Martin Lindelöf
www.medborgarplatsen.com

On Wednesday, February 23, 2011 at 5:26 PM, tom rhodes wrote:

Hi Neil, 

i tried using Lib.current.stage to ref the stage but it still throws the "not found".

interesting you are surprised it works in flash :) setting a private var as a reference to the stage you mean? 

if you have 5 mins i can chuck you a zip of the whole thing, it's really simple. but maybe your answer to the question above might help, do you think my structure is just bound to create problems when targetting JS with jeash?


On 23 February 2011 17:11, Niel Drummond <[hidden email]> wrote:
The problem, I think, is to do with scoping rules and function pointer differences between flash and js. It surprises me a little that it works in flash - in js, if you pass a function pointer as a callback, you lose the context of "this", so the reference to "s" is lost when the stage resize event is called.

You can work around this by putting stageResized as a closure function, or by using haxe's "callback" keyword, or simply by referencing the stage using Lib.current.stage:

Lib.current.stage.removeChild(layout);

- Niel

On Wed, Feb 23, 2011 at 04:39:16PM +0100, tom rhodes wrote:
> i'm still getting the none found error even just returning a new sprite from
> getLayout, here's the original LayoutManager...
>
> class LayoutManager
> {
> private var layoutWidth:Int;
>  private var layoutHeight:Int;
> private var layout:Sprite;
> static inline var goldenRatio:Float = 1.618;
>  private var horizPadding:Int;
> private var verticalPadding:Int;
> private var sectionHorizPadding:Int;
>  private var sectionVertPadding:Int;
> private var contentHeight:Int;
> private var contentWidth:Int;
>      public function new(w:Int, h:Int):Void
> {
> layoutWidth = w;
>  layoutHeight = h;
> layout = new Sprite();
> }
>  public function getLayout():Sprite
> {
>  horizPadding = getGoldenSlice(layoutWidth, 5);
> verticalPadding = getGoldenSlice(layoutHeight, 5);
>  sectionHorizPadding = getGoldenSlice(layoutWidth, 8);
> sectionVertPadding = getGoldenSlice(layoutHeight, 8);
>  layout.x = horizPadding;
> layout.y = verticalPadding;
> contentHeight = layoutHeight - (verticalPadding * 2);
>  contentWidth = layoutWidth - (horizPadding * 2);
> drawLayout(layoutWidth > layoutHeight ? true : false);
>  return layout;
> }
>  private function drawLayout(isLandscape:Bool):Void
> {
>  var contentAreaWidth:Int = isLandscape ? Math.round(contentWidth /
> goldenRatio) - (sectionHorizPadding * 2) : contentWidth;
> var contentAreaHeight:Int = isLandscape ? contentHeight : contentHeight -
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 2);
>  var contentAreaX:Int = isLandscape ? contentWidth - contentAreaWidth : 0;
> var contentAreaY:Int = isLandscape ? 0 : contentHeight - contentAreaHeight +
> sectionVertPadding;
>  var headerAreaWidth:Int = isLandscape ? contentAreaX - (sectionHorizPadding
> * 2) : contentWidth;
>  var headerAreaHeight:Int = isLandscape ? contentHeight -
> Math.round(contentHeight / goldenRatio) - sectionVertPadding :
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 3);
>  var headerAreaX:Int = 0;
> var headerAreaY:Int = 0;
>  var navAreaWidth:Int = isLandscape ? headerAreaWidth : contentWidth;
> var navAreaHeight:Int = isLandscape ? contentHeight - headerAreaHeight -
> sectionVertPadding : Math.round(headerAreaHeight / goldenRatio) -
> sectionVertPadding;
>  var navAreaX:Int = 0;
> var navAreaY:Int = isLandscape ? headerAreaHeight + sectionVertPadding :
> headerAreaHeight + sectionVertPadding;
>  var contentSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(contentAreaWidth, contentAreaHeight);
>  var headerSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(headerAreaWidth, headerAreaHeight);
> var navSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(navAreaWidth, navAreaHeight);
>  contentSectionLayout.drawLayout();
> headerSectionLayout.drawLayout();
>  navSectionLayout.drawLayout();
>  contentSectionLayout.x = contentAreaX;
>  contentSectionLayout.y = contentAreaY;
> layout.addChild(contentSectionLayout);
>  headerSectionLayout.x = headerAreaX;
> headerSectionLayout.y = headerAreaY;
>  layout.addChild(headerSectionLayout);
>  navSectionLayout.x = navAreaX;
>  navSectionLayout.y = navAreaY;
> layout.addChild(navSectionLayout);
> }
>  private function getGoldenSlice(layoutDim:Int, numDivides:Int):Int
> {
>  var w:Float = cast(layoutDim);
> while (numDivides-- > 0) { w /= goldenRatio; };
>  return Math.round(w);
> }
> }
>
> all BasicSectionLayout does for now is draw a rectangle. can't see why
> anything in there would mess with the stage?
>
>
> On 23 February 2011 16:25, tom rhodes <[hidden email]> wrote:
>
> > sweet! lemme check out layoutManager then...
> >
> >
> >
> > On 23 February 2011 16:22, Niel Drummond <[hidden email]>wrote:
> >
> >> I can't reproduce your example as it stands, because you haven't provided
> >> LayoutManager.  The problem is not with initialisation, if I remove the
> >> LayoutManager code, your example works. If I replace LayoutManager.getLayout
> >> with a stub, that returns an empty Sprite, it also works.
> >>
> >> - Niel
> >>
> >> On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> >> > maybe you need to call an init function as in nme/neash.
> >> >
> >> > Am 23.02.2011 14:46, schrieb tom rhodes:
> >> > >Hi all,
> >> > >
> >> > >i'm back on trying to get a simple little flash thing to work in
> >> > >html/canvas with jeash. i'm now calling my stageResized function in
> >> > >the html because of Event.RESIZE not working yet in jeash. my main
> >> > >class is like this...
> >> > >
> >> > >class Main
> >> > >{
> >> > >static private var app:Main;
> >> > >private var layoutManager:LayoutManager;
> >> > >private var layout:Sprite;
> >> > >private var s:Stage;
> >> > >static public function main()
> >> > >{
> >> > >app = new Main();
> >> > >}
> >> > >public function new()
> >> > >{
> >> > >s = Lib.current.stage;
> >> > >s.scaleMode = StageScaleMode.NO_SCALE;
> >> > >s.align = StageAlign.TOP_LEFT;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >s.addEventListener(Event.RESIZE, stageResized);
> >> > >}
> >> > >private function stageResized(?e:Event):Void
> >> > >{
> >> > >s.removeChild(layout);
> >> > >layout = null;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >}
> >> > >}
> >> > >
> >> > >which works perfectly in flash, redrawing my layout according to the
> >> > >new stage dimensions as expected. however when i run the jeash output
> >> > >in my browser i get an uncaught TypeError "Cannot call a method
> >> > >'removeChild' of null". so i had a look at jeash's output...
> >> > >
> >> > >Main = function(p) { if( p === $_ ) return; {
> >> > >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >> > >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >> > >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >
> >> > >
> >> this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >> > >}}
> >> > >Main.__name__ = ["Main"];
> >> > >Main.app = null;
> >> > >Main.main = function() {
> >> > >    Main.app = new Main();
> >> > >}
> >> > >Main.prototype.layoutManager = null;
> >> > >Main.prototype.layout = null;
> >> > >Main.prototype.s = null;
> >> > >Main.prototype.stageResized = function(e) {
> >> > >    this.s.removeChild(this.layout);
> >> > >    this.layout = null;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >}
> >> > >
> >> > >and the line that is throwing it is
> >> > >"this.s.removeChild(this.layout);", now s is getting set when
> >> > >Main.main() is called as the last line of the jeash JS. why is it null
> >> > >when stageResized is called?
> >> > >
> >> > >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >> > >tried using an init function and waiting 1 second before calling it to
> >> > >see is it really was an execution order thing. i'm pretty stumped
> >> > >though now! i'm just seeing if i can get a simple layout engine that
> >> > >adapts to portrait/landscape and diff size screens going, which i'll
> >> > >then mirror with some html/css for those without flash or canvas
> >> > >support. should end up with the result that content looks nicely
> >> > >formatted no matter what you use to get at it. i'm getting the feeling
> >> > >that it's not possible right now though :(
> >> > >
> >> > >cheers,
> >> > >
> >> > >tom.
> >> >
> >>
> >> > --
> >> > haXe - an open source web programming language
> >> > http://haxe.org
> >>
> >> --
> >> haXe - an open source web programming language
> >> http://haxe.org
> >>
> >
> >

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

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

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


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

Re: jeash issues, possible to work around this?

tom rhodes
same result, probably nicer than what i was doing though :)

On 23 February 2011 17:33, Martin Lindelöf <[hidden email]> wrote:
maybe you could reference it a static var.

static var APP_STAGE : Stage;

-- 
Martin Lindelöf
www.medborgarplatsen.com

On Wednesday, February 23, 2011 at 5:26 PM, tom rhodes wrote:

Hi Neil, 

i tried using Lib.current.stage to ref the stage but it still throws the "not found".

interesting you are surprised it works in flash :) setting a private var as a reference to the stage you mean? 

if you have 5 mins i can chuck you a zip of the whole thing, it's really simple. but maybe your answer to the question above might help, do you think my structure is just bound to create problems when targetting JS with jeash?


On 23 February 2011 17:11, Niel Drummond <[hidden email]> wrote:
The problem, I think, is to do with scoping rules and function pointer differences between flash and js. It surprises me a little that it works in flash - in js, if you pass a function pointer as a callback, you lose the context of "this", so the reference to "s" is lost when the stage resize event is called.

You can work around this by putting stageResized as a closure function, or by using haxe's "callback" keyword, or simply by referencing the stage using Lib.current.stage:

Lib.current.stage.removeChild(layout);

- Niel

On Wed, Feb 23, 2011 at 04:39:16PM +0100, tom rhodes wrote:
> i'm still getting the none found error even just returning a new sprite from
> getLayout, here's the original LayoutManager...
>
> class LayoutManager
> {
> private var layoutWidth:Int;
>  private var layoutHeight:Int;
> private var layout:Sprite;
> static inline var goldenRatio:Float = 1.618;
>  private var horizPadding:Int;
> private var verticalPadding:Int;
> private var sectionHorizPadding:Int;
>  private var sectionVertPadding:Int;
> private var contentHeight:Int;
> private var contentWidth:Int;
>      public function new(w:Int, h:Int):Void
> {
> layoutWidth = w;
>  layoutHeight = h;
> layout = new Sprite();
> }
>  public function getLayout():Sprite
> {
>  horizPadding = getGoldenSlice(layoutWidth, 5);
> verticalPadding = getGoldenSlice(layoutHeight, 5);
>  sectionHorizPadding = getGoldenSlice(layoutWidth, 8);
> sectionVertPadding = getGoldenSlice(layoutHeight, 8);
>  layout.x = horizPadding;
> layout.y = verticalPadding;
> contentHeight = layoutHeight - (verticalPadding * 2);
>  contentWidth = layoutWidth - (horizPadding * 2);
> drawLayout(layoutWidth > layoutHeight ? true : false);
>  return layout;
> }
>  private function drawLayout(isLandscape:Bool):Void
> {
>  var contentAreaWidth:Int = isLandscape ? Math.round(contentWidth /
> goldenRatio) - (sectionHorizPadding * 2) : contentWidth;
> var contentAreaHeight:Int = isLandscape ? contentHeight : contentHeight -
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 2);
>  var contentAreaX:Int = isLandscape ? contentWidth - contentAreaWidth : 0;
> var contentAreaY:Int = isLandscape ? 0 : contentHeight - contentAreaHeight +
> sectionVertPadding;
>  var headerAreaWidth:Int = isLandscape ? contentAreaX - (sectionHorizPadding
> * 2) : contentWidth;
>  var headerAreaHeight:Int = isLandscape ? contentHeight -
> Math.round(contentHeight / goldenRatio) - sectionVertPadding :
> getGoldenSlice(Math.round(contentHeight / goldenRatio), 3);
>  var headerAreaX:Int = 0;
> var headerAreaY:Int = 0;
>  var navAreaWidth:Int = isLandscape ? headerAreaWidth : contentWidth;
> var navAreaHeight:Int = isLandscape ? contentHeight - headerAreaHeight -
> sectionVertPadding : Math.round(headerAreaHeight / goldenRatio) -
> sectionVertPadding;
>  var navAreaX:Int = 0;
> var navAreaY:Int = isLandscape ? headerAreaHeight + sectionVertPadding :
> headerAreaHeight + sectionVertPadding;
>  var contentSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(contentAreaWidth, contentAreaHeight);
>  var headerSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(headerAreaWidth, headerAreaHeight);
> var navSectionLayout:BasicSectionLayout = new
> BasicSectionLayout(navAreaWidth, navAreaHeight);
>  contentSectionLayout.drawLayout();
> headerSectionLayout.drawLayout();
>  navSectionLayout.drawLayout();
>  contentSectionLayout.x = contentAreaX;
>  contentSectionLayout.y = contentAreaY;
> layout.addChild(contentSectionLayout);
>  headerSectionLayout.x = headerAreaX;
> headerSectionLayout.y = headerAreaY;
>  layout.addChild(headerSectionLayout);
>  navSectionLayout.x = navAreaX;
>  navSectionLayout.y = navAreaY;
> layout.addChild(navSectionLayout);
> }
>  private function getGoldenSlice(layoutDim:Int, numDivides:Int):Int
> {
>  var w:Float = cast(layoutDim);
> while (numDivides-- > 0) { w /= goldenRatio; };
>  return Math.round(w);
> }
> }
>
> all BasicSectionLayout does for now is draw a rectangle. can't see why
> anything in there would mess with the stage?
>
>
> On 23 February 2011 16:25, tom rhodes <[hidden email]> wrote:
>
> > sweet! lemme check out layoutManager then...
> >
> >
> >
> > On 23 February 2011 16:22, Niel Drummond <[hidden email]>wrote:
> >
> >> I can't reproduce your example as it stands, because you haven't provided
> >> LayoutManager.  The problem is not with initialisation, if I remove the
> >> LayoutManager code, your example works. If I replace LayoutManager.getLayout
> >> with a stub, that returns an empty Sprite, it also works.
> >>
> >> - Niel
> >>
> >> On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> >> > maybe you need to call an init function as in nme/neash.
> >> >
> >> > Am 23.02.2011 14:46, schrieb tom rhodes:
> >> > >Hi all,
> >> > >
> >> > >i'm back on trying to get a simple little flash thing to work in
> >> > >html/canvas with jeash. i'm now calling my stageResized function in
> >> > >the html because of Event.RESIZE not working yet in jeash. my main
> >> > >class is like this...
> >> > >
> >> > >class Main
> >> > >{
> >> > >static private var app:Main;
> >> > >private var layoutManager:LayoutManager;
> >> > >private var layout:Sprite;
> >> > >private var s:Stage;
> >> > >static public function main()
> >> > >{
> >> > >app = new Main();
> >> > >}
> >> > >public function new()
> >> > >{
> >> > >s = Lib.current.stage;
> >> > >s.scaleMode = StageScaleMode.NO_SCALE;
> >> > >s.align = StageAlign.TOP_LEFT;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >s.addEventListener(Event.RESIZE, stageResized);
> >> > >}
> >> > >private function stageResized(?e:Event):Void
> >> > >{
> >> > >s.removeChild(layout);
> >> > >layout = null;
> >> > >var w:Int = Lib.current.stage.stageWidth;
> >> > >var h:Int = Lib.current.stage.stageHeight;
> >> > >layoutManager = new LayoutManager(w, h);
> >> > >layout = layoutManager.getLayout();
> >> > >s.addChild(layout);
> >> > >}
> >> > >}
> >> > >
> >> > >which works perfectly in flash, redrawing my layout according to the
> >> > >new stage dimensions as expected. however when i run the jeash output
> >> > >in my browser i get an uncaught TypeError "Cannot call a method
> >> > >'removeChild' of null". so i had a look at jeash's output...
> >> > >
> >> > >Main = function(p) { if( p === $_ ) return; {
> >> > >    this.s = jeash.Lib.jeashGetCurrent().GetStage();
> >> > >    this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> >> > >    this.s.align = jeash.display.StageAlign.TOP_LEFT;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >
> >> > >
> >> this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> >> > >}}
> >> > >Main.__name__ = ["Main"];
> >> > >Main.app = null;
> >> > >Main.main = function() {
> >> > >    Main.app = new Main();
> >> > >}
> >> > >Main.prototype.layoutManager = null;
> >> > >Main.prototype.layout = null;
> >> > >Main.prototype.s = null;
> >> > >Main.prototype.stageResized = function(e) {
> >> > >    this.s.removeChild(this.layout);
> >> > >    this.layout = null;
> >> > >    var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> >> > >    var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> >> > >    this.layoutManager = new com.LayoutManager(w,h);
> >> > >    this.layout = this.layoutManager.getLayout();
> >> > >    this.s.addChild(this.layout);
> >> > >}
> >> > >
> >> > >and the line that is throwing it is
> >> > >"this.s.removeChild(this.layout);", now s is getting set when
> >> > >Main.main() is called as the last line of the jeash JS. why is it null
> >> > >when stageResized is called?
> >> > >
> >> > >i've tried moving "Main,prototype.layout = null" to no effect, i also
> >> > >tried using an init function and waiting 1 second before calling it to
> >> > >see is it really was an execution order thing. i'm pretty stumped
> >> > >though now! i'm just seeing if i can get a simple layout engine that
> >> > >adapts to portrait/landscape and diff size screens going, which i'll
> >> > >then mirror with some html/css for those without flash or canvas
> >> > >support. should end up with the result that content looks nicely
> >> > >formatted no matter what you use to get at it. i'm getting the feeling
> >> > >that it's not possible right now though :(
> >> > >
> >> > >cheers,
> >> > >
> >> > >tom.
> >> >
> >>
> >> > --
> >> > haXe - an open source web programming language
> >> > http://haxe.org
> >>
> >> --
> >> haXe - an open source web programming language
> >> http://haxe.org
> >>
> >
> >

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

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

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


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


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

Re: jeash issues, possible to work around this?

Niel Drummond-3
In reply to this post by MartinLindelof
yeah, send me the zip, i'll take a look - also try the latest jeash updates, i've committed a patch which delays the resize event call until the first render pass. i guess my comment on function pointers is a bit nonsense afterall, because i forget haxe correctly makes a closure out of the reference.

- Niel

On Wed, Feb 23, 2011 at 05:33:26PM +0100, Martin Lindel??f wrote:

> maybe you could reference it a static var.
>
> static var APP_STAGE : Stage;
> --
> Martin Lindel??f
> www.medborgarplatsen.com
> On Wednesday, February 23, 2011 at 5:26 PM, tom rhodes wrote:
> > Hi Neil,
> >
> > i tried using Lib.current.stage to ref the stage but it still throws the "not found".
> >
> > interesting you are surprised it works in flash :) setting a private var as a reference to the stage you mean?
> >
> > if you have 5 mins i can chuck you a zip of the whole thing, it's really simple. but maybe your answer to the question above might help, do you think my structure is just bound to create problems when targetting JS with jeash?
> >
> >
> > On 23 February 2011 17:11, Niel Drummond <[hidden email]> wrote:
> > >  The problem, I think, is to do with scoping rules and function pointer differences between flash and js. It surprises me a little that it works in flash - in js, if you pass a function pointer as a callback, you lose the context of "this", so the reference to "s" is lost when the stage resize event is called.
> > >
> > >  You can work around this by putting stageResized as a closure function, or by using haxe's "callback" keyword, or simply by referencing the stage using Lib.current.stage:
> > >
> > >  Lib.current.stage.removeChild(layout);
> > >
> > >  - Niel
> > >
> > >  On Wed, Feb 23, 2011 at 04:39:16PM +0100, tom rhodes wrote:
> > > > i'm still getting the none found error even just returning a new sprite from
> > > > getLayout, here's the original LayoutManager...
> > > >
> > > > class LayoutManager
> > > > {
> > > > private var layoutWidth:Int;
> > > > private var layoutHeight:Int;
> > > > private var layout:Sprite;
> > > > static inline var goldenRatio:Float = 1.618;
> > > > private var horizPadding:Int;
> > > > private var verticalPadding:Int;
> > > > private var sectionHorizPadding:Int;
> > > > private var sectionVertPadding:Int;
> > > > private var contentHeight:Int;
> > > > private var contentWidth:Int;
> > > > public function new(w:Int, h:Int):Void
> > > > {
> > > > layoutWidth = w;
> > > > layoutHeight = h;
> > > > layout = new Sprite();
> > > > }
> > > > public function getLayout():Sprite
> > > > {
> > > > horizPadding = getGoldenSlice(layoutWidth, 5);
> > > > verticalPadding = getGoldenSlice(layoutHeight, 5);
> > > > sectionHorizPadding = getGoldenSlice(layoutWidth, 8);
> > > > sectionVertPadding = getGoldenSlice(layoutHeight, 8);
> > > > layout.x = horizPadding;
> > > > layout.y = verticalPadding;
> > > > contentHeight = layoutHeight - (verticalPadding * 2);
> > > > contentWidth = layoutWidth - (horizPadding * 2);
> > > > drawLayout(layoutWidth > layoutHeight ? true : false);
> > > > return layout;
> > > > }
> > > > private function drawLayout(isLandscape:Bool):Void
> > > > {
> > > > var contentAreaWidth:Int = isLandscape ? Math.round(contentWidth /
> > > > goldenRatio) - (sectionHorizPadding * 2) : contentWidth;
> > > > var contentAreaHeight:Int = isLandscape ? contentHeight : contentHeight -
> > > > getGoldenSlice(Math.round(contentHeight / goldenRatio), 2);
> > > > var contentAreaX:Int = isLandscape ? contentWidth - contentAreaWidth : 0;
> > > > var contentAreaY:Int = isLandscape ? 0 : contentHeight - contentAreaHeight +
> > > > sectionVertPadding;
> > > > var headerAreaWidth:Int = isLandscape ? contentAreaX - (sectionHorizPadding
> > > > * 2) : contentWidth;
> > > > var headerAreaHeight:Int = isLandscape ? contentHeight -
> > > > Math.round(contentHeight / goldenRatio) - sectionVertPadding :
> > > > getGoldenSlice(Math.round(contentHeight / goldenRatio), 3);
> > > > var headerAreaX:Int = 0;
> > > > var headerAreaY:Int = 0;
> > > > var navAreaWidth:Int = isLandscape ? headerAreaWidth : contentWidth;
> > > > var navAreaHeight:Int = isLandscape ? contentHeight - headerAreaHeight -
> > > > sectionVertPadding : Math.round(headerAreaHeight / goldenRatio) -
> > > > sectionVertPadding;
> > > > var navAreaX:Int = 0;
> > > > var navAreaY:Int = isLandscape ? headerAreaHeight + sectionVertPadding :
> > > > headerAreaHeight + sectionVertPadding;
> > > > var contentSectionLayout:BasicSectionLayout = new
> > > > BasicSectionLayout(contentAreaWidth, contentAreaHeight);
> > > > var headerSectionLayout:BasicSectionLayout = new
> > > > BasicSectionLayout(headerAreaWidth, headerAreaHeight);
> > > > var navSectionLayout:BasicSectionLayout = new
> > > > BasicSectionLayout(navAreaWidth, navAreaHeight);
> > > > contentSectionLayout.drawLayout();
> > > > headerSectionLayout.drawLayout();
> > > > navSectionLayout.drawLayout();
> > > > contentSectionLayout.x = contentAreaX;
> > > > contentSectionLayout.y = contentAreaY;
> > > > layout.addChild(contentSectionLayout);
> > > > headerSectionLayout.x = headerAreaX;
> > > > headerSectionLayout.y = headerAreaY;
> > > > layout.addChild(headerSectionLayout);
> > > > navSectionLayout.x = navAreaX;
> > > > navSectionLayout.y = navAreaY;
> > > > layout.addChild(navSectionLayout);
> > > > }
> > > > private function getGoldenSlice(layoutDim:Int, numDivides:Int):Int
> > > > {
> > > > var w:Float = cast(layoutDim);
> > > > while (numDivides-- > 0) { w /= goldenRatio; };
> > > > return Math.round(w);
> > > > }
> > > > }
> > > >
> > > > all BasicSectionLayout does for now is draw a rectangle. can't see why
> > > > anything in there would mess with the stage?
> > > >
> > > >
> > > > On 23 February 2011 16:25, tom rhodes <[hidden email]> wrote:
> > > >
> > > > > sweet! lemme check out layoutManager then...
> > > > >
> > > > >
> > > > >
> > > > > On 23 February 2011 16:22, Niel Drummond <[hidden email]>wrote:
> > > > >
> > > > >> I can't reproduce your example as it stands, because you haven't provided
> > > > >> LayoutManager. The problem is not with initialisation, if I remove the
> > > > >> LayoutManager code, your example works. If I replace LayoutManager.getLayout
> > > > >> with a stub, that returns an empty Sprite, it also works.
> > > > >>
> > > > >> - Niel
> > > > >>
> > > > >> On Wed, Feb 23, 2011 at 04:02:50PM +0100, Heinz H?lzer wrote:
> > > > >> > maybe you need to call an init function as in nme/neash.
> > > > >> >
> > > > >> > Am 23.02.2011 14:46, schrieb tom rhodes:
> > > > >> > >Hi all,
> > > > >> > >
> > > > >> > >i'm back on trying to get a simple little flash thing to work in
> > > > >> > >html/canvas with jeash. i'm now calling my stageResized function in
> > > > >> > >the html because of Event.RESIZE not working yet in jeash. my main
> > > > >> > >class is like this...
> > > > >> > >
> > > > >> > >class Main
> > > > >> > >{
> > > > >> > >static private var app:Main;
> > > > >> > >private var layoutManager:LayoutManager;
> > > > >> > >private var layout:Sprite;
> > > > >> > >private var s:Stage;
> > > > >> > >static public function main()
> > > > >> > >{
> > > > >> > >app = new Main();
> > > > >> > >}
> > > > >> > >public function new()
> > > > >> > >{
> > > > >> > >s = Lib.current.stage;
> > > > >> > >s.scaleMode = StageScaleMode.NO_SCALE;
> > > > >> > >s.align = StageAlign.TOP_LEFT;
> > > > >> > >var w:Int = Lib.current.stage.stageWidth;
> > > > >> > >var h:Int = Lib.current.stage.stageHeight;
> > > > >> > >layoutManager = new LayoutManager(w, h);
> > > > >> > >layout = layoutManager.getLayout();
> > > > >> > >s.addChild(layout);
> > > > >> > >s.addEventListener(Event.RESIZE, stageResized);
> > > > >> > >}
> > > > >> > >private function stageResized(?e:Event):Void
> > > > >> > >{
> > > > >> > >s.removeChild(layout);
> > > > >> > >layout = null;
> > > > >> > >var w:Int = Lib.current.stage.stageWidth;
> > > > >> > >var h:Int = Lib.current.stage.stageHeight;
> > > > >> > >layoutManager = new LayoutManager(w, h);
> > > > >> > >layout = layoutManager.getLayout();
> > > > >> > >s.addChild(layout);
> > > > >> > >}
> > > > >> > >}
> > > > >> > >
> > > > >> > >which works perfectly in flash, redrawing my layout according to the
> > > > >> > >new stage dimensions as expected. however when i run the jeash output
> > > > >> > >in my browser i get an uncaught TypeError "Cannot call a method
> > > > >> > >'removeChild' of null". so i had a look at jeash's output...
> > > > >> > >
> > > > >> > >Main = function(p) { if( p === $_ ) return; {
> > > > >> > > this.s = jeash.Lib.jeashGetCurrent().GetStage();
> > > > >> > > this.s.scaleMode = jeash.display.StageScaleMode.NO_SCALE;
> > > > >> > > this.s.align = jeash.display.StageAlign.TOP_LEFT;
> > > > >> > > var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> > > > >> > > var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> > > > >> > > this.layoutManager = new com.LayoutManager(w,h);
> > > > >> > > this.layout = this.layoutManager.getLayout();
> > > > >> > > this.s.addChild(this.layout);
> > > > >> > >
> > > > >> > >
> > > > >> this.s.addEventListener(jeash.events.Event.RESIZE,$closure(this,"stageResized"));
> > > > >> > >}}
> > > > >> > >Main.__name__ = ["Main"];
> > > > >> > >Main.app = null;
> > > > >> > >Main.main = function() {
> > > > >> > > Main.app = new Main();
> > > > >> > >}
> > > > >> > >Main.prototype.layoutManager = null;
> > > > >> > >Main.prototype.layout = null;
> > > > >> > >Main.prototype.s = null;
> > > > >> > >Main.prototype.stageResized = function(e) {
> > > > >> > > this.s.removeChild(this.layout);
> > > > >> > > this.layout = null;
> > > > >> > > var w = jeash.Lib.jeashGetCurrent().GetStage().GetStageWidth();
> > > > >> > > var h = jeash.Lib.jeashGetCurrent().GetStage().GetStageHeight();
> > > > >> > > this.layoutManager = new com.LayoutManager(w,h);
> > > > >> > > this.layout = this.layoutManager.getLayout();
> > > > >> > > this.s.addChild(this.layout);
> > > > >> > >}
> > > > >> > >
> > > > >> > >and the line that is throwing it is
> > > > >> > >"this.s.removeChild(this.layout);", now s is getting set when
> > > > >> > >Main.main() is called as the last line of the jeash JS. why is it null
> > > > >> > >when stageResized is called?
> > > > >> > >
> > > > >> > >i've tried moving "Main,prototype.layout = null" to no effect, i also
> > > > >> > >tried using an init function and waiting 1 second before calling it to
> > > > >> > >see is it really was an execution order thing. i'm pretty stumped
> > > > >> > >though now! i'm just seeing if i can get a simple layout engine that
> > > > >> > >adapts to portrait/landscape and diff size screens going, which i'll
> > > > >> > >then mirror with some html/css for those without flash or canvas
> > > > >> > >support. should end up with the result that content looks nicely
> > > > >> > >formatted no matter what you use to get at it. i'm getting the feeling
> > > > >> > >that it's not possible right now though :(
> > > > >> > >
> > > > >> > >cheers,
> > > > >> > >
> > > > >> > >tom.
> > > > >> >
> > > > >>
> > > > >> > --
> > > > >> > haXe - an open source web programming language
> > > > >> > http://haxe.org
> > > > >>
> > > > >> --
> > > > >> haXe - an open source web programming language
> > > > >> http://haxe.org
> > > > >>
> > > > >
> > > > >
> > >
> > > > --
> > > > haXe - an open source web programming language
> > > > http://haxe.org
> > >
> > >  --
> > >  haXe - an open source web programming language
> > > http://haxe.org
> > >
> > --
> > haXe - an open source web programming language
> > http://haxe.org
> >

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

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