Seite 1 von 1

Problem mit Action Script

Verfasst: 9. Feb 2010, 00:17
von Daki
Hi,

habe ein ActionScript zur Bildüberblendung im Internet gefunden. Da ich mich mit AS nicht so gut auskenne (eigentlich garnicht =( ), habe ich diesbezüglich eine Frage: Wie kann ich bei folgendem Script die Position des geladenen Movie Clips bestimmen?
Das Problem ist nämlich, dass wenn ich die Bilder laufen lasse, sie irgendwo auf der Bühne sind und ich hätte sie gerne zentriert. Wissen tu ich nur, dass die Maximalwerte der Höhe und Breite der geladenen Bilder 1000px sind.
Path = "/"

Pictures = new Array()
Pictures[0] = "MT1.jpg";
Pictures[1] = "MT2.jpg";
Pictures[2] = "MT3.jpg";
Pictures[3] = "MT4.jpg";

for(p = 0; p < Pictures.length; p++){
_root.createEmptyMovieClip("Pic" + p, 666 + p);
_root["Pic" + p]._alpha = 0;
_root["Pic" + p].loadMovie(Path + Pictures[p]);


//Zentrieren
_root["Pic" + p]._y = Stage.height/2-(_root["Pic" + p].height/2);
_root["Pic" + p]._x = Stage.width/2-(_root["Pic" + p].width/2);

// Funktioniert überhaupt nicht .. =(
}
Active = 0

function switching(){
Active ++
if(Active == Pictures.length){
Active = 0
}

ActivePic = _root["Pic" + Active]
fadePic()
}


function fadePic(){
FadeOut = new mx.transitions.Tween(OldPic, "_alpha", mx.transitions.easing.Regular.easeInOut , 100, 0, 4, true);

FadeIn = new mx.transitions.Tween(ActivePic, "_alpha", mx.transitions.easing.Regular.easeInOut , 0, 100, 2, true);
FadeIn.onMotionFinished = function(){
OldPic = ActivePic
}
}

switching()
setInterval(switching, 4000)

Re: Problem mit Action Script

Verfasst: 9. Feb 2010, 16:15
von Daki
Durch langes googlen hab ich herausgefunden, dass das Bild erst geladen werden muss, damit die Größe mit _width und _height auslesbar ist. Nun hab sieht mein Script so aus:


Naja jetzt trennt mich ne kleine Frage von der Lösung: Wieso ist mc_listener.onLoadInit = function() immer false? =(
Path = "/"

Pictures = new Array()
Pictures[0] = "MT1.jpg";
Pictures[1] = "MT2.jpg";
Pictures[2] = "MT3.jpg";
Pictures[3] = "MT4.jpg";
Pictures[4] = "MT5.jpg";
Pictures[5] = "MT6.jpg";
Pictures[6] = "MT7.jpg";
Pictures[7] = "MT8.jpg";
Pictures[8] = "MT9.jpg";
Pictures[9] = "MT10.jpg";
Pictures[10] = "MT11.jpg";
Pictures[11] = "MT12.jpg";
Pictures[12] = "MT13.jpg";
Pictures[13] = "MT14.jpg";
Pictures[14] = "MT15.jpg";
Pictures[15] = "MT16.jpg";
Pictures[16] = "MT17.jpg";
Pictures[17] = "MT18.jpg";
Pictures[18] = "MT19.jpg";
Pictures[19] = "MT20.jpg";
Pictures[20] = "MT21.jpg";
Pictures[21] = "MT22.jpg";

mc_listener = new Object(); //Neues Listener Objekt erstellen

mc_listener.onLoadInit = function()
{
trace("INIT");
//Hier kommt dann die Berechnung der Position rein..
}


for(p = 0; p < Pictures.length; p++)
{
_root.createEmptyMovieClip("Pic" + p, 666 + p);
_root["Pic" + p]._alpha = 0;
_root["Pic" + p].loadMovie(Path + Pictures[p]);
}

_root["Pic" + (Pictures.length - 1)].addListener(mc_listener);

Active = 0

function switching(){
Active ++
if(Active == Pictures.length){
Active = 0
}

ActivePic = _root["Pic" + Active]
fadePic()
}


function fadePic(){
FadeOut = new mx.transitions.Tween(OldPic, "_alpha", mx.transitions.easing.Regular.easeInOut , 100, 0, 4, true);

FadeIn = new mx.transitions.Tween(ActivePic, "_alpha", mx.transitions.easing.Regular.easeInOut , 0, 100, 2, true);
FadeIn.onMotionFinished = function(){
OldPic = ActivePic
}
}



switching()
setInterval(switching, 4000)