Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 07-04-2007, 16:08   #1 (permalink)
Neuer User
 
Registriert seit: Mar 2005
Beiträge: 8
onRelease auf dynamischem MC

Hallo,

ich versuche gerade mehreren in einer Schleife erzeugten MCs eine ID an ihre onRelease-Funktionen mitzugeben. Diese Fumktion soll dann eine URL aufrufen, die in b_Link[] gespeichert ist. Mein Problem ist nun, daß die ID nicht richtig übergeben wird. Als ich am Anfang nicht daran gedacht hatte, die alten MCs am Anfang der Funktion zu löschen, hat es zumindest beim zweiten Aufruf der Funktion funktioniert. Jetzt gibt das trace in der ballonGetUrl-Funktion nur "undefined" aus. Die neuen MCs werden aber aufgabut und angezeigt.

Erklärungen zum Code:
Jedes "Ballon"-Objekt hat eine Instanzvariable "ID"
ballons[]: Array mit bereits bestehenden Ballon-Objekten
IDS[]: Array mit den IDs der bereits bestehenden Ballon-Objekten in ballons[]
(mc.ID muss nicht ballons[ID].ID sein)

Ich wäre für jede Hilfe dankbar.

Hier nun der meiner Meinung nach relevante Code:
Code:
function ballonGetUrl(ID) {
	trace("ID: " + ID);
	trace("Link: " + b_Link[ID]);
	//getURL("http://"+b_Link[ID]);
}

function makeZoom(IDS:Array, ID) {
	removeMovieClip(_root.Zoom);
	zoomballons = [];
	_root.createEmptyMovieClip("Zoom", _root.getNextHighestDepth());
	_root.Zoom._x = 200;
	_root.Zoom._y = 400;
	for (var i = 0; i<IDS.length; i++) {
		_root.Zoom.attachMovie("Ballon", "Ballon"+i, _root.Zoom.getNextHighestDepth());
		zoomballons.push(eval("_root.Zoom.Ballon"+i));
		zoomballons[i].ID = ballons[IDS[i]].ID;
		zoomballons[i].onRelease = function(){
			ballonGetUrl(this.ID);
			};
		
	}

}
C.Hammer ist offline   Mit Zitat antworten
Alt 07-04-2007, 16:16   #2 (permalink)
................
 
Benutzerbild von Der Frager
 
Registriert seit: Jun 2004
Beiträge: 15.890
Hallo und willkommen im Forum!

