|
-
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!
-
Ubi bene, ibi patria
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.
-
nope, it didn't work but thanks for your help!
-
KoolMoves Moderator
Try changing onLoadInit to just onLoad
Last edited by blanius; 09-08-2008 at 07:31 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!
-
Ubi bene, ibi patria
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.
-
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
-
Ubi bene, ibi patria
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.
-
KoolMoves Moderator
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.
-
KoolMoves Moderator
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);
-
Ubi bene, ibi patria
 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.
-
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.
-
KoolMoves Moderator
 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
-
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!!
-
Ubi bene, ibi patria
 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.
-
KoolMoves Moderator
container2_mc.onRelease=function(){
getURL("Dsc_0411.jpg","_new");
}
-
@ Blanius: Its not working for some reason!
-
KoolMoves Moderator
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)
-
KoolMoves Moderator
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);
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|