A Flash Developer Resource Site

Page 2 of 7 FirstFirst 123456 ... LastLast
Results 21 to 40 of 134

Thread: dynamically loading jpgs and sizing the movie appropriately

  1. #21
    Dan-
    If I understand correctly you want to dynamically load different images into 1 MC and have the images sized appropriately (If I am off I appologize ;-) )

    In my example I use 3 images which are completly different in size and resize them to the correct size to be displayed Here's a really simple way to do this:

    Code:
    btnA.onPress = function(){
    		holder._visible = false
    		holder.loadMovie("1.jpg")
    		interval = setInterval(check_loaded,10)
    }
    btnB.onPress = function(){
    		holder._visible = false
    		holder.loadMovie("2.jpg")
    		interval = setInterval(check_loaded,10)
    }
    btnC.onPress = function(){
    		holder._visible = false
    		holder.loadMovie("3.jpg")
    		interval = setInterval(check_loaded,10)
    }
    function check_loaded(){
    	if (holder._width>0){
    		holder._width = 200
    		holder._height = 200
    		holder._visible = true
    		clearInterval(interval)
    	}
    }
    this code is placed on on empty keyframe
    holder is an empty mc
    btnA - C are buttons accordingly.

    I hope this helps

  2. #22
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    That sounds like a lot of work. Especially if the only drawback to your current version is that the canvas starts from zero size sometimes. You can try this....

    onClipEvent (enterFrame) {
    trace(math.round(_root.picholder._width));
    trace(math.round(this._width));
    // Make canvas dynamically resize to whatever is loaded in picholder clip and width and height matches (and only when tótally loaded )
    if(_root.picholder.getBytesLoaded()>=_root.pichold er.getBytesTotal()&&_root.picholder.getBytesLoaded ()>1000){
    this._width += (_root.picholder._width-this._width+20)/7;
    this._height += (_root.picholder._height-this._height+20)/7;
    }
    // Show picholder only when something is loaded into it
    if (math.round(_root.picholder._width+20) == math.round(this._width) && _root.picholder.getBytesLoaded()>1000 ) {
    _root.picholder._alpha = 100;
    } else {
    _root.picholder._alpha = 0;
    }
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #23
    Senior Member
    Join Date
    Aug 2001
    Posts
    220
    pellepiano thank you so much for all your help. I was trying to figure this out and your code works great.

    thanks again.

  4. #24
    Got it in one Pellepiano!
    Many thanks for your help. I haven't uploaded the final .swf file but when i do it will be on http://members.lycos.co.uk/pointlessonline/pix.htm
    Thanks again,
    Dan

  5. #25
    Senior Member
    Join Date
    Aug 2001
    Posts
    220
    can anyone tell me why this isnt working?:

    I have a semi-transparent window that animates over the existing photo in _root.picholder and stops. I then have the following code on the keyframe:

    loadMovie("loading.swf", "_root.loader");
    if (_root.picholder.getBytesLoaded()>=_root.picholder .getBytesTotal() && _root.picholder.getBytesLoaded()>1000) {
    play();
    } else {
    stop();
    }

    what should happen is if the pic is fully loaded, the timeline should play if not stay where it is. I am using the same code from the canvas MC and that works, this is driving me nuts.If I just publish the movie and test locally iut works, but if I "simulate download" once the pic gets loaded, the timeline in question doesnt move..

    Any help is greatly appreciated.

  6. #26
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Its because a preloader code works by constantly checking if the condition is met, and you have the code on one frame that doesnt repeat itself, it just checks once, when its loaded.

    When testing locally the image is loaded so fast that it works, but online , all is needed is one frame of delay , and the code wont work.

    Thats why it works , sitting on a movieclip that runs the code all the time ( every frame ).

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  7. #27
    Senior Member
    Join Date
    Aug 2001
    Posts
    220
    I think I understand what you are saying so my solution was to change the code to this:

    loadMovie("loading.swf", "_root.loader");
    if (_root.picholder.getBytesLoaded()>=_root.picholder .getBytesTotal() && _root.picholder.getBytesLoaded()>1000) {
    play();
    } else {
    gotoAndPlay("back");
    }

    and the frame "back" just sends them back to this frame after 5 frames.

    Still no luck...

  8. #28
    Senior Member
    Join Date
    Aug 2001
    Posts
    220
    nevermind I got it!

    pellepiano, you really kick ass.

    thank you.

  9. #29
    Junior Member
    Join Date
    Nov 2003
    Location
    Australia
    Posts
    11
    Im inclined to agree having looked at some of the picloading stuff, awesome

    paul

  10. #30
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    If you also want movement in resizing and stuff things get a little more complicated but is doable ( example www.maxschultz.com/pp ). [/B]
    fantastic image gallery, i have been trying to mimick something like this all day now, without success i might add.
    Probably doesnt help that i havent used action script much before.
    Is their any chance that you could possibly either post an example zip file or send me an email explaining in more detail how I would go about setting up an image gallery like the above, I know you are very busy (can see that by the amount of posts you appear on).

    Frustrated newbie Adam

  11. #31
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Thanks!. Unfortunately I dont have the time or energy to write a tutorial for it.

    There are some useful codes in this thread though. A few posts above is the whole resizing code for the canvas movieclip.

    There are also several other threads with bits and pieces. You can make a search for username pellepiano and .....
    resize movieclip load jpg

    ...and youll find some other threads discussing the same thing. If I remeber correctly there is also some submissions of .fla files from some people.

    The search did not work at the moment so I can not direct you to it.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  12. #32
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    Thanks for the response, i have tried searching the threads and their are many useful codes fla's lying around, but none seem to do what you have created, it was mainly the thumbnail to container that impressed me. Thats whats stumping me. I will try searching the threads again, thank again for your time.

    Adam

  13. #33
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    If you have specific questions just fire away, its just that writing everything about the gallery would be some long read as it somewhat dynamic in the sense that there is only 2 movieclips really in the .fla. They get duplicated depending on how many images are defined in a textfile, and all actions are also dynamic. Buttons only have general actions like..

    container.loadMovie(eval("_root.image"+id));

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  14. #34
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    pelle piano,
    thanks again for your response, as i said though actionscript is a very new thing to me, that last post flew over my head like concorde.
    I should probably look into learning actionscript before hassling you. If i created a movie for the thumbnail, and a movie for the container how would i load the images dynamically & how would the container show whats in the thumbnail on mouseover? Like on yours.
    Looking at some of your posts right now, trying to learn the basics.
    PS.. That invention u made that does the 360 tours is mint! i know what an pain it is to take shed loads of piccys to get a panorama.

    Thanks again

    Adam

  15. #35
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Unfortunately its hard to find exactly round mirrors, so the images dont get that accurate. Ive been experimenting with, shristmas balls, soop spoons, pinballs etc =)

    If you are fairly new to actionscript I would not recommend making a dynamic gallery to start with. Its better to come to grips with the basic actions first.

    My first versions had 10 thumbanail bitmaps placed on stage. then I put buttons over them ( on top) , with no graphics in the up state, and a shaded shape on the Over state ). That made the images seem to behave like buttons. ( this is so I could use the same button for all images ). The buttons then only had one action, to load the big image into the container MC, which the resizing canvas resized itself for.

    The whole code for resizing, preloading, hiding image until its loaded and so on, is a few posts up in this thread.It should be placed ON the canvas clip.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  16. #36
    Senior Member
    Join Date
    Jul 2004
    Location
    In a box outside of Safeway
    Posts
    201
    very interesting, but one of the few technical things that confuses me
    If computer games affected us, would I not be running into walls popping strange yellow pills and listening to repetitive music?

  17. #37
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    pellepiano

    Thanks for your advice, I did as u said and have created this test gallery http://www.silverpearl.co.uk/adsthum...ry/gallery.htm
    its basic but its functional thanks to you. As you can see I have included 2 dynamically loaded buttons on the right side so I am progressing.
    Please could you give advice on the following :
    1. Their seems to be a fault coding as when i run it in flash the output panel producing random numbers. Is this normal?
    2. I will be changing all the (thumbnail) images so they load dynamically, currently my each thumbnail movie contains the following code
    loadText = new LoadVars();
    loadText.load("http://www.silverpearl.co.uk/adsthumbnailgallery/data.txt");
    loadText.onLoad = function() {
    name.text = this.name;
    email.text = this.email;
    location.text = this.location;
    picholder.loadMovie("http://www.silverpearl.co.uk/adsthumbnailgallery/1s.jpg");
    };

    picholder movie is contained within the individual thumbnail movies.
    I then have to create a data.txt for each thumbnail eg.. data1.txt, data2.txt etc.. is their a better way of doing this?

    Anyway thanks for all your help you have been great
    I hope you get chance to look at it and laugh at my appauling actionscript.

    Adam

  18. #38
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    Nearly forgot theirs a little box at the bottom left of the screen, how do i include the dynamically loaded data in their ie. name, email, location.

    Sorry - Newbies must really frustrate you

    Adam

  19. #39
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    1. The numbers appears because of the trace actions in the code, its just code I used to check the script, you can delete the trace actions.

    2. You can use ONE texfile with all information.

    image_url1=images/someBroad.jpg&image_name1=Girl in Color&image_email1=someOne@someWhere.com&image_url 2&images/anotherBroad.jpg ....and so on

    When having a textfile like this you have specified image names ( dont know what the email is for but..ok... ) the path to the image ( for loading ) and so on, these can be referenced at any time. By naming the thumnail images the same name as the big ones BUT with a x infront things can get very dynamic

    for(i=1;i<30;i++){
    this["thumbnailMovie"+i].picholder.loadMovie("x"+eval("image_url"+i))
    }

    This line will actually load 30 thumbanail images into 30 buttons picholder, using the variables in the textile for the url and adding a x in front so its only the thumbnails that load.

    For loading the larger version you can use

    thumbnailMovie1.picholder.loadMovie(image_url1));

    Just a tip.

    The little box.
    // Combine two variables in the textbox.
    littleboxName=image_name1+newline+image_email1;

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  20. #40
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    Thanks again,
    can u tell me where / Which timelines i should put the scripts onto. are they on entry scripts.
    sorry

    Ad

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