can i change the viewport size dynamically?

Post here your questions about the OpenSpace 1.x or notify bugs and suggestions.

Moderators: Lapo, Bax

Post Reply
hirokimo
Posts: 5
Joined: 17 Nov 2008, 06:57

can i change the viewport size dynamically?

Post by hirokimo »

hi,
i know i could set the os viewport size in component panel,and it works,
but if i want to change the os viewport size dynamically,i mean according to the stage width or something else,is it possible?
thx~~~
morgflast
Posts: 9
Joined: 04 Sep 2008, 15:21

Re: Changing viewport size

Post by morgflast »

I was actually having a similar, simpler problem. I would like to know how to 'statically' resize the viewport for openspace, so that the openspace window is larger than 640x480.

If you happen to have some instructions about how to do this, it would be much appreciated.

Thank you!
morgflast
Posts: 9
Joined: 04 Sep 2008, 15:21

Re: Changing viewport size

Post by morgflast »

To clarify the above post, we are interested in exporting the Openspace libraries as an swc file for Flex to use with a larger viewport.
morgflast wrote:I was actually having a similar, simpler problem. I would like to know how to 'statically' resize the viewport for openspace, so that the openspace window is larger than 640x480.

If you happen to have some instructions about how to do this, it would be much appreciated.

Thank you!
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

hirokimo:
dinamically changing the size of the OpenSpace component is not possible. When initialized, OpenSpace "reads" the viewport size and it can't be changed later.

morgflast:
you need the Flex Component Kit for Flash.
Create a new fla in Flash and drag the FlexComponentBase component to its library.
Then create a new movieclip, set it to be exported for ActionScript and give it a class name (for example OpenSpaceWrapper) and set its base class as mx.flash.UIMovieClip.
Drag the OpenSpace component inside the movieclip and give it an instance name, for example os.
Then create the OpenSpaceWrapper.as class like this:

Code: Select all

package
{
	import mx.flash.UIMovieClip;
	import mx.events.ResizeEvent ;
	
	public class OpenSpaceWrapper extends UIMovieClip
	{
		function OpenSpaceWrapper()
		{
			_width = os.width
			_height = os.height
		}
		
		override public function get measuredWidth():Number 
		{ 
			return os.width
		} 
		
		override public function get measuredHeight():Number 
		{ 
			return os.height
		} 
		
		override public function setActualSize(newWidth:Number, newHeight:Number):void
		{
			if (newWidth != _width || newHeight != _height) 
			{ 
				_width = newWidth
				_height = newHeight
				
				os.setSize(_width,_height)
			}
		}
	}
}
In the end, export the swc following the guidelines of the Flex Component Kit for Flash.
This has not been fully tested, but should do the trick: when you resize the wrapper in Flex, OpenSpace is resized accordingly. Of course what said to hirokimo is still valid: if you resize the wrapper after OpenSpace initialization, the OpenSpace behavior will be messed up.

Important: see this reply below for a possible issue and its workaround
Last edited by Bax on 25 Mar 2009, 16:33, edited 3 times in total.
Paolo Bax
The SmartFoxServer Team
hirokimo
Posts: 5
Joined: 17 Nov 2008, 06:57

Post by hirokimo »

to bax:
ok,i see,it`s unreasonable to change the viewport size when the os componet initialized.

to morgflast:
i`ve tested this way in flex(actionscript project),and it works :P

here`s my step:
1.export a swc file with os componet
2.add the swc into an actionscript project in flex.
3.var os:OpenSpace = new OpenSpace();
4.os.setSize(800,250); or you can, os.setSize(stage.stageWidth,stage.stageHeight);
5.load the os skin,os bg....

and as bax said,the size could not be resized again only if you reload the os.
thx u guys~
Paul Scherbak
Posts: 4
Joined: 23 Feb 2009, 08:09
Location: Ukraine, Kharkiv
Contact:

Post by Paul Scherbak »

Hi!

I create OpenSpace component how is specified above, by means of OpenSpaceWrapper. I use MXML, AS3 in FlashDevelop. The component successfully created, avatars can move, but over tiles there is a white area.
Image

And after a while it is informed on an error:

Code: Select all

ReferenceError: The POWERED BY OPENSPACE text must be visible!
	at com.smartfoxserver.openspace::OpenSpace/com.smartfoxserver.openspace:OpenSpace::onLinkTest()
	at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
	at flash.utils::Timer/flash.utils:Timer::tick()
Help, please...
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Not clear why you have that white rectangle covering OpenSpace. Maybe you can send your code an we will give it a look.

The error is due to the fact that the rectangle partially covers the OpenSpace logo in the top-right corner (this is not allowed when using the evaluation version of OpenSpace).
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

I create OpenSpace component how is specified above, by means of OpenSpaceWrapper. The component successfully created, avatars can move, but over tiles there is a white area.
It took a while, but we have an explanation to this strange behavior. It seems that Flex doesn't like the mask that the OpenSpace component uses internally to hide tiles and background portions outside of the viewport. That white rectangle is the movieclip which "should" become a mask.
The good news is that this issue show up only if you place the OpenSpaceWrapper (see code above) on the stage via ActionScript. If you create it directly inside the mxml and set its width/height, it works like a charm.
This issue has already been fixed in the engine of the next OpenSpace version (under development, please don't ask the release date!), which will be distributed as a Flex native component (side by side with a Flash native component).
Paolo Bax
The SmartFoxServer Team
Paul Scherbak
Posts: 4
Joined: 23 Feb 2009, 08:09
Location: Ukraine, Kharkiv
Contact:

Post by Paul Scherbak »

Thanks, it works!
nig3d
Posts: 164
Joined: 02 Jul 2008, 09:42

Post by nig3d »

one problem I have using flex or flash develop is that I can't compile the code of my avatar.
My avatar is a fla file which a movieclip inheriting from an OS avatar object so I can't compile it with flex.
Do you have some hints about it?
Paul Scherbak
Posts: 4
Joined: 23 Feb 2009, 08:09
Location: Ukraine, Kharkiv
Contact:

Post by Paul Scherbak »

nig3d wrote:one problem I have using flex or flash develop is that I can't compile the code of my avatar.
My avatar is a fla file which a movieclip inheriting from an OS avatar object so I can't compile it with flex.
Do you have some hints about it?
The class an avatar is compiled by "publish" in Flash.
Post Reply