Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 22-11-2007, 02:21   #1 (permalink)
Neuer User
 
Benutzerbild von denniz
 
Registriert seit: Aug 2006
Beiträge: 282
Cool eventDispatcher will nicht mit registerClass

Hi Leute,

ich instanziere 4 Grüne Buttons sowie ein Roten Button dynamisch auf die Bühne.
Die Buttons habe in ihrer Klassenfunktion stehen was die zu tun haben.
Also wenn man auf einen Grünen Button klickt soll der Rote Button sich an die _x position des Grünen Buttons bewegen.
Ich habe das alles über prototype + eventDispatcher gelöst. Das klappt auch wunderbar.
Das AS:
Code:
import mx.events.EventDispatcher;
var _t = this;

MovieClip.prototype.setRedButton = function() {
	this.onEventFired = function(evt:Object) {
		this._x = evt._pos;
	};
};
MovieClip.prototype.setGreenButton = function() {
	EventDispatcher.initialize(this);
	this.addEventListener("onEventFired", _t.con.btnRed);
	var pos = this._x;
	this.onPress = function() {
		trace(this._idx);
		this.dispatchEvent({type:"onEventFired", _pos:pos});
	};
};
function init() {
	for (i=0; i<=3; i++) {
		var btn:MovieClip = _t.attachMovie("btnGreen", "btnGreen"+i, _t.getNextHighestDepth());
		btn._x = 75*i;
		btn._y = 350;
		btn._idx = i;
		if (i == 0) {
			var btnRed:MovieClip = _t.con.attachMovie("btnRed", "btnRed", 1000);
			btnRed._x = 0;
			btnRed._y = 250;
			btnRed.setRedButton();
		}
		btn.setGreenButton();
	}
}
init();
Jetzt hab ich genau das gleiche skript versucht mit object.RegisterClass aufzubauen, klappt aber nicht , der event wird nicht ausgeführt.
Das AS:
Code:
import mx.events.EventDispatcher;
var _t = this;


function setGreenButton() {
	EventDispatcher.initialize(this);
	this.addEventListener("onEventFired", _t.con.btnRed);
	var pos = this._x;
	this.onPress = function() {
		trace(this._idx);
		this.dispatchEvent({type:"onEventFired", _pos:pos});
	};
}
function setRedButton() {
	this.onEventFired = function(evt:Object) {
		this._x = evt._pos;
	};
}
function init() {
	for (i=0; i<=3; i++) {
		var btn:MovieClip = _t.attachMovie("btnGreen", "btnGreen"+i, _t.getNextHighestDepth());
		btn._x = 75*i;
		btn._y = 350;
		btn._idx = i;
		if (i == 0) {
			var btnRed:MovieClip = _t.con.attachMovie("btnRed", "btnRed", 1000);
			btnRed._x = 0;
			btnRed._y = 250;
		}
	}
}
setRedButton.prototype = new MovieClip();
setGreenButton.prototype = new MovieClip();
Object.registerClass("btnRed", setRedButton);
Object.registerClass("btnGreen", setGreenButton);
init();
Was ist an dem unterem skript falsch?
Hier die Fla.
Ich weiß ist AS1.0 OOP,also bitte nicht hauen ;-) , irgendwie muß man es ja lernen.
Plz help.

GRuß
denniz 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 08:32 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele