I would like to do in AS3 inside a package to align left and forbid stage scaling.
Here is my code:
[SWF(width="640", height="480", frameRate="31", backgroundColor="0x000000")]
public class Main extends Sprite
{
This code works but I would like to not to use the first line and prefer to do something like this:
stage.scaleMode = StageScaleMode.NO_SCALE;
But this fails to compile.
I would like to dynamically set the stage width and height.
Unfortunately you cannot change your SWF's width and height dynamically. This is done when compiling.
You can adjust stageWidth and stageHeight, but they will only affect the appearance of your graphics when you change the scaleMode and the align properties.
Related
I have a 800px600px flash app that has a fullscreen button. When doing fullscreen, the height gets fixed on my monitor, but there is a lot of "overflow", or "extra space" to the sides.
Is there a way to hide this extra space, other than adding a "window" movieclip on the of the movie?
(The blackened space is the movie area, I want to hide everything to the left and right of that area.)
EDIT: What I want is not to change the position/size of the stage/work area, but instead to get something that hides whatever is going on outside of the suposed window(800x600). Something like a "mask" to show only what is going on in that square.
check out the fullScreenSourceRect property of the Stage. That clips the stage to only what you want to show in full screen view. It may look pixelated though, depending on how small that source rect is.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#fullScreenSourceRect
Do not quite understand your question, but see if it helps you:
If you are using Event.RESIZE, you can change the size and position of objects in the x and y screen flash, so:
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.dispatchEvent(new Event(Event.RESIZE));
stage.addEventListener(Event.RESIZE, alterarPosicao);
function alterarPosicao(e:Event):void {
fundo_escuro.width = stage.stageWidth;
fundo_escuro.height = stage.stageHeight;
}
Thus, whatever the resolution of the project, the objects are aligned to the stage.
Hugs!
I ended up fixing the problem by just drawing a huge yellow (same color as background) square around the stage and leaving a empty area in the middle for the actual app to show.
It may be a bit "silly" solution, but it got the job done.
I have a JFrame that I am sticking a JPanel into to display an image, in this case 1024x1025. The problem I cannot seem to find an answer to is how to ensure my containing JFrame will display the whole image/JPanel. I have something close to this example:
ImagePanel view = new ImagePanel(); //extends JPanel
JFrame Container = new JFrame();
view.setSize(1024, 1025);
container = new JFrame(winTitle);
container.setLayout(new BorderLayout());
container.setSize(view.getSize());
container.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
container.add(view);
container.setVisible(true);
The problem with this obviously is that the JFrame is decorated by the underlying OS, so I have no idea how many pixels to make it larger than the size of the JPanel from system to system. As it is now, the image is cut off on the right and bottom by a handful of pixels each due to the setting of the JFrame to the same size as the JPanel. Is there a way to tell the JFrame to read the size of the Jpanel it is containing and make itself large enough to display the entire JPanel? Thanks!
EDIT
Setting preferred size on the image panels, then setting size (not preferred) on the container, then packing after the add gives me the behavior I was wanting. Can anyone explain whats going on here, I still am a bit fuzzy on order of operations by some swing components.
You should add the image panel to the contentPane of the JFrame. And you should just use pack() on the frame to make it take the appropriate size. It will take the size needed to accomodate the preferred size of its components.
After the container.add() and before the container.setVisible(), add a container.pack().
EDIT: You could also use Box.createVerticalStrut(int) and Box.createHorizontalStrut(int) in one of the sides of your BorderLayout. That should force the layout to leave room for the image.
If you are sure about the Image resolution, then use setPreferredSize(new Dimension(1024, 1025)) for the JFrame and also for the JPanel. Since JFrame uses BorderLayout by default, you dont need to specify container.setLayout(new BorderLayout());.
I am making a Class that extends JFrame and have my custom background image on it..
I have two problems..
1) I want my background image to stay fixed sized that covers whole screen when maximized. How can I do that?
2) I want to add a transparent button and panels on the frame that does not disturb my background. Is there any easy way to do that?
help will be greatly appreciated... thank you
Load the image into a BufferedImage.
Add a ComponentListener to determine when the frame is resized. Use the frame size to calculate scaling and call BufferedImage.getScaledImage(xScale, yScale) to obtain a scaled image.
In your class you should be overriding paintBackground() to do the painting. Just call g.drawImage(scaledImage, getWidth(), getHeight(), this) to paint the image.
Any components you add to the frame need to call setOpaque(false) so the background gets painted underneath them.
I have a pure code Actionscript 3 project in flash builder 4 and I want to align the stage.
For now I have a sprite that I have set the x property to 10, but the sprites are in the middle of the screen. How to set these kind of properties in code? I suppose it's the stage object that needs to be set in some way.
You should have a look at the Stage.align property.
For example, if you want to align your Stage depending the top left corner :
stage.align = StageAlign.TOP_LEFT;
Make sure the stage is available though...
I'm creating a simple AIR app with resize-functionality. Of course i need to position a resize-arrow to the bottom-right corner. Here's my code:
stage.addEventListener(Event.RESIZE, handleResize);
function handleResize(e:Event):void{
resize_btn.y = stage.stageHeight-resize_btn.height;
}
This doesn't work, my button gets out of the window very quickly. How could I make this work?
Martti Laine
I think you forgot to set the stage scale and align modes.
Therefore, when you resize, the button goes to the desired Y but as the stage is centered it goes offscreen, giving the idea it's not working.
Try using this:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Does it fall out of the window vertically or horizontally?
You might want to set
resize_btn.x = stage.stageWidth-resize_btn.width;
this may be your problem.