Den Aufbau habe ich nicht ganz kapiert. Aber das hier
PHP-Code:
zoomballons[i].ID ballons[IDS[i]].ID
kommt mit irgendwie spanisch vor.
Mal so'n Schuss ins Blaue:
PHP-Code:
function makeZoom(IDS:Array, ID) {
    
removeMovieClip(_root.Zoom);
    
zoomballons = [];
    
_root.createEmptyMovieClip("Zoom"_root.getNextHighestDepth());
    
_root.Zoom._x 200;
    
_root.Zoom._y 400;
    for (var 
0i<IDS.lengthi++) {
        
zoomballons.push(_root.Zoom.attachMovie("Ballon""Ballon"+i_root.Zoom.getNextHighestDepth()));
        
zoomballons[i].ID IDS[i];
        
zoomballons[i].onRelease = function() {
            
ballonGetUrl(this.ID);
        };
    }

Sonst bräuchte man schon den gesamten relevanten Code.
__________________

ternärer Konditionaloperator

+++ Bitte keine Privat-Nachrichten bezüglich Flashfragen! +++
Der Frager ist offline   Mit Zitat antworten
Alt 07-04-2007, 16:25   #3 (permalink)
Neuer User
 
Registriert seit: Mar 2005
Beiträge: 8
Hallo,

danke für die schnelle Antwort und das Willkommen.

Die ID-Zuweisung passt schon, wenn ich nach
Code:
zoomballons[i].ID = ballons[IDS[i]].ID;
trace bekomme ich auch die richtige ID angezeigt. IDS[i] ist nur die Position des MCs in ballons[]. Bei ballon[id].ID muss id nicht zwingend ID sein.

Hier der gesammte Code (schlecht kommentiert, wie es halt so ist wenn mans eilig hat, tut mir leid):

Code:
var testString = "";
stop();
phpFile = "http://localhost:85/ballonmillion/db2.php?";
b_Text = [];
b_Farbe = [];
b_XK = [];
b_YK = [];
b_KOO = [];
b_Spez = [];
b_EMail = [];
b_Link = [];
b_currID = 0;
ballons = [];
cluster = [];
zoomballons = [];
b_koordinaten = [];
XMLdaten = new XML();
XMLkoordinaten = new XML();
ballonWidth = 1;
ballonHeight = 1;

makeBallons();
XMLkoordinaten.load(phpFile+"modus=4&query=select%20*%20from%20koordinaten where Aktiv = 1 limit 12000");
XMLkoordinaten.onLoad = function(success) {
	//Datei wird gerade geladen
	//Laden der Daten der Koordinaten (X, Y, Farbe) und überführen in die Arrays
	if (success) {
		for (var i = 0; i<XMLkoordinaten.firstChild.childNodes.length; i++) {
			b_koordinaten[XMLkoordinaten.firstChild.childNodes[i].attributes.I] = new koo();
			b_koordinaten[XMLkoordinaten.firstChild.childNodes[i].attributes.I].xK = XMLkoordinaten.firstChild.childNodes[i].attributes.X;
			b_koordinaten[XMLkoordinaten.firstChild.childNodes[i].attributes.I].yK = XMLkoordinaten.firstChild.childNodes[i].attributes.Y;
			b_koordinaten[XMLkoordinaten.firstChild.childNodes[i].attributes.I].farbe = XMLkoordinaten.firstChild.childNodes[i].attributes.F;
			b_koordinaten[XMLkoordinaten.firstChild.childNodes[i].attributes.I].ballonID = XMLkoordinaten.firstChild.childNodes[i].attributes.B;
		}
		loadBallonKoo();
	}
};
//Lädt die Aktiven Koordinatenpaare aus der Datenbank (Modus 4 ist gür Tabelle Koordinaten);
XMLdaten.load(phpFile+"modus=1&query=select%20*%20from%20ballons");
XMLdaten.onLoad = function(success) {
	//Datei wird gerade geladen
	if (success) {
		//wenn das laden der File erfolgreich war
		//Laden der Daten der Ballons (Text, URL, E-Mail, usw.) und überführen in die jeweiligen Arrays
		for (i=0; i<XMLdaten.firstChild.childNodes.length; i++) {
			b_currID = XMLdaten.firstChild.childNodes[i].attributes.I;
			b_Text[b_currID] = XMLdaten.firstChild.childNodes[i].attributes.T;
			b_Spez[b_currID] = XMLdaten.firstChild.childNodes[i].attributes.S;
			b_EMail[b_currID] = XMLdaten.firstChild.childNodes[i].attributes.E;
			b_Link[b_currID] = XMLdaten.firstChild.childNodes[i].attributes.L;
			b_KOO[b_currID] = XMLdaten.firstChild.childNodes[i].attributes.K;
		}
		fillText();
		//gotoAndStop(nextFrame()); 	
	}
};
function setNewColor(mc:MovieClip, myColor:Number) {
	newColor = new Color(mc);
	newColor.setRGB(myColor);
}
function miniPress(ID) {
	trace("ID: "+ID);
}
function makeBallons() {
	for (e=0; e<120; e++) {
		var i = 0;
		//Erzeugen der Cluster
		_root.attachMovie("Cluster", "Cluster"+e, this.getNextHighestDepth());
		//schiebt alle Ballons des Clusters in das Array ballons
		for (j=0; j<10; j++) {
			ballons.push(eval("Cluster"+e+".B"+j));
			eval("Cluster"+e+".B"+j)._visible = false;
			eval("Cluster"+e+".B"+j).ID = (e*10+j);
			//trace(e*10+j);
			//eval("Cluster"+e+".B"+j).onRelease = function(){trace(this.ID)}
		}
	}
}
function loadBallonKoo() {
	for (var i = 0; i<b_koordinaten.length; i++) {
		var bID = b_koordinaten[i].ballonID;
		//ID des Ballons der dem Koo-Objekt zugewiesen wird
		if (bID != 0) {
			ballons[bID]._x = b_koordinaten[i].xK*ballonWidth;
			ballons[bID]._y = b_koordinaten[i].yK*ballonHeight;
			setNewColor(ballons[bID].bFarbe, b_koordinaten[i].farbe);
			ballons[bID].ID = bID;
			ballons[bID].onRelease = function() {
				getNeighborhood(this.ID);
			};
			ballons[bID]._visible = true;
		}
		warten._visible = false;
	}
}
function fillText() {
	for (var i = 0; i<b_Text.length; i++) {
		ballons[i].bText.text = b_Text[i];
	}
}
function ballonGetUrl(ID) {
	trace("ID: " + ID);
	trace("Link: " + b_Link[ID]);
	//getURL("http://"+b_Link[ID]);
}
function getNeighborhood(ID) {
	var XMLTemp = new XML();
	XMLTemp.load(phpFile+"modus=5&XK="+ballons[ID]._x+"&YK="+ballons[ID]._y);
	XMLTemp.onLoad = function(success) {
		var IDS = [];
		if (success) {
			for (var i = 0; i<XMLTemp.firstChild.childNodes.length; i++) {
				IDS.push(XMLTemp.firstChild.childNodes[i].attributes.I);
				trace("IDS: "+IDS[i]);
			}
			trace("IDS.length: "+IDS.length);
			makeZoom(IDS, ID);
		}
	};
}
function makeZoom(IDS:Array, ID) {
	removeMovieClip(_root.Zoom);
	zoomballons = [];
	_root.createEmptyMovieClip("Zoom", _root.getNextHighestDepth());
	_root.Zoom._x = 200;
	_root.Zoom._y = 400;
	for (var i = 0; i<IDS.length; i++) {
		//_root.removeMovieClip(eval("Zoom.Ballon"+i))
		_root.Zoom.attachMovie("Ballon", "Ballon"+i, _root.Zoom.getNextHighestDepth());
		zoomballons.push(eval("_root.Zoom.Ballon"+i));
		trace(zoomballons[i]);
		zoomballons[i]._x = (ballons[IDS[i]]._x - ballons[ID]._x)*10;
		zoomballons[i]._y = (ballons[IDS[i]]._y - ballons[ID]._y)*10;
		zoomballons[i].ID = ballons[IDS[i]].ID;
		trace("ID: " + zoomballons[i].ID);
		newColor = new Color(zoomballons[i].bFarbe);
		newColor.setRGB(b_koordinaten[IDS[i]].farbe);
		zoomballons[i].bText.text = ballons[IDS[i]].bText.text;
		trace("_XSCALE: "+ zoomballons._xscale);
		zoomballons[i]._xscale *= 13;
		zoomballons[i]._yscale *= 13;
		zoomballons[i].onRelease = function(){
			ballonGetUrl(this.ID);
			};
		
	}

}
C.Hammer ist offline   Mit Zitat antworten
Alt 07-04-2007, 16:31   #4 (permalink)
................
 
Benutzerbild von Der Frager
 
Registriert seit: Jun 2004
Beiträge: 15.890
...und bei dem trace() hier, in der Funktion makeZoom() kommt der richtige Wert raus?
PHP-Code:
trace("ID: " zoomballons[i].ID); 
__________________

ternärer Konditionaloperator

+++ Bitte keine Privat-Nachrichten bezüglich Flashfragen! +++
Der Frager ist offline   Mit Zitat antworten
Alt 07-04-2007, 16:32   #5 (permalink)
Neuer User
 
Registriert seit: Mar 2005
Beiträge: 8
Ja. Zeigt an was er soll.
C.Hammer ist offline   Mit Zitat antworten
Alt 07-04-2007, 17:09   #6 (permalink)
Neuer User
 
Registriert seit: Mar 2005
Beiträge: 8
Wenn ich die Zeile 122
Code:
removeMovieClip(_root.Zoom);
lösche und die Funktion zweimal ausführe, hat er plötzlich einen Link auch wenn der MC dann nicht mehr das tut was er soll, da er zuviele und zu große Objekte enthält.
C.Hammer 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 23:56 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele