Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 19-08-2003, 13:28   #1 (permalink)
wum
Neuer User
 
Registriert seit: Aug 2003
Beiträge: 6
setInterval und attachMovie???

Verzeiht, Ich bin erst am Anfang.

folgendes Problem: Versuche 18 MC per AttachMovie in regelmässigem Abstand auf die Bühne zu kriegen.

Bei SetInterval verzögert sich der erste Aufruf entsprechend des Intervals, dann gehts immer gleich schnell ohne Berücksichtigung des Intervals. Was mach ich Falsch???

var Anzahl = 12;
Dauer = 1000;

// Erzeugen von 18 zufaellig verteilten und scalierten movie instanzen

HintergrundAnim = function () {

for (i = 1; i <= Anzahl; ++i) {
attachMovie("labmiddle", "labmiddle" + i,++i);

_root["labmiddle" + i]._x = Math.random() * 800;
_root["labmiddle" + i]._y = Math.random() * 600;
_root["labmiddle" + i]._rotation = 90 * (Math.floor(Math.random() *4));
_root["labmiddle" + i]._xscale = Math.random() * 75;
_root["labmiddle" + i]._yscale = _root["labmiddle" + i]._xscale;
}
}

HintergrundInterval = setInterval(HintergrundAnim, Dauer);


Danke für Eure Hilfe.
wum ist offline   Mit Zitat antworten
Alt 19-08-2003, 14:19   #2 (permalink)
Hirnverbrannt
 
Benutzerbild von NastyFrog
 
Registriert seit: Aug 2001
Ort: AUSTRIA
Beiträge: 2.020
Lass das for weg, das wird ohne Intervall dazwischen ausgeführt.
__________________
50 Seiten hardcore ActionScript von den Grundlagen bis zu 3D Darstellungen.... eben eine Abendlektüre.

Dogs fucked the Pope, no fault of mine. Watch out! ... Why money? My name is Brinks; I was born ... born? Get sheep over side ... women and children to armored car ... orders from Captain Zeep.(Hunter S. Thompson)
NastyFrog ist offline   Mit Zitat antworten
Alt 19-08-2003, 14:21   #3 (permalink)
Hirnverbrannt
 
Benutzerbild von NastyFrog
 
Registriert seit: Aug 2001
Ort: AUSTRIA
Beiträge: 2.020
Fast vergessen... Wilkommen im Forum.
__________________
50 Seiten hardcore ActionScript von den Grundlagen bis zu 3D Darstellungen.... eben eine Abendlektüre.

Dogs fucked the Pope, no fault of mine. Watch out! ... Why money? My name is Brinks; I was born ... born? Get sheep over side ... women and children to armored car ... orders from Captain Zeep.(Hunter S. Thompson)
NastyFrog ist offline   Mit Zitat antworten
Alt 19-08-2003, 17:02   #4 (permalink)
wum
Neuer User
 
Registriert seit: Aug 2003
Beiträge: 6
Danke für die Hilfe und das Willkommen. Schön bei Euch. Sorry, ich bin etwas langsam. Versuche das gesagte umzusetzen und zu verstehen, bevor ich reagiere. Leider anscheinend ohne Erfolg

hab ich das so richtig verstanden? Ich lasse das for weg. SetInterval ergibt von sich schon eine Schleife die solange ausgeführt wird, bis sie angehalten wird.

Ich hätte jetzt gedacht, mit diesem Code kriege ich 12 MC auf den screen. Var i und var HintergrundInterval erhöhen sich um 1 bis 12. dann ist schluss. Statt dessen spielt var i und var HintergrundInterval verrückt. Die Schleife läuft endlos. Wo ist mein Denkfehler?

Und wie kriege ich die 12 Mc auf die Bühne und dann im zeitlichen Abstand von 1000ms wieder 12 neue (alte müssen weg) usw.

Bin ich dümmer als die Polizei erlaubt? Hab ich Pflichtlekture versäumt?


var Anzahl = 12;
Dauer = 1000;
var HintergrundInterval;
var i = 0;

// Erzeugen von 18 zufaellig verteilten und scalierten movie instanzen

