Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: XML Image scale on browser resize

  1. #1
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default XML Image scale on browser resize

    Hi,

    Im working on a full screen flash project that calls in an image from an xml file and displays it in the background. This all works great but is it possible to have the imported image scale up/down when the user resizes the browser window?? I have searched for a solution but cant seem to find one. Is this possible?

    Im not sure if this will do any good but here is the code for loading in the background image:

    var oldVar = 0;
    var newVar = 0;
    var my_xml = new XML();
    my_xml.ignoreWhite = true;
    my_xml.onLoad = function(success) {
    if (success) {
    library = this.firstChild.childNodes;
    maxVal = library.length;
    delete my_xml;
    getImage();
    } else {
    desc_txt.text = 'Error: XML Not Loaded';
    }
    };
    my_xml.load('library.xml');
    p = 0;
    this.onEnterFrame = function() {
    if (container_mc._alpha<100) {
    container_mc._alpha += 8;
    }
    };
    function getImage() {
    newVar = Math.floor(Math.random()*maxVal);
    if (newVar == oldVar) {
    getImage();
    } else {
    oldVar = newVar;
    container_mc._alpha = 0;
    container_mc.loadMovie(library[newVar].firstChild.firstChild.nodeValue);
    newVar = Math.floor(Math.random()*maxVal);
    one_btn.onRelease = function() {
    getImage();
    };
    }
    }



    Any help would be appreciated

    Hurley
    Last edited by Hu4ley; 06-20-2007 at 02:27 PM.

  2. #2
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Anybody help or point me in the right direction?

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Once the image is brought in via XML, just treat it like a regular image that you have within a MC.

    I'm not sure what your bk is of so you should tweak this to suit your needs but not consider aspect ratios etc...

    Code:
    background_mc._width = Stage.width
    background_mc._height = Stage.height
    
    sizeListener = new Object();
    sizeListener.onResize = function() {
         background_mc._width = Stage.width
         background_mc._height = Stage.height
    }
    
    Stage.addListener(sizeListener);

  4. #4
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    First off thanks Medyman for your reply.

    This has been driving me insane.

    What im doing is importing random images into the background of my full screen flash project and would like the images to have the same aspect ratio regarless of browser size. Is there a piece of code I could add to this to achieve this effect???

    Thanks for your help!!

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Code:
    img._width = Stage.width;
    img._height = Stage.height;
    if (img._xscale > img._yscale) {
         img._yscale = img._xscale;
    } else {
         img._xscale = img._yscale;
    }
    This will make it so that the scaling is proportional.

    HTH

  6. #6
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Medyman your a genius!!!

    That code did the trick!! Really appreciate your help. Cant believe such a tiny piece of code caused me so much headache. Once I finish the project ill post a link and you can see it in action. Once again THANKS!!

    Hurley

  7. #7
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    No problem. Glad to help!

  8. #8
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default just whe you thought it was safe to go back into the water...

    Hi medyman...

    One more question... when I load my movie the imported background image loads fullscreen and dosent fit to window until I grab the browser and resize it. Have you any ideas on how to fix it?

    sorry to be a pain

  9. #9
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Make sure the aspect ratio piece of code is declared inside the onResize listener as well as outside.

    Your code should look like this...add the code from my second to last post above where it's commented

    Code:
    background_mc._width = Stage.width
    background_mc._height = Stage.height
    // Aspect ratio code
    
    sizeListener = new Object();
    sizeListener.onResize = function() {
         background_mc._width = Stage.width
         background_mc._height = Stage.height
         // Aspect ratio code
    }
    
    Stage.addListener(sizeListener);

  10. #10
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I used the code you posted and the background image still dosent show up until I resize the window? Ill post the code below maybe im missing something..

    #include "lmc_tween.as"
    Stage.align = "LT";
    Stage.scaleMode = "noScale";
    /////////////////////////////////////////////////////
    container_mc._width = Stage.width
    container_mc._height = Stage.height
    container_mc._width = Stage.width;
    container_mc._height = Stage.height;
    if (container_mc._xscale > container_mc._yscale) {
    container_mc._yscale = container_mc._xscale;
    } else {
    container_mc._xscale = container_mc._yscale;
    }

    sizeListener = new Object();
    sizeListener.onResize = function() {
    container_mc._width = Stage.width
    container_mc._height = Stage.height
    container_mc._width = Stage.width;
    container_mc._height = Stage.height;
    if (container_mc._xscale > container_mc._yscale) {
    container_mc._yscale = container_mc._xscale;
    } else {
    container_mc._xscale = container_mc._yscale;
    }
    }

    Stage.addListener(sizeListener);

    stageListener = {};
    stageListener.onResize = function(){
    header._y = Stage.height - header._height;
    header._x = Stage.width - header._width;
    }
    Stage.addListener(stageListener);
    /////////////////////////////////////////////////////////////////////////
    var oldVar = 0;
    var newVar = 0;
    var my_xml = new XML();
    my_xml.ignoreWhite = true;
    my_xml.onLoad = function(success) {
    if (success) {
    library = this.firstChild.childNodes;
    maxVal = library.length;
    delete my_xml;
    getImage();
    } else {
    desc_txt.text = 'Error: XML Not Loaded';
    }
    };
    my_xml.load('library.xml');
    p = 0;
    this.onEnterFrame = function() {
    if (container_mc._alpha<100) {
    container_mc._alpha += 8;
    }
    };
    function getImage() {
    newVar = Math.floor(Math.random()*maxVal);
    if (newVar == oldVar) {
    getImage();
    } else {
    oldVar = newVar;
    container_mc._alpha = 0;
    container_mc.loadMovie(library[newVar].firstChild.firstChild.nodeValue);
    newVar = Math.floor(Math.random()*maxVal);
    one_btn.onRelease = function() {
    getImage();
    };
    }
    }


    thanks medyman for the help.

Bookmarks

Posting Permissions

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