Actionscript von Movieclip auch bei Schaltfläche

Christofk

Erfahrenes Mitglied
Hi Leute,

ich habe mal wieder ein kleines Problem. Ich hab mir ein paar schöne Buttons erstellt ( Schaltflächen) beim Darüberfahren kommt ein Sound , und wenn ich vom einen Button zum anderen fahre wird die Maus von einer Krempe verfolgt.

Ich habe dank Datic das Tutorial "externe Flash Dateien laden" erfplgreich bewältigt.
Nun möchte ich dieses jedoch in meine Seite einbauen. In dem Tutorial liegt das Actionscript auf Movieclips und in meinem Fall brauche ich das auf Schaltflächen, da diese ja die Sound beim Mouseover haben.

das ist der Code aus dem Tutorials auf den Movieclips und diesen möchte ich nun zu dem Actionscript meiner schaltflächen hinzufügen: das findet ihr weiter unten:

PHP:
this.onEnterFrame = function() {
	// Festlegen der Beschriftungen der Buttons:
	button1.setText("1");
	button2.setText("2");
	button3.setText("3");
	delete this.onEnterFrame;
}

var currentContent = 0; // Aktueller Inhalt (0 = keiner)

function setContent(bname) {
	var new_content = int(bname.substr(bname.length - 1, 1)); // Nummer holen
	if (new_content > 0 && new_content != current_content) {
		if (current_content != 0) {
			switchContent(new_content); // Inhalt wechseln
		} else {
			loadContent(new_content); // Inhalt direkt laden
		}
	} else {
		switchContent(0); // Inhalt ausblenden
		current_content = 0;
	}
}

function switchContent(nc) {
	current_content = 0; // Auf Null setzen, damit neue Inhalte schnell angezeigt werden können
	this.onEnterFrame = function() {
		container._alpha += (0 - container._alpha) / 2; // Container ausblenden
		if (container._alpha < 1) {
			container._alpha = 0;
			if (nc > 0) {
				loadContent(nc); // Neuen Inhalt laden, 
			} else {
				delete this.onEnterFrame; // oder anhalten, wenn kein Inhalt
			}
		}
	}
}

function loadContent(nc) {
	var stime = getTimer(); // Zeitstempel merken
	loader.loadContent(container, getContentName(nc)); // Inhalt laden lassen
	this.onEnterFrame = function() {
		container._alpha = 0;
		if (loader.isloaded == true) { // Wenn geladen:
			current_content = nc; // Aktuellen Inhalt setzen
			appearContent(); // Inhalt anzeigen
		}
		if (getTimer() - stime > 8000) { // Timeout beim Laden:
			current_content = 0; // Auf Null setzen
			container._alpha = 0;
			delete this.onEnterFrame;
		}
	}
}

function appearContent() {
	this.onEnterFrame = function() {
		container._alpha += (100 - container._alpha) / 2; // Inhalt einblenden
		if (container._alpha > 99) {
			container._alpha = 100;
			delete this.onEnterFrame; // Anhalten
		}
	}
}

function getContentName(nr) {
	switch(nr) {
		case 1: return "test4.swf"; break;
		case 2: return "test5.swf"; break;
		case 3: return "test3.swf"; break;
	}
	return "nofile.swf";
}

Schaltflächenscript

PHP:
if (_global.wahl ==1) {
	if (this.krempe_mc._x>196) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -196)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((196 - this.krempe_mc._x )/5);

	}
}
}

if (_global.wahl ==2) {
	if (this.krempe_mc._x>280) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -280)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((280 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==3) {
	if (this.krempe_mc._x>364.5) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -364.5)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((364.5 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==4) {
	if (this.krempe_mc._x>449.0) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -449.0)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((449.0 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==5) {
	if (this.krempe_mc._x>533.5) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -533.5)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((533.5 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==6) {
	if (this.krempe_mc._x>618.5) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -618.5)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((618.5 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==7) {
	if (this.krempe_mc._x>703.5) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -703.5)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((703.5 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==8) {
	if (this.krempe_mc._x>788.5) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -788.5)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((788.5 - this.krempe_mc._x )/5);

	}
	}
}

if (_global.wahl ==9) {
	if (this.krempe_mc._x>873.5) {

	with (this.krempe_mc) {
			this.krempe_mc._x = this.krempe_mc._x -((this.krempe_mc._x -873.5)/5);

	}
	} else {
		with (this.krempe_mc) {
			
			this.krempe_mc._x = this.krempe_mc._x +((873.5 - this.krempe_mc._x )/5);

	}
	}
}


Ich höffe wirklich ihr versteht mein Problem, danke im Vorraus. Christof K
 
Hi,

was Du gepostet hast, ist nicht der Code auf den Buttons, sondern der auf der Hauptzeitleite - und der kann durchaus so bleiben. Alles, was Deine Buttons tun müssen, ist beim Klicken die Funktion "setContent" auf der Hauptzeitleiste aufzurufen, und dieser ihren Namen zu übergeben:
PHP:
on (release) {
    _root.setContent(this._name);
}
Das kannst Du jeweils direkt auf die Instanzen der Schaltflächen schreiben, da Du in einer Schaltfläche direkt keinen Code eingeben kannst.

Nun musst Du den Schaltflächen nur noch Instanznamen zuweisen, die mit einer fortlaufenden Nummer enden (z.B. button1, button2 usw.) und die Funktion "getContentName" auf der Hauptzeitleiste so ändern, dass die von Dir gewünschten Dateinamen zurückgegeben werden.

Gruß
.
 
Zurück