Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Actionscript Array gibt nur undefined zurück.

Empfohlene Antworten

Veröffentlicht

Holla,

ich habe ein kleines Actionscript in dem ich den Fehler nicht beheben kann. Ich hoffe ihr könnt mir helfen.

Das ganze soll ein kleines Puzzle sein. Wenn ich ein _root["puzzlebild" + i] nach dem Drag loslasse, wird die Funktion onRelease() aufgerufen. Dort will ich überprüfen, welcher _root["rahmen" + i] die geringste Entfernung zum _root["puzzlebild" + i] aufweist. Zuerst errechne ich die Distanzen mit getDistanceTo(x, y). Das Ergebnis dieser Funktion kann ich fehlerfrei mit trace() ausgeben. Wenn ich aber den Inhalt des Arrays ausgeben möchte

trace(distances[0]);
, kommt nur "undefined". Bei
trace(distances);
wird der Inhalt des Arrays komplett ausgegeben. Muss ich dem Array oder dem Rückgabewert der Funktion einen Datentyp zuweisen? Wie mache ich das? Woran kann das noch liegen? Vielen Dank im Voraus. Hier das Skript:
Puzzle2 = function(){

	for(var i = 1; i <= 10; i++){

		_root["rahmen" + i]._visible = true;

		_root["rahmen" + i].getDistanceTo = function(x, y){

			return Math.sqrt(Math.pow((this._x-47.2) -(x ),2) + Math.pow((this._y-37.5) -(y) ,2));

		}

		_root["puzzlebild" + i]._y += 200;

		_root["puzzlebild" + i].onPress = function(){

			startDrag(this);

		}

		_root["puzzlebild" + i].onRelease = function(){

			stopDrag();

			var distances =  new Array();

			distances[0] = rahmen1.getDistanceTo(this._x, this._y);

			distances[1] = rahmen2.getDistanceTo(this._x, this._y);

			distances[2] = rahmen3.getDistanceTo(this._x, this._y);

			distances[3] = rahmen4.getDistanceTo(this._x, this._y);

			distances[4] = rahmen5.getDistanceTo(this._x, this._y);

			distances[5] = rahmen6.getDistanceTo(this._x, this._y);

			distances[6] = rahmen7.getDistanceTo(this._x, this._y);

			distances[7] = rahmen8.getDistanceTo(this._x, this._y);

			distances[8] = rahmen9.getDistanceTo(this._x, this._y);

			distances[9] = rahmen10.getDistanceTo(this._x, this._y);

			var min:Number = 0;

			var minDistance:Number = (800*600);

			trace("minDistance: " + minDistance);

			for(var i = 0; i < 10; i++){

					trace("i:" + i);

					trace("min:" + min);

					trace("Distance i: " + Number(distances[i]));

					trace("minDistance: " + minDistance);

				if(Number(distances[i]) < minDistance){

					min = i;

					minDistance = distance[i];

				}

			}

			if(_root["rahmen"+(min+1)].hitTest(this)){

				this._x = _root["rahmen"+min]._x;

				this._y = _root["rahmen"+min]._y;				

			}

		}

	}

}

Puzzle2();

btnFertig.onRelease = function(){

	gotoAndPlay("Auswertung");

}

stop();

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.