PDA

View Full Version : Tween class



clark kent
02-09-2007, 02:42 PM
Hello everybody

have a problem, maybe someone out there can help me...

I have a galery. It works fine. Now i want to add some FX when changing pictures. The problem is, the FX should start only when the picture has finished loading, so that the FX is visible.

On the main-timeline i have this code:


function ladeBild(paktBild) {
status_mc._visible = 1;
bild = bilder_theDataStore[paktBild].pic;
bildname = bilder_theDataStore[paktBild].name_;
titel_txt.text = bildname;
bild_mc._xscale = bild_mc._yscale=100;
//bild_mc._alpha = 100;
loadMovie(bild, "bild_mc");

this.onEnterFrame = function() {
if (bild_mc.getBytesLoaded()>=bild_mc.getBytesTotal() && bild_mc.getBytesLoaded()>12) {
delete this.onEnterFrame;
}
};

// When i put the below code here, the FX works, but it starts before the
// picture has finished loading... so no use putting it in here...

//new Tween(bild_mc, "_x", Bounce.easeOut, -100, 300, 1, true);
//new Tween(bild_mc, "_alpha", Strong.easeOut, 0, 100, 5, true);


and on the Movieclip "bild_mc" i have this code:


onClipEvent (load) {
var i = 0;
}
onClipEvent (enterFrame) {
if (this._url != this._parent._url && !this.loaded)
{
var kilobytes = Math.ceil (this.getBytesTotal () / 1024);
var prozent = Math.ceil ((this.getBytesLoaded () / this.getBytesTotal ()) * 100);
this._parent.counter_txt.text = "Lade " + prozent + "% of " + kilobytes + "k";
this._parent.loading_txt.text = "Bild wird geladen - Bitte warten!";
this._parent.status_mc._width = prozent * 2;
if (prozent == 100)
{

i++;
// grosses bild bei bedarf anpassen START
if (this._width>_global.picmaxbreite) {
this._width = _global.picmaxbreite;
this._yscale = this._xscale;

}
// grosses bild bei bedarf anpassen ENDE
if (i == 15)
{
this.loaded = true;
this._parent.counter_txt.text = "";
this._parent.loading_txt.text = "";
this._parent.status_mc._visible = 0;
delete i;

trace ("finished loading..."); // this is displayed !
// I have here the FX, but it doesn't start/show ??!!
new Tween(this, "_x", Bounce.easeOut, -100, 300, 1, true);
new Tween(this, "_alpha", Strong.easeOut, 0, 100, 5, true);
//

}
}
}
}


I check the picture to be loaded, and then want to start the FX ... but the TWEEN does not start. is this because it is in a movieclip???

Every help is appreciated...! Thanks in advance

Clark Kent

BLiZZaRD
02-09-2007, 02:54 PM
Instead of making Flash work triple time (Loading, Checking, Acting)

Why don't you "preload" your images off stage.

Make an emptyMovieClip() off stage, then attach each image into it, then use your code to bring it over from the eMC to the bildMC.

The picture will be loaded already, and you can use your working code that starts it right away.

Does that make sense?


Otherwise try this:



[trace ("finished loading..."); // this is displayed !
// I have here the FX, but it doesn't start/show ??!!
new Tween(_root.bild_mc, "_x", Bounce.easeOut, -100, 300, 1, true);
new Tween(_root.bild_mc, "_alpha", Strong.easeOut, 0, 100, 5, true);
//


As most of your this comes within a clipEvent handler... levels can get confusing to the movie.

clark kent
02-09-2007, 07:55 PM
Hi

Thank you very much for your reply.

Sadly I can't preload the images as the infos come from an external XML-File.
All pictures are loaded dynamically. Thumbs created and Big pictures display etc....
and there can be a lot of pictures in each galery...!

I also tried



new Tween(_root.bild_mc, "_x", Bounce.easeOut, -100, 300, 1, true);


doesn't work neither...

I am confused..?!

Is there a way to check on the main-timeline (where the tween would work) if the picture has loaded?

clark kent
02-09-2007, 08:07 PM
Oh no!!!

I found it ... and .... i think I must apologize with you...

what a stupid error! I really did'nt know...!

the problem was, that i have on the main-timeline this code:



import mx.transitions.Tween;
import mx.transitions.easing.*;


But I need to put it also on the clip-event!!!!!!!!!!!!!! so I had to put it also into bild_mc in order to work...It seems that in Flash, when you import the class on the main timeline and use it on a ClipEvent you have to re-import the class!!!!

Crazy! But I am happy I got the solution!!!!

Thanks to all

bye bye

BLiZZaRD
02-09-2007, 08:18 PM
Glad you got it... but err.. which ClipEvent are you using? on Load or on EnterFrame?

clark kent
02-10-2007, 11:23 AM
The new Code on the bild_mc is:



onClipEvent (load) {
import mx.transitions.Tween;
import mx.transitions.easing.*;
var i = 0;
}
onClipEvent (enterFrame) {
if (this._url != this._parent._url && !this.loaded)
{
.... here comes rest of code...


that's it...

thanks again,
greets

Clark Kent

BLiZZaRD
02-10-2007, 01:53 PM
Okay, I am just not used to seeing this code you have for the transitions. Seems to me you don't need it in both places.

It should HAVE to come in a clipEvent, which means it can't work on the main time line by itself... so you should be able to remove it from there, and only have it on the MC.