Here is the code for the image component
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Metadata>
[Event(name="imageLoaded", type="events.ImageLoaded")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import events.ImageLoaded;
import flash.events.Event;
[Bindable]
private var imgsrc:String;
public function loadImage(val:String):void{
imgsrc = "assets/images/"+val;
}
private function imgLoaded(e:Event):void{
trace("w "+e.target.width);
var ed:Object = new Object();
ed.ow = e.target.width;
ed.oh = e.target.height;
var eventUpdateObj:ImageLoaded = new ImageLoaded(ed,
"imageLoaded");
dispatchEvent(eventUpdateObj);
}
]]>
</mx:Script>
<mx:Image id="bImage" source="{imgsrc}" complete="imgLoaded(event)"
width="100%" height="100%" resize="true"/>
</mx:Canvas>
here is the code in the vDividedBox that holds the Image
<mx:VDividedBox xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:is="components.*" paddingTop="1" initialize="init()"
dividerPress="dPress()" dividerRelease="dRelease()"
updateComplete="changeSize(event)" liveDragging="true">
<mx:Script>
<![CDATA[
import events.ImageLoaded;
import mx.events.DividerEvent;
private var dividerY:Number;
private var cHeight:Number;
[Bindable]
private var iUrl:String = "assets/images/L1t1_1.jpg";
[Bindable]
private var txt:String = "This is some text that is in the text
block of the body of the frame work.<br>It is suppose to wrap. but I
need enough text.<br>It need more.<br>and more.<br>and more.<br>and
more.<br>and more.<br>and more.<br>and more.<br>and more.";
private function init():void{
dividerY = this.getChildAt(1).height;
//bHolder.loadPage("http://www.infusion-studios.com");
iHolder.loadImage("L1t1_1.jpg");
}
private function toggleTxt(event:Event):void{
if(event.target.label == "Close"){
dividerY = this.getChildAt(1).height
this.moveDivider(0,this.getChildAt(1).height-20);
event.target.label = "Open";
}else{
this.moveDivider(0,-dividerY);
event.target.label = "Close";
}
}
private function dPress():void{
bHolder.hideBrowser();
}
private function dRelease():void{
if(this.getChildAt(1).height < 22){
trace("cHeight "+this.getChildAt(1).height);
dividerY = 200;
toggle.label = "Open";
}else{
toggle.label = "Close";
}
bHolder.showBrowser();
}
private function changeSize(event:Event):void{
bHolder.setBrowser();
}
private function imageLoaded(event:ImageLoaded):void{
trace("imageLoaded "+this.width/2);
iHolder.x = this.width/2-topPane.width/2
}
]]>
</mx:Script>
<mx:Canvas id="topPane" label="Canvas 1" width="100%" height="100%"
verticalScrollPolicy="off" horizontalScrollPolicy="off">
<is:BrowseHolder id="bHolder"/>
<is:ImageHolder id="iHolder" width="100%" height="100%"
imageLoaded="imageLoaded(event)"/>
</mx:Canvas>
<mx:Canvas id="txtC" label="Canvas 2" width="100%" height="100%"
verticalScrollPolicy="off" horizontalScrollPolicy="off" minHeight="20">
<mx:VBox id="textBlock" width="100%" height="100%"
verticalGap="0" >
<mx:HBox id="bar" width="100%" height="20"
backgroundImage="assets/images/barBg.jpg" backgroundSize="100%"
horizontalGap="0">
<mx:Image source="assets/images/barEnd.jpg"/>
<mx:Spacer width="100%"/>
<mx:LinkButton id="toggle" height="17" label="Close"
click="toggleTxt(event)"/>
</mx:HBox>
<mx:TextArea width="100%" height="100%" htmlText="{txt}"
borderStyle="none" verticalScrollPolicy="auto"/>
</mx:VBox>
</mx:Canvas>
</mx:VDividedBox>
So I am calling the imageLoaded function when the image completes
loading in the component. I figured that is were would need to set the x,y
also since the image scales to fit in the pane, I would need that size,
not the size of the image itself.
Russ
Rich Tretola wrote:
Please post the code that you are using.
Rich
On 1/17/07, *Russell Sprague* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
I hate the flex documentation...
All I want to do is dynamically center an image on my stage.
I have a VDividedBox with an image in the top, and text in the bottom.
I loading in images by setting the source of an image tag(probably
not
the best way to do it, but again I hate the Flex docs...).
So when the image loads I am trying to set it to center in the upper
pane of the vdividedbox, but all my attemps have failed.
It would be nice to also resize the image as the divideBar is
dragged,
but only to the original size of the image, then it just centers.
Thanks
Russ
--
Rich Tretola
<mx:EverythingFlex/>
http://www.EverythingFlex.com <http://www.EverythingFlex.com>