My images don’t cache because I use non-cache code for them. I did this for testing purposes, I didn’t want to keep clearing my cache to test my movie
As for your code, it doesn’t work because you are defining everything in the onPress. The only thing you need in the onPress is the loadMovie code… like this…
this.createEmptyMovieClip("preloader", 1000);
this.createEmptyMovieClip("container", 1001);
//container._x = 250 ;
//container._y = 0 ;
container._visible = false;
preloader.onEnterFrame = function() {
var l = container.getBytesLoaded();
var t = container.getBytesTotal();
var getPercent = l/t;
//loadText = Math.round(getPercent*100)+"%";
loadBar._width = getPercent*500;
if (l>0 && l>=t) {
container._visible = 1;
delete this.onEnterFrame;
}
};
button.onPress = function() {
container.loadMovie("test.jpg");
};
To edit the properties of what you load, just edit the properties of the container clip that holds what you load in. In this case its its the empty movie clip called “container” that is dynamically created.
As for if its working or not, I don’t know, I am on cable. I can’t find the script anywhere in your .fla, where is it?
I don’t see that script you have mentioned with time and date on this thread… Anyways… You can ONLY change those properties when the file is FULLY loaded… From the lostinbeta’s last code, you probably can do this right before you turn the visibility on…
I usually check wth if (container._width > 0) to make sure if it has been loaded into the container movieclip…
*Originally posted by CyanBlue *
**I usually check wth if (container._width > 0) to make sure if it has been loaded into the container movieclip… **
Yes, but given the fact that we have a preloader that shows the percent loaded, we can’t just do a simple if width>0 deal. It would be different if we weren’t going to show exact percent loaded, because then we would just be able to use an if statement to check if the width is 0 and if not, then do whatever.
it’s working now … it’s not perfect but i’m getting there. man my fla is a mess. next site i do is going to be a lot more organized. this has been one big learning experience. experimenting and programming as i go.
the path to the code is _root.window.content.techtext … images layer frame 2
I know this hread has not been active for a while but I was interedted in the code thta lostinbeta has provided - howvere how do I make sure the pictures cache so I don’t have to reload - thta would solve a huge problem I am trying to work out!!
They will automatically cache. The movie I posted a link to has extra no-cache code in it, but the code provided in this thread does not include that extra bit of code.
the code works great offline but when I tested by uploading it, the images don’t appear to cache as I have to reload the images every time I want to view them. At the moment I have three buttons with the code as follows:
on (release) {
this.createEmptyMovieClip(“preloader”, 1000);
picture.createEmptyMovieClip(“picture”, 1);
picture.picture.loadMovie(“pic1.jpg”);
picture._visible = false;
preloader.onEnterFrame = function() {
var l = picture.picture.getBytesLoaded();
var t = picture.picture.getBytesTotal();
var getPercent = l/t;
loadBar._width = getPercent*100;
if (l>0 && l>=t) {
gotoAndStop(2);
this.onEnterFrame;
}
};
Well theres no cache prevention code in that script there so any delay is most likely in Flash interpreting the data and loading it into the .swf.
And this line makes no sense…[AS]this.onEnterFrame;[/AS]
this.onEnterFrame what? you don’t delete it, but you don’t run anything in it either, so why are you re-initializing it when it is already initialized? If you are loading only 1 picture using that script then I recommend using [AS]delete this.onEnterFrame;[/AS] so that you can stop running the onEnterFrame since it won’t be used for anything.
Thanks - indeed I had forgotten the ‘delete’
After refreshing the browser - the images do cache, so I don’t know why it was reloading before (ie load bar moves).
However - I have now got another problem! Because there is a delay in loading the jpg from the cache, my dynamic border has problems!
I have an MC that resizes itself to the size of the loaded jpg in the MC ‘picture’ However in the short delay it shrinks to a small square and then expands to the correct size when loaded. Obviously offline this does not happen - is there a way I can get the border MC to execute when the jpg is loaded and the dimensions can be read?
would it be a ifFrameloaded task - does this work for jpgs - and indeed what would the path be. I keep confusing myself as to the correct path.
Can you use this function to check loaded frame in another MC from an MC
My resize code is:
onClipEvent (enterFrame) {
w = _root.picture._width;
h = _root.picture._height;
xpos = _root.picture._x;
ypos = _root.picture._y;
speed = 5;
this._width += ((w-this._width)/speed)+8;
this._height += ((h-this._height)/speed)+8;
this._x += ((xpos-this._x)/speed)-4;
this._y += ((ypos-this._y)/speed)-4;
}
ifFramesLoaded is deprecated syntax, you shouldn’t use it at all.
As for the width and height of your clip, set that in a variable.
When the image loads, set the variable to the new image width and height. That way when the clip is unloaded the width of the border area will still be the original height instead of shrinking back to 0.
Or something along those lines should do
And please use the vbCode AS tags, its a pain to read unformatted code. [<I></I>AS]//codeHere[<I></I>/AS]
Thanks for your help so far. I have been trying your suggestion of setting variables - I belive I am doing it correctly but the border MC will do nothing now…
On the loading of the jpg - I have set the variables after the preloader as follows (var x and var y):
[AS]//
on (release) {
this.createEmptyMovieClip(“preloader”, 1000);
picture.createEmptyMovieClip(“picture”, 1);
picture.picture.loadMovie(“pic1.jpg”);
picture._visible = 1;
preloader.onEnterFrame = function() {
var l = picture.picture.getBytesLoaded();
var t = picture.picture.getBytesTotal();
var getPercent = l/t;
loadBar._width = getPercent*100;
if (l>0 && l>=t) {
var x = picture._width;
var y = picture._height;
delete this.onEnterFrame;
}
};
}
[/AS]
ok I’m new to this forum- but half my message disappeared when I posted!!
Anyway this is the missing bit:
The border MC should in theory use these set variables and resize:
[AS]//
onClipEvent (enterFrame) {
w = picture.x;
h = picture.y;
xpos = _root.picture._x;
ypos = _root.picture._y;
speed = 5;
this._width += ((w-this._width)/speed)+8;
this._x += ((xpos-this._x)/speed)-4;
this._y += ((ypos-this._y)/speed)-4;
}
[/AS]
You define them in your script as just x and y, but you call them as picture.x and picture.y. I recommend not applying the variables to the picture clip because I believe when you load something new into that clip those actions will disappear.
I have tried all combinations of names - ie x and y instead of picture.x etc but nothing seems to work. But as you say, it could be that the variables are lost when load - but it doesn’t work the first time I press load. I have put the script in lots of different places but eith no luck.
How else could I set the variables?
ps I really appreciate the help you are giving me:)
set the variables on the _root…
(edit of a short excerpt of your script…) [AS]if (l>0 && l>=t) {
_root.x = picture._width;
_root.y = picture._height;
delete this.onEnterFrame;
}[/AS]
Then call it in your enterFrame as _root.x and _root.y.