flash9 stage?

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

flash9 stage?

brian@huntercreative.com
Hi all,

I guess I am not understanding the relationship between
flash.display.Stage and haxe. In the Flash IDE I can refer to the stage
as 'stage', so if I want to use a reference to the stage it would be
something like: stage.stageWidth or stage.addChild(someKid).
Haxe doesn't seem to like my importing flash.display.Stage, and I can't
seem to access the stage props from a class (or anywhere at the
moment).
Any help would be appreciated.

here is a simple example:

package;

import flash.display.Stage;
import MyClass;

class Entry {

        public var stage:Stage;

        public function new() {
                var circ:MyClass = new MyClass();
                circ.x = stage.stageWidth/2; //does not work
                //etc
                stage.addChild(circ);//nope
        }
        public static function main() {
                new Entry();
        }
}


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

Re: flash9 stage?

Joacim Magnusson
Hi,

You can access the stage properties using flash.Lib.current.stage

And when you add displayobjects you can add them directly to flash.Lib.current, so stage.addChild(circ) would be flash.Lib.current.addChild(circ)

So there is really no need to import the Stage class.

/J

On 24 nov 2009, at 16:16, [hidden email] wrote:

> Hi all,
>
> I guess I am not understanding the relationship between flash.display.Stage and haxe. In the Flash IDE I can refer to the stage as 'stage', so if I want to use a reference to the stage it would be something like: stage.stageWidth or stage.addChild(someKid).
> Haxe doesn't seem to like my importing flash.display.Stage, and I can't seem to access the stage props from a class (or anywhere at the moment).
> Any help would be appreciated.
>
> here is a simple example:
>
> package;
>
> import flash.display.Stage;
> import MyClass;
>
> class Entry {
>
> public var stage:Stage;
>
> public function new() {
> var circ:MyClass = new MyClass();
> circ.x = stage.stageWidth/2; //does not work
> //etc
> stage.addChild(circ);//nope
> }
> public static function main() {
> new Entry();
> }
> }
>
>
> --
> 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: flash9 stage?

jlm@justinfront.net
In reply to this post by brian@huntercreative.com
There is a stage property of any MovieClip...
  so

var stage = Lib.current.stage

so you could also do
> var circ:MyClass = new MyClass();
> circ.x = circ.stage.stageWidth/2;
> //etc
> Lib.current.addChild(circ);

I think.

Cheers

;j


On 24 Nov 2009, at 15:16, [hidden email] wrote:

> Hi all,
>
> I guess I am not understanding the relationship between  
> flash.display.Stage and haxe. In the Flash IDE I can refer to the  
> stage as 'stage', so if I want to use a reference to the stage it  
> would be something like: stage.stageWidth or stage.addChild(someKid).
> Haxe doesn't seem to like my importing flash.display.Stage, and I  
> can't seem to access the stage props from a class (or anywhere at  
> the moment).
> Any help would be appreciated.
>
> here is a simple example:
>
> package;
>
> import flash.display.Stage;
> import MyClass;
>
> class Entry {
>
> public var stage:Stage;
>
> public function new() {
> var circ:MyClass = new MyClass();
> circ.x = stage.stageWidth/2; //does not work
> //etc
> stage.addChild(circ);//nope
> }
> public static function main() {
> new Entry();
> }
> }
>
>
> --
> 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: flash9 stage?

Baluta Cristian
In reply to this post by Joacim Magnusson
i was writing things in the same order as you :P
but i will add only that at this line: circ.x = stage.stageWidth/2; //does not work
is not working because the stage was not inited, is null, you only defined it but is not what you thought will be.

On Tue, Nov 24, 2009 at 5:29 PM, Joacim Magnusson <[hidden email]> wrote:
Hi,

You can access the stage properties using flash.Lib.current.stage

And when you add displayobjects you can add them directly to flash.Lib.current, so stage.addChild(circ) would be flash.Lib.current.addChild(circ)

So there is really no need to import the Stage class.

/J

On 24 nov 2009, at 16:16, [hidden email] wrote:

