ActionScript Flex how to send browser width in swf

I work with flex, but ActionScript ideas are just as good.

The flex <s:Application> has height="100%" width="100%" , so swf is suitable for the browser when resizing the browser.

My problem is that I have a <s:Label> which I need to place based on the real / current browser size.

 <s:Application height="100%" width="100%"> ..... <s:Label text="hello" x="?" y=">" /> </s:Application> 

I heard that you can use Application.application.width; but I get a compilation error that she does not know what it is.

Any ideas how to do this. I am trying to get the current swf size in the browser since the size of the browser is changing.

+6
flex actionscript flash adobe
source share
4 answers

As far as I can tell, the following should work. Application.application is just the same as assuming you are in the base application. Binding should allow resizing after initialization.

 <s:Application height="100%" width="100%"> ..... <s:Label text="hello" x="{width}" y="" /> </s:Application> 

Edit: I just checked and it works. To put your shortcut in the middle of the scene, you just need to do it

 <s:Application height="100%" width="100%"> ..... <s:Label text="hello" x="{width/2}" y="{height/2}" /> </s:Application> 
+3
source share

you can only know the size of the scene, when an element is added inside the scene, you can try eventdelegate, like this

  app.addEventListener (Event.ADDED_TO_STAGE, init);
 private function init (evt: Event): void {
    trace (stage.stageWidth);
    trace (stage.stageHeight);
 }
0
source share

Call javascript function when resizing browser. From there, get a link to swf and call the AS function to resize the label. Pass the width / height of the browser.

See an example here.

UPDATE: Bugfix: ExternalInterface is sent by AS to JS.

0
source share

It is not clear what you are trying to do. x and y are positional elements, width and height are size elements. If you position the shortcut, you should probably use top, left, right and bottom , rather than x and y , if you want it to be the size as the size of the parent control.

If you want the label to be centered, you can use horizontalCenter and verticalCenter .

If you place it inside a layout control, such as panel or canvas , you can just set its left and right to 0 and have the size of the canvas.

If your shortcut is always located elsewhere depending on size, you can override updateDisplayList to set the position. This applies to whether you put it in the layout control or not.

0
source share

All Articles