Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : help! live preview that redraws when resized


sneakyimp
6/15/2004 8:15:04 PM
hi:

i've done searches on this, I've read tutorials at macromedia, and I've
experimented for hours but I haven't had any luck.

I want to make a live preview movie for a component that I've written that
will redraw itself when the user resizes it while authoring so that the objects
on it don't appear stretched. I'm not talking about creating a custom ui here.
The built in Flash MX components do this...scrollpane, combobox, listbox, etc.
You just change their width in the properties in spector and they redraw
themselves so they still look natural (and not stretched) at the new size.

I understand to a limited extent how to share information using the XCH movie
using the onUpdate function, but the onUpdate function is not triggered when
you resize. I've also tried creating an onResize function in my live preview
movie and that also doesn't work. I've tried determining the target path of my
livePreview movie but it doesn't seem to have an instance name (not even a temp
one).

any help you folks could give would be much much appreciated.


ellisn
6/16/2004 9:22:57 AM
This is taken from one of my components live preview swf's linked to a
component which shows what you are after:

Stage.scaleMode = "noScale" // This stops the scaling
myListener = new Object();
myListener.onResize = function () {
preview_mc.width=Stage.width;
preview_mc.height=Stage.height;
preview_mc.arrange(); // This is my function to arrange and scale the graphics
Stage.align = "TL";
}
Stage.addListener(myListener);

Hope this helps

Neil
sneakyimp
6/16/2004 8:46:59 PM
firstly, thanks for your help!

i'm looking at your code and I'm not sure that it's going to help...

firstly, the stage is not getting resized...i'm trying to make my component's
live preview redraw itself when the component instance gets resized. for
instance,
* i've created a component that I export as myPictureLoader
* i put an instance of myPictureLoader on the stage
* i name that instance myPL1
* i select it and resize it using the properties inspector

if this happens, i want myPL1's live preview movie to redraw itself so that it
doesn't appear to be all stretched. The built-in flash components
(FScrollPaneSymbol, FComboBoxSymbol, etc.) do this.

I have no problem getting my component's live preview movie to respond to
changes made via the default parameter editor, but I haven't had any luck at
all triggering the redraw when someone simply resizes it using the properties
inspector.

ALSO...i haven't been able to determine the path to my live preview movie when
i'm authoring in flash. the live preview movie (which, as far as i can tell,
is the thing actually getting resized) doesn't seem to have an instance name or
path that I can discern. I tried creating an onEnterFrame function inside my
live preview movie...i had some limited success here, but i can't get that
onEnterFrame function to locate the live preview's actual height or width on
the stage.


sneakyimp
6/18/2004 8:00:32 PM
MechaFlasher
6/18/2004 9:37:36 PM
I created my components without using Macromedia's UIObject or UIComponent
classes so I don't know if this would help you exactly but it might give you
ideas. In your AS2 class that is registered to your component, you define a
method named setSize. Flash automatically calls this method whenevere the
component is resized on the stage. In that method you would resize/adjust the
graphic elements of your component:

public function setSize(w:Number, h:Number):Void
{
// resize and move your objects here

};

In that code you might have to set the xscale and yscale of the objects back
to 100 to prevent the stretching, I can't remember. Width and height of the new
size are passed to this method by Flash each time it's called.

public function setSize(w:Number, h:Number):Void
{
// resize and move your objects here

};
sneakyimp
6/19/2004 12:18:34 AM
thanks for your help

first, I'm using flash MX...doesn't have AS2

second, my component already has setSize....it's the live preview movie that
I'm trying to fix. My component redraws itself just fine. what I can't seem
to find is the event that gets triggered when someone resizes the component in
authoring mode. I've also tried adding an onEnterFrame function to my live
preview movie but it somehow cannot detect its own size or the fact that it is
scaled.
MechaFlasher
6/19/2004 12:29:51 AM
Sry, never worked with components in MX but I know they're different so yah,
what I said won't help. In 2004 setSize is what is called when the user
resizes in the authoring environment, and they got rid of the Live Preview
thing. Maybe try putting a setSize method in your live preview swf?
sneakyimp
6/19/2004 1:20:15 AM
no need to apologize.

yeah i tried the setSize function in the live preview movie...no dice.

I just cannot locate the right event in the live preview movie to trigger a
redraw. nor can i determine the path relation between the object on your stage
in authoring mode and the live preview movie. I know this is done...the built
in flash components do it. I've been trying to study them but I have no access
to their live preview movies.


ewernli
11/11/2005 11:26:43 AM
I found a page that address this issue:
http://www.kirupa.com/forum/showthread.php?t=75642

They use the Stage to track resizing:

// make sure we update the size of the component
// when the live preview is resized!
function onResize() {
trace("stage resize detected..");
comp_mc.setSize(Stage.width, Stage.height);
}
Stage.addListener(this);

Make sure your stage size in your live preview match your component's size. I
guess that when the user resize the component at design-time, the live preview
actually has its stage size changed, and not the "xch" object. But as both have
the same size, you can propagate the change to the component (named "comp_mc"
here) ...

It worked for me when i was designing a component with an element that always
had to appear centered in the component bounding box.

E.
AddThis Social Bookmark Button