> Hi all,
>
> I guess I am not understanding the relationship between flash.display.Stage and haxe. In the Flash IDE I can refer to the stage as 'stage', so if I want to use a reference to the stage it would be something like: stage.stageWidth or stage.addChild(someKid).
> Haxe doesn't seem to like my importing flash.display.Stage, and I can't seem to access the stage props from a class (or anywhere at the moment).
> Any help would be appreciated.
>
> here is a simple example:
>
> package;
>
> import flash.display.Stage;
> import MyClass;
>
> class Entry {
>
>       public var stage:Stage;
>
>       public function new() {
>               var circ:MyClass = new MyClass();
>               circ.x = stage.stageWidth/2; //does not work
>               //etc
>               stage.addChild(circ);//nope
>       }
>       public static function main() {
>               new Entry();
>       }
> }
>
>
> --
> haXe - an open source web programming language
> http://haxe.org


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



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

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

Re: flash9 stage?

brian@huntercreative.com
Thank you for the responses they have been very informative!


On Nov 24, 2009, at 10:33 AM, Baluta Cristian wrote:

> i was writing things in the same order as you :P
> but i will add only that at this line: circ.x = stage.stageWidth/2;
> //does not work
> is not working because the stage was not inited, is null, you only
> defined it but is not what you thought will be.
>
> On Tue, Nov 24, 2009 at 5:29 PM, Joacim Magnusson
> <[hidden email]> wrote:
>>
>>
>>  You can access the stage properties using flash.Lib.current.stage
>>
>>  And when you add displayobjects you can add them directly to
>> flash.Lib.current, so stage.addChild(circ) would be
>> flash.Lib.current.addChild(circ)
>>
>>  So there is really no need to import the Stage class.
>>
>>  /J
>>
>>  On 24 nov 2009, at 16:16, [hidden email] wrote:
>>
>>  > Hi all,
>>  >
>>  > I guess I am not understanding the relationship between
>> flash.display.Stage and haxe. In the Flash IDE I can refer to the
>> stage as 'stage', so if I want to use a reference to the stage it
>> would be something like: stage.stageWidth or stage.addChild(someKid).
>>  > Haxe doesn't seem to like my importing flash.display.Stage, and I
>> can't seem to access the stage props from a class (or anywhere at the
>> moment).
>>  > Any help would be appreciated.
>>  >
>>  > here is a simple example:
>>  >
>>  > package;
>>  >
>>  > import flash.display.Stage;
>>  > import MyClass;
>>  >
>>  > class Entry {
>>  >
>>  >       public var stage:Stage;
>>  >
>>  >       public function new() {
>>  >               var circ:MyClass = new MyClass();
>>  >               circ.x = stage.stageWidth/2; //does not work
>>  >               //etc
>>  >               stage.addChild(circ);//nope
>>  >       }
>>  >       public static function main() {
>>  >               new Entry();
>>  >       }
>>  > }
>>  >
>>  >
>>  > --
>>  > haXe - an open source web programming language
>>  > http://haxe.org
>>
>>
>>  --
>>  haXe - an open source web programming language
>> http://haxe.org
>
>
>
> --
> Băluță Cristian
> http://ralcr.com
> http://imagin.ro
> --
> 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: flash9 stage?

Gamehaxe
In reply to this post by Baluta Cristian
The stage is a little tricky because you often derive your main
object from a DisplayObject, which has a property "stage", which
is only set when you "addChild" your main object to the stage.

So if you do:

