A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Help with the code

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147

    Help with the code

    Hi,

    I found this code somewhere and it does exactly what i want but it's as2 and i don't know how to port in to as1:

    var myMCL:MovieClipLoader = new MovieClipLoader();
    var ml:Object = new Object();
    ml.onLoadInit = function(target_mc:MovieClip) {
    target_mc._x = 50;
    target_mc._y = 50;
    }
    myMCL.addlistener(ml);

    _root.createEmptyMovieClip("container_mc",1);
    myMCL.loadClip("pic1.jpg", container_mc);

    Any help would be appreciated!

  2. #2
    Ubi bene, ibi patria Nightcap's Avatar
    Join Date
    Jun 2007
    Location
    GA, USA
    Posts
    184
    This will work:

    Code:
    var myMCL = new MovieClipLoader();
    var ml = new Object();
    ml.onLoadInit = function(target_mc) {
    target_mc._x = 50;
    target_mc._y = 50;
    }
    myMCL.addlistener(ml);
    
    _root.createEmptyMovieClip("container_mc",1);
    myMCL.loadClip("pic1.jpg", container_mc);
    Everybody thinks of changing humanity,
    Nobody thinks of changing himself.

  3. #3
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    nope, it didn't work but thanks for your help!

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Try changing onLoadInit to just onLoad
    Last edited by blanius; 09-08-2008 at 07:31 AM.

  5. #5
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    Still nothing!

    Anyway, do you know any code that will resize image onLoad or after its loaded?

    If not, i ll just make a bunch of small/(jpg) swf's and load em into the main movie!

  6. #6
    Ubi bene, ibi patria Nightcap's Avatar
    Join Date
    Jun 2007
    Location
    GA, USA
    Posts
    184
    joca_hdj, tried the code myself and it worked. I had to save the fun file the first time, close KM, open it again and load the fun file in order for it to find the picture. That was all.
    Last edited by Nightcap; 09-08-2008 at 01:59 PM.
    Everybody thinks of changing humanity,
    Nobody thinks of changing himself.

  7. #7
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    Nightcap, thank you for your time.I worked this time, but the code turned not to be what i wanted.I need some script that will resize the loaded image to a 100 x 100 px aprox. I am working on a kind of gallery and it would be way easier for me to do it this way, then to go and resize the images, make separate swfs..
    you know what i mean!

    Do you have any idea how to archive this? And i m not gonna google it all night long!

    Thanks!

    Jovan

  8. #8
    Ubi bene, ibi patria Nightcap's Avatar
    Join Date
    Jun 2007
    Location
    GA, USA
    Posts
    184
    Jovan, why don't you do it like this:

    Code:
    createEmptyMovieClip("container_mc", 1);
    container_mc._x = 50;
    container_mc._y = 50;
    container_mc._xscale = 40; //number is percentage of original
    container_mc._yscale = 40; //number is percentage of original
    container_mc.loadMovie("pic1.jpg");
    It's simpler than the AS2 code and you don't have to resize the images, and as long as you don't make them too small, they'll look decent enough.

    Hope this helps.

    Everybody thinks of changing humanity,
    Nobody thinks of changing himself.

  9. #9
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Actually you have to resize AFTER you load the Image. So you are almost there. Instead of using fix x and Y you can scale it.
    Code:
    var myMCL = new MovieClipLoader();
    
    myMCL.onLoadInit = function(target_mc) {
    
    target_mc._xscale = (100/target_mc._width)*100;;
    target_mc._yscale = (100/target_mc._height)*100;
    }
    
    myMCL.addlistener(ml);
    
    _root.createEmptyMovieClip("container_mc",1);
    myMCL.loadClip("CRW_2448.jpg", container_mc);
    I tested this code.....
    Last edited by blanius; 09-08-2008 at 10:21 PM.

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Better still is this.... Now it works for as many container clips as you have
    Code:
    var myMCL = new MovieClipLoader();
    
    myMCL.onLoadInit = function(target_mc) {
    
    target_mc._xscale = (100/target_mc._width)*100;;
    target_mc._yscale = (100/target_mc._height)*100;
    }
    
    
    _root.createEmptyMovieClip("container_mc",this.getNextHighestDepth());
    _root.createEmptyMovieClip("container2_mc",this.getNextHighestDepth());
    container2_mc._x+=100
    _root.createEmptyMovieClip("container3_mc",this.getNextHighestDepth());
    container3_mc._x+=200
    myMCL.loadClip("CRW_2448.jpg", container_mc);
    myMCL.loadClip("Dsc_0411.jpg", container2_mc);
    myMCL.loadClip("IMG27A-2.jpg", container3_mc);

  11. #11
    Ubi bene, ibi patria Nightcap's Avatar
    Join Date
    Jun 2007
    Location
    GA, USA
    Posts
    184
    Quote Originally Posted by blanius
    Actually you have to resize AFTER you load the Image.
    May I ask why it has to be after loading? I tried this in the past, but I couldn't notice a difference in picture quality. Just trying to learn here.

    BTW Nice piece of code for Jovan! He's gonna be a happy camper.

    Everybody thinks of changing humanity,
    Nobody thinks of changing himself.

  12. #12
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    OMG, look what i wrote up there.

    " i m not gonna google all night long", jeeeez, what i meant is that i was gonna google the solution all night and i did! Found nothing interesting!What a terrible typo, sorry for that!

    @Nightcap

    Thanks for your code, works perfectly and i am going to use it!

    @Blanius

    Holy dinah!!! Works and look wonderful!!Thank you!I am also gonna use this one!!

    I 've been trying to make the link of a loaded image(e.g. to the 1.jpg) but i was afraid i would ruin the integrity of your code.How would you do that?

    I always feel like telling you to submit these files/solutions to the exchange since you guys do sucha good job!!
    Last edited by joca_hdj; 09-09-2008 at 05:42 AM.

  13. #13
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by Nightcap
    May I ask why it has to be after loading? I tried this in the past, but I couldn't notice a difference in picture quality. Just trying to learn here.

    BTW Nice piece of code for Jovan! He's gonna be a happy camper.

    You can't get the original size untill the image loads

  14. #14
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    Blanius, sorry to bug you! I need these pix to be links to itself e.g. 1.jpg...and so on!

    I had an idea of creating 2 empty mc in container_mc, one for the link, one for the image, but it didn't work for me! Do you know to do this?

    Thank you!!

  15. #15
    Ubi bene, ibi patria Nightcap's Avatar
    Join Date
    Jun 2007
    Location
    GA, USA
    Posts
    184
    Quote Originally Posted by blanius
    You can't get the original size untill the image loads
    Ah, so it has nothing to do with image quality. Thanks for clearing that up.

    My code snippet was used on pictures that had the same size. There was no need to determine that after loading.

    Everybody thinks of changing humanity,
    Nobody thinks of changing himself.

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    container2_mc.onRelease=function(){
    getURL("Dsc_0411.jpg","_new");
    }

  17. #17
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    @ Blanius: Its not working for some reason!

  18. #18
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    you are correct that doesn't work..... The issue is that when we load a clip it overwrites the actionscript as well. You'd have to set it in the onLoadInit function. But I don't see an easy way to do that.

    Everything I can think of would require rethinking the whole thing. I'm hoping someone else can come up with a simple solution.

    What you probably need to do is either make a more complex loading routine that saves the name somewhere that you can reference in the onLoadInit routine. Or Create a clip inside of the container clip and load the image there then any actionscript on the container will remain intact.(this is probably the way to go)

  19. #19
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok here you go.


    PHP Code:
    var myMCL = new MovieClipLoader();

    myMCL.onLoadInit = function(target_mc) {
    //After loading get size and rescale  to 100pixel
    target_mc._xscale = (100/target_mc._width)*100;;//Calculate percent to use to get 100 pxl
    target_mc._yscale = (100/target_mc._height)*100;
    }

    //Creat our own function to handle things
    myMCL.loadit=function(myUrl,clip){//we pass the same info in the same order as loadClip function
    //Now we create an empty clip named photo inside each container movie
    clip.createEmptyMovieClip("photo",clip.getNextHighestDepth());
    //now we load the child clip with the photo
        
    myMCL.loadClip(myUrl,clip.photo);
        
    //now we set the onRelease function for the container movie
            
    clip.onRelease=function(){
                
    getUrl(myUrl,"_new");
                }
        }
        
    _root.createEmptyMovieClip("container_mc",this.getNextHighestDepth())
    _root.createEmptyMovieClip("container2_mc",this.getNextHighestDepth());
    container2_mc._x+=100
    _root
    .createEmptyMovieClip("container3_mc",this.getNextHighestDepth());
    container3_mc._x+=200
    //here we call our function using the same paramters as the loadClip function
    myMCL.loadit("CRW_2448.jpg",container_mc);
    myMCL.loadit("Dsc_0411.jpg"container2_mc);
    myMCL.loadit("IMG27A-2.jpg"container3_mc); 

  20. #20
    Senior Member
    Join Date
    Apr 2006
    Location
    Yugoslavia
    Posts
    147
    Absolutely Brilliant!!!!

    I' ll Buy You A Beer!!

    Thank You!!

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