-
Hi, i'm new in this forum.
I'm trying to load a jpg, and i use the next code:
//ImageToLoad is a movieclip defined in design time
//PhotoNode.firstChild.nodeValue is a string with the IMG URL
//I'm using XML to get dinamically the image.
ImageToLoad.loadMovie(PhotoNode.firstChild.nodeVal ue);
ImageToLoad.onLoad = function () {
trace ("onLoad called");
};
Well the image is loaded but i have 2 problems. The position that i set in design time has changed and if the image has a different size, it gets the new size too. I tried to fix it using code inside of OnLoad event changing the size and the old position but it isn't executed.
btw, all is in the same timeline.
Thanks for the help.
-
make sure the image is loaded...
hi, you need to make sure the image is loaded before you set any x or y parameters
Code:
if(PhotoNode.firstChild.nodeValue.getBytesLoaded() == PhotoNode.firstChild.nodeValue.getBytesTotal() && PhotoNode.firstChild.nodeValue.getBytesTotal()>4)
hope that helps.
BenG
-
Like i said, i tried to use "OnLoad" event but it isn't executed.
Next text is from Flash mx help:
Description
MovieClip.onLoad
Event handler; invoked when the movie clip is instantiated and appears in the Timeline.
You must define a function that executes when the event is invoked.
Well,in my case, this don't work and it isn't invoked.
-
I have fixed it adding this:
ImageToLoad.onEnterFrame = function () {
trace ("onEnterFrame called");
ImageToLoad._x=0;
ImageToLoad._y=0;
ImageToLoad._width=160;
ImageToLoad._height=120;
};
but still i dont know why OnLoad event isnt invoked. I have tried using swf files instead of jpg files, and i have the same problem.
-
sorry completely wrong end of stick!
apologies. I never have any luck with the onLoad handler. But yes enterFrame seems to work perfectly - very strange.
-
Thanks for your fast answers :)
I think that it is a flash mx bug, but well, i'm not an actionscript expert
-
President, save the New Zealand dollar foundation
don't use
onEnterFrame()
this will make the code loop.
for code that you want to execute once a movieclip or variables have been fully loaded use
onData()
Code:
ImageToLoad.loadMovie(PhotoNode.firstChild.nodeValue);
ImageToLoad.onData = function () {
with(this) {
_x = 0;
_y = 0;
_width = 160;
_height = 120;
};
the reason onLoad() wouldn't work, is that the onLoad event is fired when the movieclip is first made, ie as soon as ImageToLoad was created.
I've found that even if you use
this.createEmptyMovieClip("mc", 1);
and have this
this.mc.onLoad = function(){blah}
onthe very next line, it still won't work.
-
The code doesn't loop because it is included in other event, in this case when the xml is fully loaded.
Anyways, i tried your code and it doesn't run the OnData event (yes, i included the } missed in with).
-
sonwah any ideas?
ok i have/had a similar problem
Code:
onClipEvent(load){
function loadPics(amount){
for (i=1;i<=amount;i++){
this.createEmptyMovieClip("picHolder"+i,i);
if (i<10){
loadMovie("images/thumbs/DSCF000" + i +".jpg", "picHolder"+i);
}else{
loadMovie("images/thumbs/DSCF00" + i +".jpg", "picHolder"+i);
}
this["picHolder"+i]._alpha = 50;
}
}
loadPics(40);
}
onClipEvent(enterFrame){
function movePics(movement){
xpos=0;
ypos=0;
for (i=1;i<=movement;i++){
if(this["picHolder"+i].getBytesLoaded() == this["picHolder"+i].getBytesTotal() && this["picHolder"+i].getBytesTotal()>4){
if(xpos<=250){
xpos = this["picHolder"+(i-1)]._x + this["picHolder"+(i-1)]._width + 5;
}
}
movePics(40);
you get the idea, but the enterframe was the only one that would move each image?
-
President, save the New Zealand dollar foundation
so another solution:
create another emptyMovieClip and use it's onEnterFrame to check the first:
Code:
_root.createEmptyMovieClip("mc3", 1);
_root.createEmptyMovieClip("mc4", 2);
_root.mc3.loadMovie("rude.jpg");
_root.mc4.onEnterFrame = function () {
trace("hello");
if ( _root.mc3.getBytesLoaded() == _root.mc3.getBytesTotal() ) {
_root.mc3._x = 22;
_root.mc3._y = 22;
_root.mc3._width = 160;
_root.mc3._height = 120;
this.removeMovieClip();
}
}
that way you don't have an endless enterFrame loop occurring, because the "byteChecker" unloads itself when finished.
-
nice method...
sorry about the delay:
ok i tested your version which worked well. When i tried to implement it into my own code i get a trace of undefined - is this because the function doesn't recognise it?
Code:
amount=15;
for (i=1; i<=amount; i++) {
_root.createEmptyMovieClip("picHolder"+i, i);
loadMovie("images/thumbs/DSCF000"+i+".jpg", _root["picHolder"+i]);
}
_root["picHolder"+i]._alpha = 50;
_root.createEmptyMovieClip("loadtest"+i, amount+i);
_root["loadtest"+i].onEnterFrame = function() {
trace(_root["picHolder"+i]);
I tried using eval() as well but with no luck.
BenG
-
solved it...
sorry I was over complicating things
Code:
_root.createEmptyMovieClip("loadtest", (1+amount));
_root.loadtest.onEnterFrame = function() {
Thanks for your help.
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
|