class Main {
public function new()
{
    stage.addChild(new Shape(....));

it will not compile, because "stage" is not defined, BUT it you do:


class Main extends Sprite {
...

it will compile, but it will crash, because the "stage" property is null
until you "addChild" it.  The "correct" (well, most likely) is :


class Main extends Sprite {
public function new()
{
    flash.Lib.current.stage.addChild(this);
    // Now this will work, because WE are on the stage ...
    stage.addChild(new Shape(....));

If you "extend" a DisplayObject (eg, Sprite, Shape, MovieClip) you should
not add a variable (or member variable) called "stage" because this would
get confused with the property of the same name.

Haxe automatically adds the "flash.Lib.current" object to the stage, and
you use this object to bootstrap yourself onto the stage, then you
carry on as a "normal" main class would in an AS3 proj (which automatically
get added to the stage).

Hope this makes things a bit clearer.

Hugh








> i was writing things in the same order as you :P
> but i will add only that at this line: circ.x = stage.stageWidth/2;  
> //does
> not work
> is not working because the stage was not inited, is null, you only  
> defined
> it but is not what you thought will be.
>
> On Tue, Nov 24, 2009 at 5:29 PM, Joacim Magnusson  
> <[hidden email]>wrote:
>
>> Hi,
>>
>> You can access the stage properties using flash.Lib.current.stage
>>
>> And when you add displayobjects you can add them directly to
>> flash.Lib.current, so stage.addChild(circ) would be
>> flash.Lib.current.addChild(circ)
>>
>> So there is really no need to import the Stage class.
>>
>> /J
>>
>> On 24 nov 2009, at 16:16, [hidden email] wrote:
>>
>> > Hi all,
>> >
>> > I guess I am not understanding the relationship between
>> flash.display.Stage and haxe. In the Flash IDE I can refer to the stage  
>> as
>> 'stage', so if I want to use a reference to the stage it would be  
>> something
>> like: stage.stageWidth or stage.addChild(someKid).
>> > Haxe doesn't seem to like my importing flash.display.Stage, and I  
>> can't
>> seem to access the stage props from a class (or anywhere at the moment).
>> > Any help would be appreciated.
>> >
>> > here is a simple example:
>> >
>> > package;
>> >
>> > import flash.display.Stage;
>> > import MyClass;
>> >
>> > class Entry {
>> >
>> >       public var stage:Stage;
>> >
>> >       public function new() {
>> >               var circ:MyClass = new MyClass();
>> >               circ.x = stage.stageWidth/2; //does not work
>> >               //etc
>> >               stage.addChild(circ);//nope
>> >       }
>> >       public static function main() {
>> >               new Entry();
>> >       }
>> > }
>> >
>> >
>> > --
>> > 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: flash9 stage?

clemos
Just one more thing :

DisplayObject dispatches an event when it's added to stage :
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#ADDED_TO_STAGE

So to avoid null this.stage or null this.root issues in
DisplayObjects, you can either use flash.Lib.current (like described
by Hugh) or do something like that :

class MyStuff extends Sprite {
   public function new(){
      super();
      if( stage == null ){
         addEventListener(Event.ADDED_TO_STAGE, init);
      }else{
         // I haven't seen many situations where a new Sprite() is
already added to stage, but you never know...
         init();
      }
   }

   public function init(?e:Event=null){
      // this is called when you actually addChild this MyStuff instance
      // here, the MyStuff instance is in the DisplayObject tree, so
you can use this.stage or this.root, etc...
      x = stage.stageWidth / 2;
      y = stage.stageHeight / 2;
   }
}

+++++++
Clément

On Wed, Nov 25, 2009 at 1:18 PM, Hugh Sanderson <[hidden email]> wrote:

> The stage is a little tricky because you often derive your main
> object from a DisplayObject, which has a property "stage", which
> is only set when you "addChild" your main object to the stage.
>
> So if you do:
>
> class Main {
> public function new()
> {
>   stage.addChild(new Shape(....));
>
> it will not compile, because "stage" is not defined, BUT it you do:
>
>
> class Main extends Sprite {
> ...
>
> it will compile, but it will crash, because the "stage" property is null
> until you "addChild" it.  The "correct" (well, most likely) is :
>
>
> class Main extends Sprite {
> public function new()
> {
>   flash.Lib.current.stage.addChild(this);
>   // Now this will work, because WE are on the stage ...
>   stage.addChild(new Shape(....));
>
> If you "extend" a DisplayObject (eg, Sprite, Shape, MovieClip) you should
> not add a variable (or member variable) called "stage" because this would
> get confused with the property of the same name.
>
> Haxe automatically adds the "flash.Lib.current" object to the stage, and
> you use this object to bootstrap yourself onto the stage, then you
> carry on as a "normal" main class would in an AS3 proj (which automatically
> get added to the stage).
>
> Hope this makes things a bit clearer.
>
> Hugh
>
>
>
>
>
>
>
>
>> i was writing things in the same order as you :P
>> but i will add only that at this line: circ.x = stage.stageWidth/2; //does
>> not work
>> is not working because the stage was not inited, is null, you only defined
>> it but is not what you thought will be.
>>
>> On Tue, Nov 24, 2009 at 5:29 PM, Joacim Magnusson
>> <[hidden email]>wrote:
>>
>>> Hi,
>>>
>>> You can access the stage properties using flash.Lib.current.stage
>>>
>>> And when you add displayobjects you can add them directly to
>>> flash.Lib.current, so stage.addChild(circ) would be
>>> flash.Lib.current.addChild(circ)
>>>
>>> So there is really no need to import the Stage class.
>>>
>>> /J
>>>
>>> On 24 nov 2009, at 16:16, [hidden email] wrote:
>>>
>>> > Hi all,
>>> >
>>> > I guess I am not understanding the relationship between
>>> flash.display.Stage and haxe. In the Flash IDE I can refer to the stage
>>> as
>>> 'stage', so if I want to use a reference to the stage it would be
>>> something
>>> like: stage.stageWidth or stage.addChild(someKid).
>>> > Haxe doesn't seem to like my importing flash.display.Stage, and I can't
>>> seem to access the stage props from a class (or anywhere at the moment).
>>> > Any help would be appreciated.
>>> >
>>> > here is a simple example:
>>> >
>>> > package;
>>> >
>>> > import flash.display.Stage;
>>> > import MyClass;
>>> >
>>> > class Entry {
>>> >
>>> >       public var stage:Stage;
>>> >
>>> >       public function new() {
>>> >               var circ:MyClass = new MyClass();
>>> >               circ.x = stage.stageWidth/2; //does not work
>>> >               //etc
>>> >               stage.addChild(circ);//nope
>>> >       }
>>> >       public static function main() {
>>> >               new Entry();
>>> >       }
>>> > }
>>> >
>>> >
>>> > --
>>> > 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: flash9 stage?

Pimm Hogeling
Clemos is correct.

Though I hardly ever use the stage property of the DisplayObject class (it shouldn't have been there in the first place in my opinion), if I want to do so on construction I listen to the Event.ADDED_TO_STAGE events. However, Clemos also says "I haven't seen many situations where a new Sprite() is already added to stage, but you never know...", which isn't exactly true. You do know. Since there is no way to add an object to a container before creating it. Therefore this is enough:
class SpriteExtender extends Sprite {
    public function new():Void {
        super();
        addEventListener(Event.ADDED_TO_STAGE, initialize);
    }
    private function initialize(event:Event):Void {
        removeEventListener(Event.ADDED_TO_STAGE, initialize);
       
    }
}

Don't forget to remove the event listener (otherwise you might be initializing the object more than once.)

Good luck.

On Wed, Nov 25, 2009 at 14:42, clemos <[hidden email]> wrote:
Just one more thing :

DisplayObject dispatches an event when it's added to stage :
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#ADDED_TO_STAGE

So to avoid null this.stage or null this.root issues in
DisplayObjects, you can either use flash.Lib.current (like described
by Hugh) or do something like that :

class MyStuff extends Sprite {
  public function new(){
     super();
     if( stage == null ){
        addEventListener(Event.ADDED_TO_STAGE, init);
     }else{
        // I haven't seen many situations where a new Sprite() is
already added to stage, but you never know...
        init();
     }
  }

  public function init(?e:Event=null){
     // this is called when you actually addChild this MyStuff instance
     // here, the MyStuff instance is in the DisplayObject tree, so
you can use this.stage or this.root, etc...
     x = stage.stageWidth / 2;
     y = stage.stageHeight / 2;
  }
}

+++++++
Clément

On Wed, Nov 25, 2009 at 1:18 PM, Hugh Sanderson <[hidden email]> wrote:
> The stage is a little tricky because you often derive your main
> object from a DisplayObject, which has a property "stage", which
> is only set when you "addChild" your main object to the stage.
>
> So if you do:
>
> class Main {
> public function new()
> {
>   stage.addChild(new Shape(....));
>
> it will not compile, because "stage" is not defined, BUT it you do:
>
>
> class Main extends Sprite {
> ...
>
> it will compile, but it will crash, because the "stage" property is null
> until you "addChild" it.  The "correct" (well, most likely) is :
>
>
> class Main extends Sprite {
> public function new()
> {
>   flash.Lib.current.stage.addChild(this);
>   // Now this will work, because WE are on the stage ...
>   stage.addChild(new Shape(....));
>
> If you "extend" a DisplayObject (eg, Sprite, Shape, MovieClip) you should
> not add a variable (or member variable) called "stage" because this would
> get confused with the property of the same name.
>
> Haxe automatically adds the "flash.Lib.current" object to the stage, and
> you use this object to bootstrap yourself onto the stage, then you
> carry on as a "normal" main class would in an AS3 proj (which automatically
> get added to the stage).
>
> Hope this makes things a bit clearer.
>
> Hugh
>
>
>
>
>
>
>
>
>> i was writing things in the same order as you :P
>> but i will add only that at this line: circ.x = stage.stageWidth/2; //does
>> not work
>> is not working because the stage was not inited, is null, you only defined
>> it but is not what you thought will be.
>>
>> On Tue, Nov 24, 2009 at 5:29 PM, Joacim Magnusson
>> <[hidden email]>wrote:
>>
>>> Hi,
>>>
>>> You can access the stage properties using flash.Lib.current.stage
>>>
>>> And when you add displayobjects you can add them directly to
>>> flash.Lib.current, so stage.addChild(circ) would be
>>> flash.Lib.current.addChild(circ)
>>>
>>> So there is really no need to import the Stage class.
>>>
>>> /J
>>>
>>> On 24 nov 2009, at 16:16, [hidden email] wrote:
>>>
>>> > Hi all,
>>> >
>>> > I guess I am not understanding the relationship between
>>> flash.display.Stage and haxe. In the Flash IDE I can refer to the stage
>>> as
>>> 'stage', so if I want to use a reference to the stage it would be
>>> something
>>> like: stage.stageWidth or stage.addChild(someKid).
>>> > Haxe doesn't seem to like my importing flash.display.Stage, and I can't
>>> seem to access the stage props from a class (or anywhere at the moment).
>>> > Any help would be appreciated.
>>> >
>>> > here is a simple example:
>>> >
>>> > package;
>>> >
>>> > import flash.display.Stage;
>>> > import MyClass;
>>> >
>>> > class Entry {
>>> >
>>> >       public var stage:Stage;
>>> >
>>> >       public function new() {
>>> >               var circ:MyClass = new MyClass();
>>> >               circ.x = stage.stageWidth/2; //does not work
>>> >               //etc
>>> >               stage.addChild(circ);//nope
>>> >       }
>>> >       public static function main() {
>>> >               new Entry();
>>> >       }
>>> > }
>>> >
>>> >
>>> > --
>>> > 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: flash9 stage?

clemos
Actually, there *seem* to be *one* situation where the stage is
available from the constructor, but AFAIK it's AS3 only, not haXe.
This *seems* to happen *sometimes* (depending on your cache / browser
/ os / player, ...) in the constructor of the Main class of an AS3
project...
Yes, I know, it's weird, but I lost quite a few hours to figure it out
once, and I won't forget it :).

By the way, I learned about this ADDED_TO_STAGE trick thanks to flashDevelop;
I think it is in the main class template when creating a new project.

Anyway, since haXe seems to do all the dirty job in the backstage, you
know your constructor can never access to this.stage, that's true.

+++++++
Clément

On Wed, Nov 25, 2009 at 3:24 PM, Pimm Hogeling <[hidden email]> wrote:

> Clemos is correct.
>
> Though I hardly ever use the stage property of the DisplayObject class (it
> shouldn't have been there in the first place in my opinion), if I want to do
> so on construction I listen to the Event.ADDED_TO_STAGE events. However,
> Clemos also says "I haven't seen many situations where a new Sprite() is
> already added to stage, but you never know...", which isn't exactly true.
> You do know. Since there is no way to add an object to a container before
> creating it. Therefore this is enough:
> class SpriteExtender extends Sprite {
>     public function new():Void {
>         super();
>         addEventListener(Event.ADDED_TO_STAGE, initialize);
>     }
>     private function initialize(event:Event):Void {
>         removeEventListener(Event.ADDED_TO_STAGE, initialize);
>
>     }
> }
>
> Don't forget to remove the event listener (otherwise you might be
> initializing the object more than once.)
>
> Good luck.
>
> On Wed, Nov 25, 2009 at 14:42, clemos <[hidden email]> wrote:
>>
>> Just one more thing :
>>
>> DisplayObject dispatches an event when it's added to stage :
>>
>> http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#ADDED_TO_STAGE
>>
>> So to avoid null this.stage or null this.root issues in
>> DisplayObjects, you can either use flash.Lib.current (like described
>> by Hugh) or do something like that :
>>
>> class MyStuff extends Sprite {
>>   public function new(){
>>      super();
>>      if( stage == null ){
>>         addEventListener(Event.ADDED_TO_STAGE, init);
>>      }else{
>>         // I haven't seen many situations where a new Sprite() is
>> already added to stage, but you never know...
>>         init();
>>      }
>>   }
>>
>>   public function init(?e:Event=null){
>>      // this is called when you actually addChild this MyStuff instance
>>      // here, the MyStuff instance is in the DisplayObject tree, so
>> you can use this.stage or this.root, etc...
>>      x = stage.stageWidth / 2;
>>      y = stage.stageHeight / 2;
>>   }
>> }
>>
>> +++++++
>> Clément
>>
>> On Wed, Nov 25, 2009 at 1:18 PM, Hugh Sanderson <[hidden email]>
>> wrote:
>> > The stage is a little tricky because you often derive your main
>> > object from a DisplayObject, which has a property "stage", which
>> > is only set when you "addChild" your main object to the stage.
>> >
>> > So if you do:
>> >
>> > class Main {
>> > public function new()
>> > {
>> >   stage.addChild(new Shape(....));
>> >
>> > it will not compile, because "stage" is not defined, BUT it you do:
>> >
>> >
>> > class Main extends Sprite {
>> > ...
>> >
>> > it will compile, but it will crash, because the "stage" property is null
>> > until you "addChild" it.  The "correct" (well, most likely) is :
>> >
>> >
>> > class Main extends Sprite {
>> > public function new()
>> > {
>> >   flash.Lib.current.stage.addChild(this);
>> >   // Now this will work, because WE are on the stage ...
>> >   stage.addChild(new Shape(....));
>> >
>> > If you "extend" a DisplayObject (eg, Sprite, Shape, MovieClip) you
>> > should
>> > not add a variable (or member variable) called "stage" because this
>> > would
>> > get confused with the property of the same name.
>> >
>> > Haxe automatically adds the "flash.Lib.current" object to the stage, and
>> > you use this object to bootstrap yourself onto the stage, then you
>> > carry on as a "normal" main class would in an AS3 proj (which
>> > automatically
>> > get added to the stage).
>> >
>> > Hope this makes things a bit clearer.
>> >
>> > Hugh
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >> i was writing things in the same order as you :P
>> >> but i will add only that at this line: circ.x = stage.stageWidth/2;
>> >> //does
>> >> not work
>> >> is not working because the stage was not inited, is null, you only
>> >> defined
>> >> it but is not what you thought will be.
>> >>
>> >> On Tue, Nov 24, 2009 at 5:29 PM, Joacim Magnusson
>> >> <[hidden email]>wrote:
>> >>
>> >>> Hi,
>> >>>
>> >>> You can access the stage properties using flash.Lib.current.stage
>> >>>
>> >>> And when you add displayobjects you can add them directly to
>> >>> flash.Lib.current, so stage.addChild(circ) would be
>> >>> flash.Lib.current.addChild(circ)
>> >>>
>> >>> So there is really no need to import the Stage class.
>> >>>
>> >>> /J
>> >>>
>> >>> On 24 nov 2009, at 16:16, [hidden email] wrote:
>> >>>
>> >>> > Hi all,
>> >>> >
>> >>> > I guess I am not understanding the relationship between
>> >>> flash.display.Stage and haxe. In the Flash IDE I can refer to the
>> >>> stage
>> >>> as
>> >>> 'stage', so if I want to use a reference to the stage it would be
>> >>> something
>> >>> like: stage.stageWidth or stage.addChild(someKid).
>> >>> > Haxe doesn't seem to like my importing flash.display.Stage, and I
>> >>> > can't
>> >>> seem to access the stage props from a class (or anywhere at the
>> >>> moment).
>> >>> > Any help would be appreciated.
>> >>> >
>> >>> > here is a simple example:
>> >>> >
>> >>> > package;
>> >>> >
>> >>> > import flash.display.Stage;
>> >>> > import MyClass;
>> >>> >
>> >>> > class Entry {
>> >>> >
>> >>> >       public var stage:Stage;
>> >>> >
>> >>> >       public function new() {
>> >>> >               var circ:MyClass = new MyClass();
>> >>> >               circ.x = stage.stageWidth/2; //does not work
>> >>> >               //etc
>> >>> >               stage.addChild(circ);//nope
>> >>> >       }
>> >>> >       public static function main() {
>> >>> >               new Entry();
>> >>> >       }
>> >>> > }
>> >>> >
>> >>> >
>> >>> > --
>> >>> > 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: flash9 stage?

Jan_Flanders
In reply to this post by Pimm Hogeling
I think the only child of the stage should be the instance of your document class. If you add other display objects to stage, you create siblings of the instance of your document class which does not sound like a good idea to me.

On Wed, Nov 25, 2009 at 3:24 PM, Pimm Hogeling <[hidden email]> wrote:
Clemos is correct.

Though I hardly ever use the stage property of the DisplayObject class (it shouldn't have been there in the first place in my opinion)

How do you listen for Keyboard events? How do you give focus?

Cheers,
Jan

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

Re: flash9 stage?

Edo Rivai
Most of the time I handle Keyboard events in another object which receives the stage in it's constructor. This object will then signal (hsl) or dispatch events accordingly. Objects that need to know of this Keyboard input should receive this "Keyboard handler" and listen to it's Signals/events.
This way there is only one object that knows of the stage in order to listen to Keyboard events.

Good luck,

Edo

On Wed, Nov 25, 2009 at 3:50 PM, ad nez <[hidden email]> wrote:
I think the only child of the stage should be the instance of your document class. If you add other display objects to stage, you create siblings of the instance of your document class which does not sound like a good idea to me.

On Wed, Nov 25, 2009 at 3:24 PM, Pimm Hogeling <[hidden email]> wrote:
Clemos is correct.

Though I hardly ever use the stage property of the DisplayObject class (it shouldn't have been there in the first place in my opinion)

How do you listen for Keyboard events? How do you give focus?

Cheers,
Jan

--
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: flash9 stage?

Pimm Hogeling
I'd like to add that the object Edo is referring to (an object that handles keyboard input) should not be a DisplayObject, so it uses the stage property of the main class and not that of the base class. If the stage property were only accessible from the main class, that would have been sufficient.

On Wed, Nov 25, 2009 at 16:52, Edo Rivai <[hidden email]> wrote:
Most of the time I handle Keyboard events in another object which receives the stage in it's constructor. This object will then signal (hsl) or dispatch events accordingly. Objects that need to know of this Keyboard input should receive this "Keyboard handler" and listen to it's Signals/events.
This way there is only one object that knows of the stage in order to listen to Keyboard events.

Good luck,

Edo

On Wed, Nov 25, 2009 at 3:50 PM, ad nez <[hidden email]> wrote:
I think the only child of the stage should be the instance of your document class. If you add other display objects to stage, you create siblings of the instance of your document class which does not sound like a good idea to me.

On Wed, Nov 25, 2009 at 3:24 PM, Pimm Hogeling <[hidden email]> wrote:
Clemos is correct.

Though I hardly ever use the stage property of the DisplayObject class (it shouldn't have been there in the first place in my opinion)

How do you listen for Keyboard events? How do you give focus?

Cheers,
Jan

--
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