PDA

View Full Version : can component preview change its size in the Flash editor?


Bax1
12-18-2004, 03:16 PM
Im using MX2002 and Im trying to have a component's preview change the size of its component on the stage.

Im writing a flash component where you can enter an image's filename in the parameters box and then the component loads and displays that image. Works fine.

So I made a preview for the component. And now the image shows up in the flash editor! However I cant seem to change the bounds that are displayed in the editor to match the image Ive loaded. So the bounds remain at the default 20x20 even if the image is much larger.

The problem with this is then the flash editor has all sorts of cosmetic issues. Ill drag the component around - but it will leave bits of the image behind and not update correctly.

Ive tried updating the Stage.width - but its read-only. Ive tried updating xch._width but that doesnt seem to work.

I would think its impossible to do - except something like the scrollbar component seems to do it. When you drop the scrollbar on a textfield it resizes itself to the same height as the textfield - so I *think* its possible to do what I want.

I know there are examples of how to go the other way - that is the user types in a new width and the preview redraws itself to the new size. But I dont think that helps me - I want the reverse.

thanks for any help on this,
Bax

bgx
12-19-2004, 08:25 AM
Hi,

if your component extends mx.core.UIComponent, which I assume,
resizing the actual components dimensions should work as follows:

instead of the normal MC properties "_width" and "_height" you can use "width" and "height" (read only) to determine the actual size.

To set dimensions use the "setSize()" method.

You should be able to determine the width and height of the image once loaded and then use .setSize() to resize the component to match the image dimensions. In fact that is exactly how the Loader component does. If you want check out the file mx.controls.Loader.as in you Flash Directory/Classes folder. Ther are two functions called "doSclaeContent()" and "doScaleLoader()" the latter one does what you want.

Bax1
12-20-2004, 10:36 AM
No, I was not extending mx.core.UIComponent. I was following the tutorial http://www.flashcomponents.net/tutorials/triangle/triangle.html The tutorial example file has the same problem I have - where if you change the triangle 'base' and 'height' in the component parameters to larger than 10 - the triangle gets drawn outside its bounds - and if you try and move it you leave pieces of triangle all over the stage.

So, thanks bgx! I will try extending mx.core.UIComponent. www.bgxcomponents.com looks very impressive btw.

Bax

bgx
12-20-2004, 11:33 AM
Thanks Bax1,

I find the FooterNav example at http://www.macromedia.com/devnet/mx/flash/components/components05.html
very useful to start off with.