--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote: > > I suggest your renderer look something like this. You'll see use of > dataChange and how to center the image. I don't have a proxy example, > but that's a good topic for a blog article someday... > > Can you post two image swfs that don't center correctly? I want to make > sure those swfs are aligned to topleft otherwise this centering code > won't work for you. > > <mx:Canvas dataChange="mediaObject= data as MediaElement"> > <mx:Script> > private var _mediaObject:MediaElement; > > [Bindable("mediaObjectChanged")] > public function get mediaObject():MediaElement > { > return _mediaObject; > } > > public function set mediaObject(value:MediaElement):void > { > _mediaObject = value; > dispatchEvent(new Event("mediaObjectChanged"); > } > > private function centerImage():void > { > img.x = (width - img.measuredWidth) / 2; > img.y = ??? > } > </mx:Script> > <mx:Image id="img" source="{mediaObject.imgSrc}" > complete="centerImage()" /> > ...
I tried this, and it put the image pretty far away from the upper left corner. I'm guessing that this is because x and y are actually the top left corner and not the center, though the docs are unclear on this. However, even when I corrected it to this: private function centerMe(thing:SWFLoader):void{ thing.x = (width - thing.measuredWidth) / 2 - (thing.measuredWidth/2); thing.y = (height - thing.measuredHeight) / 2 - (thing.measuredHeight/2); } it still puts the image far enough away from the corner to require scroll bars. Any ideas? Thanks; Amy