Flash AS2 - bei Click variable ändern/laden
Nightstalker 08.04.2009 - 16:16 1722 1
Nightstalker
ctrl+alt+del
|
Hallo liebe Coder, stehe wieder vor einem kleinen Problem (ja ich bin zu blöd fürs coden lol). Folgendes, ich hab eine Textbox in die beim Laden ein zufallstext geladen wird, soweit ja ganz einfach weils ja genügen Anleitungen dazu gibt: Array.prototype.rand = function(nr,i,temp_1,temp_2) {
if(temp_1.length == undefined) {
var i = 0, temp_1 = [], temp_2 = [];
for(var j in this) temp_2.push(this[j]);
}
i++;
if(i<temp_2.length && i<nr) temp_2.rand(nr,i,temp_2,temp_2);
temp_1.push(temp_2.splice(random(temp_2.length),1));
return temp_1;
}
ASSetPropFlags(Array.prototype,"rand",1,1);
var tipp = new Array()
tipp[1] = "1..."
tipp[2] = "2..."
tipp[3] = "3..."
tipp[4] = "4..."
tipp[5] = "5..."
var tipps = (tipp.rand())
txt.variable = "tipps";
Was ich zum Schluss mache ist (und das hab ich nicht anders hinbekommen!?) ist das zufällige Array Element in eine Variable "tipps" zu packen und diese dann dem Dyn.Textfeld zuzuordnen indem der Text dann stehen soll. Das klappt wie gesagt super nur möchte ich nun eine weitere Funktion einbauen und zwar: Unter dem Textfeld möchte ich 2 butons mit denen ich vom aktuell geladenen Text zum nächsten oder vorigem springen kann. Ich möchte also bei klick auf > das nächste Element in dem Textfeld laden und bei < vice versa. Wie kann ich das nun am besten realisieren, der 1. Text (also onEnterFrame? oder onLoad?) soll immer zufällig geladen werden, dann soll per klick auf < oder > vom aktuellen Text immer der nächste oder vorige gezeigt werden, ihr wisst was ich meine lol. Danke!
|
Nightstalker
ctrl+alt+del
|
Hi so hab es nun gelöst bekommen, ich muss das ganze etwas anders angehen (wie vermutet). So sieht der Hauptteil aus mit dem Array usw.: var tipp = new Array();
tipp[0] = "1...";
tipp[1] = "2...";
tipp[2] = "3...";
tipp[3] = "4...";
tipp[4] = "5...";
// Gibt mir in einer Variablen die Anzahl der Einträge
arrend = ((tipp.length)-1)
// Funktion um eine zufällige Zahl zwischen 2 Zahlen auszugeben
function rand(min,max){
return random(max-min+1)+min
}
// Variable mit der zufäligen Zahl wobei "max" mit der Anzahl der Einträge im Arr. // befüllt wird.
var count = rand(0,arrend)
// Variuable für das Dyn. Textfeld die dann auf das Array verweißt wobei das Arr. Element in der Var. count definiert ist (die zu Beginn eine Zufallszahl ist).
mytxt = tipp[count];
So und nun hab ich 2 butons gemacht die einen eigenen AS Code haben Vorwärts: on (release) {
if (count == arrend) {
count = 0;
mytxt = tipp[count];
} else {
count = count+1;
mytxt = tipp[count];
trace(count)
}
}
Rückwärts: on (release) {
if (count == 0) {
count = arrend;
mytxt = tipp[count];
} else {
count = count-1;
mytxt = tipp[count];
trace(count)
}
}
Das funzt toll, wenn wer ne bessere Lösung hat bitte her damit ![;)](/images/smilies/wink.gif) Danke schonmal
|