A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: loader.content.width vs loader.width

  1. #1
    Senior Member
    Join Date
    Jan 2009
    Posts
    208

    loader.content.width vs loader.width

    I dont quite get this.
    I am loading an image and after some calculations to proportionally resize image to fit on the stage I trace:

    trace(imageLoader.width / 2);
    trace(imageLoader.content.width / 2);

    //output
    221.425
    221.425

    these two values are the same, which is understandable..

    then I have the option to click on the image and expand it to its full width and height so I can pan it.

    and when the image expands, i trace:

    trace(imageLoader.width / 2);
    trace(imageLoader.content.width / 2);

    //output
    600.5
    221.425

    why are these values now different?

    shouldnt now these both be 600.5 ?

  2. #2

  3. #3
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    thanks, but that still doesnt answer my question...

    shouldnt this two have always the same width and height?

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Adobe site: Creates a Loader object that you can use to load files, such as SWF, JPEG, GIF, or PNG files. Call the load() method to load the asset as a child of the Loader instance.

    Does that help clear it up?

  5. #5
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    no, I dont get it, or maybe you dont get what I am asking, but it doesnt matter...
    thanks anyway

  6. #6
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    You are probably resizing 'imageLoader' or a reference to it. If you resize a displayobject it does not automatically resize all of it's children with it. The .content of a loader is a child of the loader. I don't know how else to put it, hopefully that helps?

  7. #7
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    hm... I have been looking this a little more clearly to see whats actually going on

    when image loads, I do this:

    Code:
    whole_width = imageLoader.content.width;// remember whole picture dimensions
    whole_height = imageLoader.content.height;
    then resize the picture proportionally to fit on stage:

    Code:
    var destinationRatio:Number = (stage.stageWidth) / (stage.stageHeight);
    var targetRatio:Number = imageLoader.content.width / imageLoader.content.height;
    
    if (targetRatio > destinationRatio) {
    imageLoader.content.height = ((stage.stageWidth) / imageLoader.content.width) * imageLoader.content.height;
    imageLoader.content.width = stage.stageWidth;
    } else {
    imageLoader.content.width = ((stage.stageHeight) / imageLoader.content.height) * imageLoader.content.width;
    imageLoader.content.height = stage.stageHeight;
    }
    
    partial_width = imageLoader.content.width;// remember partial picture dimensions
    partial_height = imageLoader.content.height;
    then trace for test:

    Code:
    trace(imageLoader.width);
    trace(imageLoader.height);
    trace(imageLoader.content.width);
    trace(imageLoader.content.height);
    //output:
    787.1500000000001
    590
    787.1500000000001
    590

    Code:
    addChild(imageLoader);
    then later on after I expand it to its full size:

    Code:
    TweenLite.to(imageLoader, 1, {width:whole_width, height:whole_height});
    Code:
    trace(imageLoader.width);
    trace(imageLoader.height);
    trace(imageLoader.content.width);
    trace(imageLoader.content.height);
    //output:
    1600.9
    1199.95
    787.1500000000001
    590

    so it looks to me that imageLoader.content.width and height stay the same size I made it after I resized the picture initially...

    but if loader can have only one child, which is the image I have loaded, then imageLoader.width or ImageLoader.content.width should be the same...

    I dont know, maybe my brain isnt working so perfectly these days...

  8. #8
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Lets say the image you loaded is 256x100 pixels.

    * imageLoader.content.width will be 256
    * imageLoader.content will have scale of 1 (scaleX = scaleY = 1) because that is the default.

    * imageLoader.width will be 256, because that is the total width of all the children (content in this case) when imageLoader.scaleX = 1 (which is the default).

    Now, the important thing to understand is that width and scaleX is just different sides of the same coin. If you change the width property, scaleX will also change to reflect the new width.

    So, setting imageLoader.width=512 means you make imageLoader twice the original width. It is the same thing as if you had written imageLoader.scaleX = 2 (you can verify this by tracing scaleX after you have changed the width)

    Changing size (width/scaleX) of imageLoader does not change the properties of any children (content). So the child "content" will still have the same scaleX and width property value.

    Now, if imageLoader.content.width is 256, that does not necessarily mean it will actually be that size on the screen on pixels. In this case the content will be 512 pixels wide on screen since the parent display object is scaled up, and thus all children is scale up as well when displayed.

    Hope this makes it more clear.
    Last edited by strille; 05-29-2009 at 07:41 AM.

  9. #9
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    so if I want to move the content of the loader like so (and fake the registration point) I will use:

    imageLoader.content.x = - imageLoader.content.width/2;
    imageLoader.content.y = - imageLoader.content.height/2;

    but to manipulate the width and height of the loader the is no reason to use .content. actually ?

    right?

  10. #10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center