Movieclip als button - Wie funktioniert der onClick?

Monsee

Grünschnabel
Hallo zusammen,

ich bastle seit Ewigkeiten mal wieder mit Flash (CS3).
Ich habe in einem Tutorial gelernt, wie man mit Hilfe von Movieclips animierte Buttons macht.

Lustigerweise hat der Auto aber vergessenm zu erzählen, wie ich denn diese Buttons funktionstüchtig mache :D.

Ich habe in meiner Szene1 die Movieclips b1 - b7 liegen. Für jedes Movieclip gibt es eine entsprechende Codezeile:

Code:
b1.onRollOver = over;
b1.onRollOut = out;

Die Funktionen, die oben aufgerufen werden sehen so aus:
Code:
function over() {
	this.gotoAndPlay(2)
}

function out() {
	this.gotoAndPlay(7)
}

Nichts leichter als das dachte ich:
"Mach ich doch oben einfach:"
Code:
b1.onPress = getURL("http://www.google.de","Blank");
und schon sollte es klappen. - Pustekuchen.

Ok, dann habe ich es mal so versucht:
Code:
b1.onRollOver = over;
b1.onRollOut = out;
b1.onPress = link;

Die function link() sieht so aus:
Code:
function link() {
	this.getURL("http://www.google.de","Blank");
}

Cool, das klappt, aber ich kann doch jetzt nicht für 7 Buttons 7 link-Funktionen schreiben. Also dachte ich mir folgendes: Eine Funktion link(), die die url mit übergibt und bei onPress aufgerufen wird:

Code:
b1.onRollOver = over;
b1.onRollOut = out;
b1.onPress = link("http://www.google.de");

Code:
function link(wert) {
var wert1 = wert
	this.getURL(wert1,"Blank");
}

Naja, leider klappt das auch nicht.
Kann mir jemand helfen?

Danke, mit besten Grüßen
Monsee.
 
In Actionscript 3 ist es:
Code:
bt1.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void {
  // text
}
 
Zuletzt bearbeitet:
Hallo tobee,

das hilft mir glaube ich jetzt nicht weiter,
denn ich habe das Projekt auf Actionscritpt 1.0 und 2.0 gestellt.
Weiterhin müsste ich doch für jeden Button eine neue Funktion schreiben - oder?

Gruß, Monsee
 
Hallo Monsee,

dein Code ist absolut richtig und sollte klappen. Kannst du deine Datei vielleicht hochladen?


Gruß
Matrix
 
Hallo Matrix,

hochladen ist leider schlecht, aber was ich bemerkt habe:
Code:
b1.onRollOver = over;
b1.onRollOut = out;
b1.onPress = link("http://www.google.de");
b1.buttonText.buttonText.text = "Link1";

b2.onRollOver = over;
b2.onRollOut = out;
b2.buttonText.buttonText.text = "Link2";

b3.onRollOver = over;
b3.onRollOut = out;
b3.buttonText.buttonText.text = "Link3";

b4.onRollOver = over;
b4.onRollOut = out;
b4.buttonText.buttonText.text = "Link4";

b5.onRollOver = over;
b5.onRollOut = out;
b5.buttonText.buttonText.text = "Link5";

b6.onRollOver = over;
b6.onRollOut = out;
b6.buttonText.buttonText.text = "Link6";

b7.onRollOver = over;
b7.onRollOut = out;
b7.buttonText.buttonText.text = "Link7";


function over(wert) {
	this.gotoAndPlay(2)
}

function out() {
	this.gotoAndPlay(7)
}

function link(wert) {
var wert1 = wert
	this.getURL(wert1,"Blank");
}

Wenn ich das Projekt ausführe, wird direkt google.de geöffnet.
Ohne, dass ich auf den Button drücken musste.

Gruß, -Monsee
 
Ach so, klar,

da wird die Funktion auch nur einmal direkt aufgerufen.

Wie wärs mit dieser Lösung?

PHP:
var myURLs:Array = new Array("www.google.de","www.google2.de");
for (var i = 0;i<myURLs.length;i++){
	this["b"+i].i = i;
	this["b"+i].onRollOver = over;
	this["b"+i].onRollOut = out;
	this["b"+i].onPress = function(){
		link(myURLs[this.i]);
	}
}
function over(wert) {
	this.gotoAndPlay(2)
}

function out() {
	this.gotoAndPlay(7)
}

function link(wert) {
	var wert1 = wert;
	this.getURL("http://"+wert1,"Blank");
}
 
Zurück