HintergrundAnim = function () {


attachMovie("labmiddle", "labmiddle" + i,++i);

_root["labmiddle" + i]._x = Math.random() * 800;
_root["labmiddle" + i]._y = Math.random() * 600;
_root["labmiddle" + i]._rotation = 90 * (Math.floor(Math.random() *4));
_root["labmiddle" + i]._xscale = Math.random() * 75;
_root["labmiddle" + i]._yscale = _root["labmiddle" + i]._xscale;

trace(i);
trace(HintergrundInterval);

if (i > 12) {
clearInterval(HintergrundInterval);
}

}


HintergrundInterval = setInterval(HintergrundAnim, Dauer);

__________________
Wum
Status: Noch am Strampeln
Motto: God help me, I'm just not that bright.
wum ist offline   Mit Zitat antworten
Alt 19-08-2003, 17:22   #5 (permalink)
HAY
Neuer User
 
Benutzerbild von HAY
 
Registriert seit: Aug 2002
Ort: Faust-Stadt
Beiträge: 2.577
hi
geht doch so.wie willst du sie wieder weg haben auf einmal
oder mit neuen überschreiben.
ActionScript:
  1. Anzahl = 12;
  2. Dauer = 1000;
  3. count = 1;
  4. HintergrundAnim = function () {
  5.     attachMovie("labmiddle", "labmiddle"+count, count);
  6.     _root["labmiddle"+count]._x = Math.random()*800;
  7.     _root["labmiddle"+count]._y = Math.random()*600;
  8.     _root["labmiddle"+count]._rotation = 90*(Math.floor(Math.random()*4));
  9.     _root["labmiddle"+count]._xscale = Math.random()*75;
  10.     _root["labmiddle"+count]._yscale = _root["labmiddle"+count]._xscale;
  11.     count++;
  12.     if (count>12) {
  13.         count=1
  14.         clearInterval(id);
  15.     }
  16. };
  17. id= setInterval(HintergrundAnim, Dauer);

[edit] in deinem script kommt i zum instanznamen dann wird i in der tiefe erhöht und sprichst instanznamen an die gar nicht vorhanden sind.[edit]
__________________
gruß Harry

Geändert von HAY (19-08-2003 um 17:33 Uhr)
HAY ist offline   Mit Zitat antworten
Alt 19-08-2003, 17:31   #6 (permalink)
Hirnverbrannt
 
Benutzerbild von NastyFrog
 
Registriert seit: Aug 2001
Ort: AUSTRIA
Beiträge: 2.020
Ok, setinterval und ein for sind 2 total verschiedene Dinge.
SetInterval: Eine Funktion wird alle x Millisekunden ausgeführt, bis clearInterval aufgerufen wird.
For: Der Body wird x mal ausgeführt und zwar ohne zeitlicher Verzögerung. Das gesamte For wird nur einmal ausgeführt und zwar innerhalb eines Frames.

Wenn du also beides zusammen hast, dann werden alle x Millisekunden 12 MCs attatcht und das so wie in deiner ersten Version praktisch in einer Endlosschleife.
__________________
50 Seiten hardcore ActionScript von den Grundlagen bis zu 3D Darstellungen.... eben eine Abendlektüre.

Dogs fucked the Pope, no fault of mine. Watch out! ... Why money? My name is Brinks; I was born ... born? Get sheep over side ... women and children to armored car ... orders from Captain Zeep.(Hunter S. Thompson)
NastyFrog ist offline   Mit Zitat antworten
Alt 19-08-2003, 17:41   #7 (permalink)
wum
Neuer User
 
Registriert seit: Aug 2003
Beiträge: 6
Das ist es. Funktioniert perfekt. Vielen Dank.

Aber warum hat sich meine Var i und die SetInterval Var so komisch verhalten.
__________________
Wum
Status: Noch am Strampeln
Motto: God help me, I'm just not that bright.
wum ist offline   Mit Zitat antworten
Alt 19-08-2003, 17:43   #8 (permalink)
HAY
Neuer User
 
Benutzerbild von HAY
 
Registriert seit: Aug 2002
Ort: Faust-Stadt
Beiträge: 2.577
hi
erklärung 3 post darüber
__________________
gruß Harry
HAY ist offline   Mit Zitat antworten
Alt 19-08-2003, 18:08   #9 (permalink)
wum
Neuer User
 
Registriert seit: Aug 2003
Beiträge: 6
AhHa Erlebnisse sind ja so schön.
Und am Anfang so selten.

Thx.
__________________
Wum
Status: Noch am Strampeln
Motto: God help me, I'm just not that bright.
wum ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 06:44 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele