A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Centering the stage in a NativeWindow

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    9

    Centering the stage in a NativeWindow

    I'm using AIR for the first time for its NativeWindow capability.

    I'm having trouble with the positioning of objects within the NativeWindow. So my code below creates a NativeWindow, and then draws a rectangle and adds it to the stage of the NativeWindow. I can't seem to have the rectangle centered in the window. I've tryed playing with the stage scale mode, and align properties. By default the align should be center, but it doesn't appear to be the case. The rectangle seems to be drawn from somewhere between the center and top left of the window. I've also drawn a rectangle onto the main app window using identical code. Check the jpeg to see what im talking about!

    Code:
    import flash.display.NativeWindowInitOptions;
    import flash.display.NativeWindow;
    
    var NWIO = new NativeWindowInitOptions();
    var NW:NativeWindow = new NativeWindow(NWIO);
    NW.stage.scaleMode = StageScaleMode.NO_SCALE;
    NW.activate();
    NW.width = 500;
    NW.height = 500;
    
    var mc4:MovieClip = new MovieClip();
    mc4.graphics.lineStyle(0);
    mc4.graphics.beginFill(0x736633);
    mc4.graphics.drawRect(0,0,500,500);
    mc4.graphics.endFill();
    NW.stage.addChild(mc4);
    
    var mc1:MovieClip = new MovieClip();
    mc1.graphics.lineStyle(0);
    mc1.graphics.beginFill(0x736633);
    mc1.graphics.drawRect(0,0,500,500);
    mc1.graphics.endFill();
    stage.addChild(mc1);
    http://postimage.org/image/1jqz3vp9g/

    Left window is the main app, and the right window is the NativeWindow.

    Any help would be greatly appreciated, i'm sure there is something very simple i'm missing!

    Danny.
    Last edited by DW2011DW; 08-04-2011 at 06:07 AM.

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    well i use something like

    PHP Code:
    containerMc.= (stage.stageWidth containerMC.width)/2
    containerMC
    .y=  (stage.stageHeight -containerMC.height)/
    This is just a rough example you may have to divide stage.stageWidth and height in two but thats dependent upon where your registration point is on the containerMC
    ~calmchess~

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    9
    I'm talking about the stage itself being off center in the NativeWindow. So if i add an object to the native window at points 0 and 0 - It should display in the top left of the image but instead is closer to the center of the stage. The exact same code adds the object to the top left of the main application window.

    I think it may have something to do with the StageScaleMode because if i change this to SHOW_ALL then its closer to being correct but i don't want the contents of the window to scale up!

  4. #4
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    navtive window? do you mean the browser window? I use a combination of SWFObject and CSS to center the flash player in a browser window. plz explain what you mean by native window more throughly plz.
    ~calmchess~

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    9
    I'm creating an Adobe AIR application. NativeWindow is a class that allows you to open a secondary/+ window with the desktop based application. The nativeWindow has its own stage. This stage's 0x and 0y points do not appear to be at the top left of the window like in the main application or a flash projector.

  6. #6
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    oh yeah I'm sorry I answered without actually reading your post. I don't know AIR really. Sorry for mucking up your post. Please forgive me.
    ~calmchess~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center