Finding the width of a component

I'm using the file below to load a series of images into a container named containerSprite. The size of each image will vary and I want to be able to calculate the width of the container so I can place navigation buttons relative to the position of containerSprite. My code does not work when the first image is loaded-- when I use trace("WIDTH="+containerSprite.width) I get 0 the first time through.
How or where should I set up an event listener that will fire only when the image has finished loading.
Thanks for helping me think through this process.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()" >
    <mx:Script>
        <![CDATA[
            import mvc.SlideShowTextView;
            import flash.display.*;
            import flash.events.*;
            import flash.net.URLRequest;
            import mvc.SlideShowModel;
            import mvc.SlideShowView;
            import mvc.Model;
            import mvc.View;
            import flash.text.TextField;
            private var slideModel:SlideShowModel;
            private var slideView:SlideShowView;
            private var textView:SlideShowTextView;
            private var req:URLRequest=new URLRequest("data.xml");
            private var containerSprite:Sprite;
            private var s:Shape;
            private var titleText:TextField
            private var numbersText:TextField
            private function init():void{
                titleText=new TextField;
                numbersText=new TextField;
                containerSprite=new Sprite;
                containerSprite.addEventListener(MouseEvent.CLICK, containerClicked)
                s=new Shape;
                containerSprite.addChild(s)
                holder.addChild(containerSprite)
                holder.addChild(titleText)
                holder.addChild(numbersText)
                slideView=new SlideShowView(containerSprite);
                slideModel=new SlideShowModel;
                textView=new SlideShowTextView(titleText,numbersText);
                slideView.model=slideModel;
                textView.model=slideModel;
                slideModel.addEventListener(Model.MODEL_CHANGE, dataChanged);
                slideModel.load(req);
                titleText.x=0//containerSprite.x
                titleText.y=500//containerSprite.y+containerSprite.height+10
                numbersText.x=500//containerSprite.x+containerSprite.width-100
                numbersText.y=titleText.y
            private function dataChanged(event:Event):void{
                trace("WIDTH="+containerSprite.width)
            private function containerClicked(event:MouseEvent):void{
                slideModel.setCurrentIndex(slideModel.currentIndex+1)
        ]]>
    </mx:Script>
<mx:UIComponent id="holder"  horizontalCenter="-250" />
</mx:Application>

You will need to catch the Event.COMPLETE from each Image
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui

Similar Messages

  • Finding the width of a JPEG loaded into a movie clip

    I will be loading a page of bio information. Next to the
    person's photo (photos will vary in width) I want to put a column
    of buttons about 20 pixels to the right of the photo. So after I
    load the photo into an empty movie clip, I'm trying to get the
    width of the photo in order to figure out the x position of the
    buttons next to it. Here is what I have:
    myImage = "images/" + _level0.images[link];
    loadMovie(myImage,image_mc);
    // JPEG loads okay into image_mc //
    trace("image_mc._x = " + image_mc._x);
    // I get "Image_mc._x = 393" as expected //
    trace("myImage._width = " + myImage._width);
    // I get "image_mc._width = undefined" //
    trace("image_mc._width = " + image_mc._width);
    // I get "image_mc._width = 0" //
    How do I find the width of the loaded JPEG?

    you are probably trying to get the width before the image has
    loaded completely.. use the MovieClipLoader class to load the image
    into the empty movie clip, then use the onLoadInit event to get the
    movie clips's width(which is the images width);
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    var myListener:Object = new Object();
    myListener.onLoadInit = function(target:MovieClip):Void{
    trace(image_mc._width);
    mcLoader.addListener(myListener);
    mcLoader.loadClip(myImage, image_mc);

  • Finding the width and height of an image

    Hi...
    i have a path to an image "images/me.gif" and i'm trying to find its width and height.. am trying to use javax.swing.ImageIcon but it refuses to recognise the constructor with just the filename (string) parameter, and needs a URL to the file... anyone knows what i'm doing wrong??? is this the wrong class that i'm using...!??!?!?!?!?

    String filename = "images/me.gif";
    Image myImage = carregarImagem(filename);
    System.out.println(myImage.getWidth(this));
    System.out.println(myImage.getHeight(this));
    * M�todo que carrega imagens na mem�ria, a partir da URL onde o
    * applet est� sendo carregado. O uso de um 'mediaTracker' � fundamental para
    * evitar problemas quanto � velocidade de carga de uma imagem. Se voc� n�o
    * usar um mediaTracker, o seu c�digo pode tentar usar uma imagem antes dela
    * estar plenamente carregada na mem�ria, o que causaria um erro de execu��o.
    * @param nomeDaImagem O nome da imagem a ser carregada
    * @return A imagem requisitada ou null caso n�o haja tal imagem na url do applet
    public Image carregarImagem(String nomeDaImagem)
                   try
                                   Image imagem = getImage(getDocumentBase(), nomeDaImagem);
                                   MediaTracker carregador = new MediaTracker(this);
                                   carregador.addImage(imagem, 0);
                                   carregador.waitForID(0);
                                   return imagem;
                   catch(Exception erro)
                                   erro.printStackTrace();
                                   System.exit(0);
                                   return null;

  • Where can I find the DCOM Connector Logon Component?

    Hello,
    I successfully installed the DCOM Connector (from CD SAP GUI for windows 6.20).
    But where can I find the Logon Component?
    As far as I understand the online documentation, this component is based on, but not included in the DCOM Connector.
    (I have used the Logon Control ocx, but need some features of the newer Logon Component.)
    <b>Yes, I know, it is outdated</b> and no longer supported by SAP, but I really need it.
    Where on CD or online can I find it?
    Thanks for any hint!
    Regards
    Steffi

    Dear Steffi,
    Kindly let us know, for what exactly U required the connector compo.
    Regards,
    Shaibaz

  • Finding the 'Width Tool' within Adobe Flash Professional CS6

    Hello there, I'm new onto the software; Adobe Flash Professional CS6, and hoping to find some answers onto this community.
    I would like to know how to get access with the 'Width Tool', that I've notice I don't have available onto my tool panel.
    I have also check with 'Customize Tools Panel' and it doesn't seem it exist...
                                                                               Top                                                                                                                                                                                     Bottom
    Any pointer or help with much appreciated.
    - Robert

    Now that the Adobe Download Assistant is installed you can initiate the download from http://www.adobe.com/cfusion/tdrc/index.cfm?product=flash.  If this is not sending the download information to the Adobe Download Assistant then please try a different web browser.

  • How do I find the width of an external swf file that I am loading in

    I have loaded in an external swf file and it works fine.
    However, when I get the width dimensions of the movieclip that is housing the external swf file it gives me a '0' for the width.
    Thanks for your time.

    you must wait until loading is complete before trying to access the loaded objects width.  at that point you can determine the width,height of the onstage/backstage objects in frame 1 of the loaded swf.

  • Find the width of a text string inside a text box?

    Hi,
    I have a text box with a long text string in it. I would like to know what the width of the text string is so that I can scroll it inside the textbox using the text box scrollviewer.
    var sv = this.foodieItemText.GetFirstDescendantOfType<ScrollViewer>();
    sv.ScrollToHorizontalOffsetWithAnimation(this.foodieItemText.Width, 20);
    The scrolling works fine but I don't know what value to use for the width offset in the first argument to ScrollToHorizontalOffsetWithAnimation. For my purposes I want it to scroll the full length of the text string (which is longer than the actual with of
    the text box). Any ideas?

    Hi duffybr,
    Yes, there is a ScrollViewer inside TextBox template and we could scroll to the specific position as we need, however there is no direct way to get the string width in TextBox, however we could get the width in TextBlock, by measure method.
    See this discussion for more information:
    http://stackoverflow.com/questions/9126076/how-can-i-calculate-the-width-of-a-string-in-metro-without-displaying-it
    Besides, there are some third party libraries help us get the String width.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Find the Window that a component is being displayed inside of?

    Hello all. I need to find out if a component is being displayed inside of a Window (or JWindow/Frame/JFrame). I need to get the reference for the window component that the component is in.
    I've tried using various combinations of methods in SwingUtilities, as well as Component.getParent(), etc., and can't seem to be able to get what I am looking for.
    For example, I have a JPanel nested inside of another JPanel that is nested inside of a JFrame, and I want to get a reference of the JFrame. If I use a getParent() call recursively I only get to the parent JPanel, and not to the JFrame.
    I'm trying to write a generic method in my extended JPanel class that determines if its sitting inside of a Window/JWindow/Frame/JFrame, and if so, if the window has a JMenuBar. Specifically I'm trying to get a list of all JMenu objects that a window may have that my JPanel subclass is sitting inside (don't want to assign a mnemonic value if its already being used by a JMenu object).
    Any advice/information would be appreciated. Thank you in advance for your time.

    Yeah, but when the human being runs the app, they see
    my panel inside of the window of the application they
    are running! :pThe only explanation I can think of is if you're running as an applet it will appear in firefox or IE or whatever but have no window ancestor.
    Try doing
    Container con = getParent();
    while (!(con instanceof Window) con = con.getParent();It sounds like you've got some silly bug somewhere...

  • Finding the URL of a Component

    Which package/procedure can be used to return the url or session id of an application component?

    Could you elaborate on what you are trying to do? I mean, you could use the URL calls found in the Interface Calls (on the Manage Screen) for things like Dynamic Pages, Reports, etc, but you might have something a little more complicated in mind.
    Rich

  • Is it possible to find the Width of a control before he's displayed ?

    Hi all,
    I have a simple question : Is there any way to compute the size of a control (Label in my case..) before showing it in the scene ?
    Thanks before,
    Jonathan

    Here is another workaround:
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.DepthTest;
    import javafx.scene.Group;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.stage.Stage;
    import javafx.scene.layout.*;
    import javafx.geometry.Pos;
    import javafx.geometry.VPos;
    import javafx.scene.effect.BlendMode;
    public class NodeLength extends Application {
        public static void main(String[] args) {
            Application.launch(args);
        public double getNodeWith(Node n) {
            Stage st = new Stage();
            Group g = new Group();
            g.getChildren().add(n);
            Scene scenex = new Scene(g);
            st.setScene(scenex);
            st.show();
            st.hide();
            return n.getBoundsInLocal().getWidth();
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Hello World");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250);
            TextField username = new TextField();
            username.setPromptText("Username");
            double d = getNodeWith(username);
            System.out.println("d = " + d);
            root.getChildren().add(username);
            primaryStage.setScene(scene);
            primaryStage.show();
    }

  • Finding the columns width

    Hi,
    Currently I have a BO report. The report has a section, where in it has some columns.
    Currently, I am able to retrieve the columns names and the column types of the report.
    But, now I am trying to retrieve the width of the columns of the section, but am not able to do so.
    However, while creating a new report I am able to set the column width.
    Can, you please guide me how can I find the width of columns in a report.
    Regards,
    Shruti

    Hi Shruti,
    Are you referring to something like the following?
    SimpleTable boSimpleTable = (SimpleTable) reportBlock.getRepresentation();
    CellMatrix boCellMatrix = boSimpleTable.getHeader(null);
    TableCell boTableCell = null;
    for (int i=0; i<boCellMatrix.getColumnCount(); i++) {
         boTableCell = boCellMatrix.getCell(0, i);
         boTableCell.setHeight(15.0);
         boTableCell.setWidth(25.0);
    Hope this helps.
    Regards,
    Dan

  • How to change the width for af:selectManyShuttle by skins

    i need to change the width for selectManyShuttle by skin i can do that by change the width for .AFFieldText but this method change the all select* and textfiled width,so i just want to change the width for selectManyShuttle component.
    and i hope to know how to change the header color for selectManyShuttle ,the default color for it is green.

    Thanks ,It is working
    Could you please tell me how to change the header text color for af:selectManyShuttle
    Regards
    Wish79

  • How can I control the width of an inputText and commandButton components

    I need to set the width for both &lt;af:inputText/&gt; and &lt;af: CommandButton/&gt; , but I couldn&rsquo;t find the width property in the &ldquo;Property inspector&rdquo; for them, Is there a way to do it ? Thanks.

    Msrping,
    Always mention the Version of Jdeveloper which you are using.
    If you are using Jdeveloper 11.1.1.0.1 than try this:
    <af:inputText/> :: Goto Property Inspector > Appearance > Column(Set the value for this property. ex, 10)
    <af: CommandButton/> :: Goto Property Inspector > style > Box tab > width(Set the value for this property, ex, 50)
    ---Neelmani Jaiswal

  • How to increase or decrease the width of af:inputText

    Hi,
    I want to increase the height & width of the <af:inputText>.
    To increase the Height, i made rows attribute value as "2". But i am not able to increase the width of that component.
    I have increased the "style--> box ---> Width” but it is not working.
    Please help me,
    Thanks in advance.

    Hi user,
    Post your ADF faces questions at
    JDeveloper and ADF
    --Prasanna                                                                                                                                                                                                                                   

  • Where can i find the analytic workspace manager for 11g

    Guys,
    I just downloaded the win32_11gR1_database_1013 from the website, however i did not find the 'analytic workspace manager' component as what the document mentioned during the installation.
    Anybody can help me on this?

    however i did not find the 'analytic workspace manager' component as what the document mentioned during the installation.Could you point us to that documentation?

Maybe you are looking for

  • Can't select , edit or delete extra home directories in WGM - User - Home

    I am trying to get network user accounts set up on a 10.5.8 server. I have set up the server as an OD master, and created the accounts in LDAPv3/127.0.0.1. However, users can not connect from bound client computers. Logging in from >console, gives an

  • Is the 70D significantly better than the 7D at handling high ISO situations?

    I have a 6D and it has really spoiled me with it's low noise high ISO capabilities. I'm wondering if the 70D is significantly better than my 7D when it comes to handling high ISOs. It has the same sensor as the 6D and I really like that view screen o

  • Handling Outer Join for hard coded values in the Logical Table Source

    Has anyone tried to apply an outer join in the Logical Table Source Content Tab? I have to add this APPLSYS.FND_LOOKUP_VALUES.LANGUAGE (+)= 'US' but the outer join is not allowed. I get this message.... [nQSError: 27002] Near <(>: Syntax error [nQSEr

  • Query on Personnel Actions

    I have a few personnel actions like "Trainee Extension", "Probation Extension", where I should allow the user to change the training period or probation period. In which infotype should I store this data, so that I can include it in the corresponding

  • How to run native system method?

    This method definition exists in ObjectInputStream.java: private static native Object allocateNewObject(Class aclass, Class initclass) throws InstantiationException, IllegalAccessException; I want to use this same method. I can compile with the above