dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Trouble zooming the image correctly

  1. #1
    Junior Member
    Join Date
    Mar 2004
    Posts
    16

    Trouble zooming the image correctly

    Hello,

    I have a flash file that lets you zoom pictures. My problem is when I zoom the picture the picture moves to the bottom-right. Meaning that the x and y values increases.

    Now, what I want is for the picture to zoom from the center of the picture. And not from right to left, as it does right now. You see what I mean if you test the file. Again, I want the picture to zoom from the center straight at me.

    Hope you understood my explanation.

    Very gratefull if anyone can help me solve this problem.
    Last edited by o_emma; 07-02-2004 at 07:08 AM.

  2. #2
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    when you load the photo you will need to centre it in the movieclip so that it zooms to the centre....

    Create another empty MC (called 'imageMC') inside the 'photo' MC and load the image into that:

    _root.photo.imageMC.loadMovie(this.pathToPics+this.pArray[this.pIndex])


    Once the image has loaded then set the x,y coordinates as follows:

    _root.photo.imageMC._x = (-photo.imageMC._width/2)
    _root.photo.imageMC._y = (-photo.imageMC._height/2)


    Now zoom should work has desired.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  3. #3
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    note you will have to move the "photo" movieclip to nearer the middle of the stage or your photo will be half off screen.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  4. #4
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    I'm very sorry but I'm new to flash and I don't fully understand what u mean. Would you like to upload or mail the file with the change so that I can take a look at it. I don't quite understand the terminology!

    Thanks for your help!

  5. #5
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    ok, here is an updated version of your movie where the image will always zoom to the centre of the view screen.

    I also neatened up everything a little, making fade in and out work a little better etc. It should all be fairly self explainatory.

    enjoy
    Last edited by Lexicon; 07-05-2004 at 05:45 AM.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  6. #6
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    it works super!!! thank you SO much for your help! and I understand the code

    thanks again!

  7. #7
    Junior Member
    Join Date
    Mar 2004
    Posts
    16

    One final question about retrivning exernal values...

    HI and thanks again for all your help.

    I have one more question. Hope you also can help me with this one.

    In my flash file I want to dynamically change the path to my pics. I have one folder named 'a', one named 'b' and finally one named 'c'. The content of this folders are images entitled 1.jpg, 2.jpg, 3.jpg and 4.jpg. Now, depending on which link I click want to dsiplay the images of the right folder.

    To do this I need to change this path in my flash file:

    code:
    pathToPics = "";


    Into:
    code:
    pathToPics ="a";

    code:
    pathToPics ="b";

    and so on...


    I'm retriving the dynamic value from a ASP file. I have no problems retrving the value (I think). The problem is I can't seem to use the value I have retrived. I place this code at the top of the fla file:
    code:

    myLoadVars = new LoadVars();
    myLoadVars.onLoad = function(success){
    if (success){
    test2 = myLoadVars.thePics;
    }else{
    trace("no variables loaded");
    }
    };
    myLoadVars.load("test.asp");

    pathToPics = (_root.test2); //this does't work, the path to the pics.



    My ASP file (test.asp) looks like this, txtVariable holds the value a, b or c depending on which link you click.

    Response.Write "&thePics="&txtVariable
    Which gives the correct output.

    I think I need to put the value in some form of function, but I don't really now how to do it. I'm guessing you do?

    In one of my attempts I made like a function called afterload which should start wen the variables have loaded. This way I can retrive the value anywhere. But I don't know where to close it, and I can only display one picture. If you don't know asp tell me the soloution using textfiles.


    Thanks!

  8. #8
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    I think that you are assigning the variable before it gets loaded.
    Why not assign pathToPics within the LoadVars function, without using test2?

    Code:
    myLoadVars = new LoadVars();
    myLoadVars.onLoad = function(success){
    	if (success){
    		_root.pathToPics = myLoadVars.thePics;
    		doSomething();
    	}else{
    		trace("no variables loaded");
    	}
    };
    myLoadVars.load("test.asp");
    
    function doSomething(){
    	trace(pathToPics);
    }
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  9. #9
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    Well now when I place this:
    code:

    function doSomething(){
    pArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg"];
    fadeSpeed = 5;
    pIndex = 0;
    photo._alpha = 0;
    }



    Everything works except that it doesn't display the first image. It starts with 2.jpg. Why?

  10. #10
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    does image 1 load ever? i.e. if you load image 2 and go back to image 1, does it load then?
    If so then you will probably need to add a call to the changePic function when the LoadVars function is complete.

    Code:
    function doSomething(){
            pArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg"];
            fadeSpeed = 5;
            pIndex = 0;
            photo._alpha = 0;
            changePic(pIndex);
    }
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  11. #11
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    Yes, now it works! Thanks a lot. Do you mind removing the file that you uploaded?

  12. #12
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    no worries, any time.

    I'm sure, as the file is now deleted, that anyone experiencing the same problems could come to you for help on this issue
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

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