Click to See Complete Forum and Search --> : Help with the code
joca_hdj
09-07-2008, 08:07 AM
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!
Nightcap
09-07-2008, 03:05 PM
This will work:
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);
joca_hdj
09-08-2008, 06:07 AM
nope, it didn't work but thanks for your help!
blanius
09-08-2008, 08:27 AM
Try changing onLoadInit to just onLoad
joca_hdj
09-08-2008, 10:55 AM
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!
Nightcap
09-08-2008, 02:53 PM
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.
joca_hdj
09-08-2008, 05:21 PM
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
Nightcap
09-08-2008, 08:28 PM
Jovan, why don't you do it like this:
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.
:cap:
blanius
09-08-2008, 11:03 PM
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.
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.....
blanius
09-08-2008, 11:29 PM
Better still is this.... Now it works for as many container clips as you have
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);
Nightcap
09-09-2008, 12:17 AM
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.
:cap:
joca_hdj
09-09-2008, 05:52 AM
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!!
blanius
09-10-2008, 08:04 AM
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.
:cap:
You can't get the original size untill the image loads
joca_hdj
09-10-2008, 02:04 PM
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!!
Nightcap
09-10-2008, 08:48 PM
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.
:cap:
blanius
09-10-2008, 09:38 PM
container2_mc.onRelease=function(){
getURL("Dsc_0411.jpg","_new");
}
joca_hdj
09-11-2008, 06:44 AM
@ Blanius: Its not working for some reason!
blanius
09-11-2008, 10:06 AM
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)
blanius
09-11-2008, 10:21 AM
Ok here you go.
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);
joca_hdj
09-11-2008, 10:38 AM
Absolutely Brilliant!!!!
I' ll Buy You A Beer!!
Thank You!!
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.