Zurück   Flashforum > Flash > ActionScript > ActionScript 3

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 10-02-2011, 23:24   #1 (permalink)
| ||[ PIXON ] ||
 
Benutzerbild von pixon
 
Registriert seit: Apr 2002
Beiträge: 364
last added child

hallo!
ich habe ein kleines menü mit 5 buttons. wenn ich einen der buttons klicke, dann wird ein bestimmter movieclip aus der library geadded. nun habe ich leider das problem das sich diese überlappen, sobald ich einen anderen button klicke. gibt es eine funktion die den zuletzt hinzugefügten movieclip wieder entfernt?

Code:
package 
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;


	public class IndexAs extends MovieClip
	{
		public var menu:MovieClip = new MovieClip();
		public var ff:MovieClip = new MovieClip();
		public var punkte_mc:MovieClip = new Punkte_mc();
		public var linien_mc:MovieClip = new Linien_mc();
		public var formen_mc:MovieClip = new Formen_mc();
		public var flaechen_mc:MovieClip = new Flaechen_mc();



		public function IndexAs()
		{
			menu.alpha = 0;
			menu.addEventListener(MouseEvent.ROLL_OVER, mOver);
			menu.addEventListener(MouseEvent.ROLL_OUT, mOut);
			menu.addEventListener(MouseEvent.CLICK, clicked);
			ff.addEventListener(MouseEvent.CLICK, sClick);
		}
		
		function clicked(e:MouseEvent):void
		{
			switch(e.target.name)
			{
				case "punkt_btn" :
					addChild(punkte_mc);
					break;
				case "linie_btn" :
					addChild(linien_mc);
					break;
				case "form_btn" :
					addChild(formen_mc);
					break;
				case "flaeche_btn" :
					addChild(flaechen_mc);
					break;
				case "ani_btn" :
					// loadMovie?
					break;
			}
			
		}
		
		function mOver(e:MouseEvent):void
		{
			var tIn:Tween = new Tween(e.currentTarget,"alpha",Strong.easeOut,0,1,0.5,true);
		}
		
		function mOut(e:MouseEvent):void
		{
			var tOut:Tween = new Tween(e.currentTarget,"alpha",Strong.easeOut,1,0,0.5,true);
		}
		
		
		function sClick(e:MouseEvent):void
		{
			punkte_mc.play();
		}
	}

}
pixon ist offline   Mit Zitat antworten
Alt 10-02-2011, 23:53   #2 (permalink)
ING
whatever
 
Registriert seit: May 2008
Beiträge: 419
da hilft dir eine weitere variable weiter...

ActionScript:
  1. public var last_mc:MovieClip; // diesmal bleibt es ein null objekt!!!
  2.  
in deine clicked funktion kommt dann

ActionScript:
  1. if (last_mc) removeChild(last_mc);
danach im switch das handle des neu hinzugefügten mc in last_mc speichern, zb.
ActionScript:
  1. last_mc = punkte_mc;

ps: das "var tIn:Tween =" und "var tOut:Tween =" kannst du auch weglassen, ist überflüßig
ING ist offline   Mit Zitat antworten
Alt 11-02-2011, 00:21   #3 (permalink)
| ||[ PIXON ] ||
 
Benutzerbild von pixon
 
Registriert seit: Apr 2002
Beiträge: 364
wow! ich bin begeistert!
könntest du mir noch einen kleinen tipp geben? und zwar soll beim click auf den letzten button (ani_btn) ein externes swf geladen werden, in dem wiederum auch externe swfs, je nach aktion, geladen werden. die externe swf datei ist ein eigenständiger film mit einer eigenen klasse. wie sollte ich es anstellen damit sich die beiden nicht in die quere kommen?
pixon ist offline   Mit Zitat antworten
Alt 11-02-2011, 00:42   #4 (permalink)
ING
whatever
 
Registriert seit: May 2008
Beiträge: 419
dafür gibt das loader objekt...

ActionScript:
  1. public var ani_mc:Loader = new Loader();
im switch kannst du dann laden...

ActionScript:
  1. ani_mc.load(new URLRequest("www.whatever.de/myMovie.swf"));
der loader funktioniert genau wie ein mc, du kannst also mit x & y die position bestimmen, es mit visible ausblenden usw.

allerdings musst du nun eine kleine änderung vornehmen und last_mc als typ DisplayObject festlegen weil da nun auch ein loader objekt zwischengespeichert werden kann.

du solltest dir auch eine bool variable setzen in der du dir merkst ob der film schon geladen wurde damit du nicht erneut lädst wenn man zweimal den letzten button klickt.
ING ist offline   Mit Zitat antworten
Alt 11-02-2011, 01:02   #5 (permalink)
| ||[ PIXON ] ||
 
Benutzerbild von pixon
 
Registriert seit: Apr 2002
Beiträge: 364
leider kommt ein error zurück:
Code:
TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
	at GestureNavi()
die swf die reingeladen wird heißt GestureNavi.swf und deren Klasse ebenso. Vielleicht kommt sich da doch was in die quere?
pixon ist offline   Mit Zitat antworten
Alt 11-02-2011, 01:20   #6 (permalink)
ING
whatever
 
Registriert seit: May 2008
Beiträge: 419
was soll sich den da in die quere kommen? es spielt sich alles im loader ab und die beiden klassen objekte kennen sich noch nichtmal gegenseitig. das ist as3, wenn sich da was in die quere kommen soll muss man das schon explizit so programmieren

wie du der fehlermeldung (komisch warum sie dir jetzt angezeigt wird) sitzt das problem auch in der GestureNavi und rein zufallig ist es ein null objekt problem, also das worauf ich dich schon paarmal hingewiesen hatte

du hast diesen fehler auch in der GestureNavi gemacht, ohne das script kann ich dir aber natürlich nicht sagen wo.
ING ist offline   Mit Zitat antworten
Alt 11-02-2011, 02:13   #7 (permalink)
| ||[ PIXON ] ||
 
Benutzerbild von pixon
 
Registriert seit: Apr 2002
Beiträge: 364
die flash IDE ist echt blöd. die gibt keine Fehler aus wenn ich GestureNavi compile.
Code:
package 
{

	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import flash.ui.Mouse;



	import com.foxaweb.ui.gesture.*;

	public class GestureNavi extends MovieClip
	{

		private var mg:MouseGesture;

		public var draw_mc:MovieClip;
		public var kasten_mc:MovieClip;

		private var timer:Timer;
		private var fadeTween:Tween;

		private var currentContent:DisplayObject;
		private var currentTarget:DisplayObject;


		private var movementPattern:String = "R";

		//private var myPatterns:Array = new Array("bla","bli","blu");
		private var myPatterns:Array = new Array("1","2","3");

		private var indexPattern:int = 0;
		var disk:DiskCursor = new DiskCursor();

		




		public function GestureNavi()
		{
			disk.mouseEnabled = false;
			stage.scaleMode = "noScale";

			mg = new MouseGesture(stage);
			mg.addGesture("O","6");
			mg.addGesture("U","2");
			mg.addGesture("R","0");
			mg.addGesture("L","4");
			mg.addGesture("RO","7");
			mg.addGesture("LU","3");
			mg.addGesture("LO","5");
			mg.addGesture("RU","1");

			mg.addGesture("NEXT",".");

			timer = new Timer(10,1);
			timer.addEventListener(TimerEvent.TIMER,fadeDrawing);

			//_root.addEventListener(MouseEvent.CLICK,nextmuster);
			mg.addEventListener(GestureEvent.GESTURE_MATCH,matchHandler);
			mg.addEventListener(GestureEvent.NO_MATCH,noMatchHandler);
			mg.addEventListener(GestureEvent.START_CAPTURE,startHandler);
			mg.addEventListener(GestureEvent.STOP_CAPTURE,stopHandler);
			kasten_mc.addEventListener(MouseEvent.MOUSE_OVER, removeKasten);
			kasten_mc.addEventListener(MouseEvent.MOUSE_OUT, showKasten);
			kasten_mc.addEventListener(MouseEvent.ROLL_OUT,boardOut);
			kasten_mc.addEventListener(MouseEvent.ROLL_OVER,boardOver);
			kasten_mc.addEventListener(MouseEvent.MOUSE_MOVE,boardMove);
		}

		
		function onClick(e:MouseEvent) {
  if(e.target!=stage) return;
  trace("Stage was clicked");
}
		
		function boardOver(e:MouseEvent):void
		{
			this.addChild(disk);
			disk.x = stage.mouseX;
			disk.y = stage.mouseY;
			Mouse.hide();
		}

		function boardOut(e:MouseEvent):void
		{
			if (this.contains(disk))
			{
				this.removeChild(disk);
				Mouse.show();
			}
		}

		function boardMove(e:MouseEvent):void
		{
			disk.x = stage.mouseX;
			disk.y = stage.mouseY;
			e.updateAfterEvent();
		}

		protected function matchHandler(e:GestureEvent):void
		{
			trace("currentContent: "+currentContent);

			if (e.datas == "NEXT" && currentContent != undefined)
			{

				if (indexPattern < myPatterns.length - 1)
				{
					indexPattern++;
				}
				else
				{
					indexPattern = 0;
				}

			}
			else if (e.datas=="NEXT" && currentContent == undefined)
			{
				indexPattern = 0;

			}
			else
			{
				trace("muster bleibt gleich");
				movementPattern = e.datas;
			}
			trace("////////");
			/*trace("e.datas: "+e.datas)
			trace("myPatterns[indexPattern]: "+myPatterns[indexPattern]);
			trace("indexPattern: "+indexPattern)
			trace("movementPattern: "+movementPattern);*/

			loadPattern(myPatterns[indexPattern], movementPattern);


		}


		private function loadPattern(pattern, movementPattern )
		{
			trace("loadPattern");
			trace("patern: "+pattern);
			trace("movementPattern: "+movementPattern);


			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadInit);
			trace("url: "+pattern+"_"+movementPattern+".swf");
			loader.load(new URLRequest([pattern+"_"+movementPattern+".swf"]));
			timer.start();


		}



		private function loadInit(e:Event):void
		{
			e.currentTarget.removeEventListener(Event.COMPLETE,loadInit);

			if (currentContent)
			{
				removeChild(currentContent);
			}

			currentContent = DisplayObject(e.currentTarget.content);
			addChild(currentContent);
		}

		private function removeKasten(e:Event):void
		{
			if (! currentContent)
			{
				var myTween:Tween = new Tween(kasten_mc,"alpha",Strong.easeOut,1,0,1,true);
			}
		}

		private function showKasten(e:Event):void
		{
			if (! currentContent)
			{
				var myTween:Tween = new Tween(kasten_mc,"alpha",Strong.easeOut,0,1,1,true);
			}
		}

		protected function noMatchHandler(e:GestureEvent):void
		{
			draw_mc.zone_mc.graphics.clear();
		}

		protected function startHandler(e:GestureEvent):void
		{
			timer.stop();
			if (fadeTween)
			{
				fadeTween.stop();
			}

			draw_mc.zone_mc.graphics.clear();
			draw_mc.alpha = 1;
			draw_mc.zone_mc.graphics.lineStyle(4,0x444444);
			draw_mc.zone_mc.graphics.moveTo(mouseX,mouseY);
			addEventListener(Event.ENTER_FRAME,capturingHandler);
		}

		protected function fadeDrawing(e:TimerEvent):void
		{
			fadeTween = new Tween(draw_mc,"alpha",Regular.easeIn,draw_mc.alpha,0,10);
		}

		protected function stopHandler(e:GestureEvent):void
		{
			removeEventListener(Event.ENTER_FRAME,capturingHandler);
		}

		protected function capturingHandler(e:Event):void
		{
			draw_mc.zone_mc.graphics.lineTo(mouseX,mouseY);
		}

	}

}
das ist der code, wenn ich jetzt aber bei den objekten überall ein "= new ..."hinzufüge, dann gibts probleme beim compilen
pixon ist offline   Mit Zitat antworten
Alt 11-02-2011, 02:19   #8 (permalink)
Keine Panik
 
Registriert seit: Apr 2010
Ort: Düsseldorf (im ernst)
Beiträge: 1.866
Thumbs up

Zitat:
die flash IDE ist echt blöd. die gibt keine Fehler aus wenn ich GestureNavi compile
weil es da auch keine Probleme gibt. die kommen ja erst, wenn du diese swf in eine andere reinlädst.


Code:
stage.scaleMode = "noScale";
diese Zeile bereitet die Probleme. stage ist im Constructor noch garnicht bekannt.

bau das so um:
PHP-Code:
public function GestureNavi()
{
    if(
stageinit();
    else 
addEventListener(Event.ADDED_TO_STAGEinit);
}

private function 
init(e:Event=null):void
{
    
removeEventListener(Event.ADDED_TO_STAGEinit);
    
//entry Point

    //...

__________________
greetz Thomas

plz RTFM & Coding Conventions

Geändert von thomas_E (11-02-2011 um 02:21 Uhr)
thomas_E ist offline   Mit Zitat antworten
Alt 11-02-2011, 02:40   #9 (permalink)
| ||[ PIXON ] ||
 
Benutzerbild von pixon
 
Registriert seit: Apr 2002
Beiträge: 364
ich habe mal stage.scaleMode = "noScale"; komplett rausgeschmissen und es umgebaut, leider der gleiche fehler
hat es mit dem comment //entry point was bestimmtes auf sich?
pixon ist offline   Mit Zitat antworten
Alt 11-02-2011, 02:50   #10 (permalink)
Keine Panik
 
Registriert seit: Apr 2010
Ort: Düsseldorf (im ernst)
Beiträge: 1.866
nein, nur ein Kommentar.

wie sieht dein constructor jetzt aus
versuch mal paar traces in constructor und init einzubauen, um zu schauen, wie weit er kommt, bevor der Fehler passiert.
vor allen dingen mal vor und nach
Code:
mg = new MouseGesture(stage);
__________________
greetz Thomas

plz RTFM & Coding Conventions
thomas_E ist offline   Mit Zitat antworten
Alt 11-02-2011, 02:51   #11 (permalink)
ING
whatever
 
Registriert seit: May 2008
Beiträge: 419
draw_mc & kasten_mc sind beides wieder null objekte, gleiches problem was ich jetzt schon mehrmals angesprochen habe. ich glaub da hast da einen denkfehler...

ActionScript:
  1. public var draw_mc:MovieClip;
ist eine leere variable vom typ movieclip (also ein null objekt)

ActionScript:
  1. public var draw_mc:MovieClip = new MovieClip();
ist eine variable mit einem movieclip
ING ist offline   Mit Zitat antworten
Alt 11-02-2011, 03:19   #12 (permalink)
| ||[ PIXON ] ||
 
Benutzerbild von pixon
 
Registriert seit: Apr 2002
Beiträge: 364
sorry war etwas älterer code, habe draw_mc & kasten_mc schon berichtigt gehabt. das problem liegt wahrscheinlich in der gesten erkennungs klasse ( import com.foxaweb.ui.gesture.*; ) jetzt kommt auch ein anderer error:

Code:
TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
	at com.foxaweb.ui.gesture::MouseGesture/init()
	at com.foxaweb.ui.gesture::MouseGesture()
	at GestureNavi()
habe mal getraced, der error kommt direkt vor mg = new MouseGesture(stage);

die gesture klassen:
Code:
/**
*
*
*	GestureEvent
*	
*	@notice		Gesture Event
*	@author		Didier Brun
*	@version	1.0
* 	@link		http://www.bytearray.org/?p=91
*
*/

package com.foxaweb.ui.gesture {
	
	import flash.events.Event;

	public class GestureEvent extends Event {
		
		// ------------------------------------------------
		//
		// ---o static
		//
		// ------------------------------------------------
		
		public static const START_CAPTURE:String="startCapture";
		public static const STOP_CAPTURE:String="stopCapture";
		public static const CAPTURING:String="capturing";
		public static const GESTURE_MATCH:String="gestureMatch";
		public static const NO_MATCH:String="noMatch";
		
		// ------------------------------------------------
		//
		// ---o properties
		//
		// ------------------------------------------------
		
		public var datas:*;
		public var fiability:uint;
		
		// ------------------------------------------------
		//
		// ---o constructor
		//
		// ------------------------------------------------
		
		public function GestureEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false){
			super (type,bubbles,cancelable);
		}
		
		// ------------------------------------------------
		//
		// ---o methods
		//
		// ------------------------------------------------
		
		public override function clone():Event{
			return new GestureEvent(type, bubbles, cancelable) as Event;
		}
		
	}
}
Code:
/**
*
*
*	MouseGesture
*	
*	@notice		Mouse Gesture Recognizer
*	@author		Didier Brun
*	@version	1.0
* 	@date		2007-05-17
* 	@link		http://www.bytearray.org/?p=91
* 
* 
*	Original author :
*	-----------------
*	Didier Brun aka Foxy
*	webmaster@foxaweb.com
*	http://www.foxaweb.com
*
* 	AUTHOR ******************************************************************************
* 
*	authorName : 	Didier Brun - www.foxaweb.com
* 	contribution : 	the original class
* 	date :			2007-01-18
* 
* 	VISIT www.byteArray.org
* 
*
*	LICENSE ******************************************************************************
* 
* 	This class is under RECIPROCAL PUBLIC LICENSE.
* 	http://www.opensource.org/licenses/rpl.php
* 
* 	Please, keep this header and the list of all authors
* 
*
*/

package com.foxaweb.ui.gesture {
	
	import com.foxaweb.ui.gesture.*;
	
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Timer;
	
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.events.MouseEvent;
	
	import flash.display.InteractiveObject;
	import flash.display.Stage;

	public class MouseGesture extends EventDispatcher {
		
		// ------------------------------------------------
		//
		// ---o static
		//
		// ------------------------------------------------

		public static const DEFAULT_NB_SECTORS:uint=8;		// Number of sectors
		public static const DEFAULT_TIME_STEP:uint=20;		// Capture interval in ms
		public static const DEFAULT_PRECISION:uint=8;		// Precision of catpure in pixels
		public static const DEFAULT_FIABILITY:uint=30;		// Default fiability level
		
		// ------------------------------------------------
		//
		// ---o properties
		//
		// ------------------------------------------------
		
		private var moves:Array;						// Mouse gestures
		private var lastPoint:Point;					// Last mouse point
		private var mouseZone:InteractiveObject;		// Mouse zone
		private var captureDepth:uint;					// Current capture depth 
		private var gestures:Array;						// Gestures to match
		private var rect:Object;						// Rectangle zone
		private var points:Array;						// Mouse points 
	
		protected var timer:Timer;						// Timer
		protected var sectorRad:Number;					// Angle of one sector		
		protected var anglesMap:Array;					// Angles map 
		
		// ------------------------------------------------
		//
		// ---o constructor
		//
		// ------------------------------------------------

		function MouseGesture(pZone:InteractiveObject){
			
			// parametters
			mouseZone=pZone;
	
			// initialization
			init();
		}
		
		// ------------------------------------------------
		//
		// ---o public methods
		//
		// ------------------------------------------------
		
		/**
		*	Add a gesture
		*/
		public function addGesture(o:*,gesture:String,matchHandler:Function=null):void{
			var g:Array=[];
			for (var i:uint=0;i<gesture.length;i++){
				g.push(gesture.charAt(i)=="." ? -1 : parseInt(gesture.charAt(i),16));				
			}
			gestures.push({datas:o,moves:g,match:matchHandler});	
		}
								   
		
		// ------------------------------------------------
		//
		// ---o private methods
		//
		// ------------------------------------------------
		
		/**
		*	Initialisation
		*/
		protected function init():void{
			
			// Build the angles map
			buildAnglesMap();
			
			// Timer
			timer=new Timer(DEFAULT_TIME_STEP);
			timer.addEventListener(TimerEvent.TIMER,captureHandler,false,0,true);
				
			// Gesture Spots
			gestures=[];
			
			// Mouse Events
			mouseZone.addEventListener(MouseEvent.MOUSE_DOWN,startCapture,false,0,true);
			mouseZone.addEventListener(MouseEvent.MOUSE_UP,stopCapture,false,0,true);
			
		}
		
		/**
		*	Build the angles map
		*/
		protected function buildAnglesMap():void{
			
			// Angle of one sector
			sectorRad=Math.PI*2/DEFAULT_NB_SECTORS;
			
			// map containing sectors no from 0 to PI*2
			anglesMap=[];
			
			// the precision is Math.PI*2/100
			var step:Number=Math.PI*2/100;
						
			// memorize sectors
			var sector:Number;
			for (var i:Number=-sectorRad/2;i<=Math.PI*2-sectorRad/2;i+=step){
				sector=Math.floor((i+sectorRad/2)/sectorRad);
				anglesMap.push(sector);
			}
		}
		
		/**
		*	Time Handler
		*/
		protected function captureHandler(e:TimerEvent):void{
			
			// calcul dif 
			var msx:int=mouseZone.mouseX;
			var msy:int=mouseZone.mouseY;
			
			var difx:int=msx-lastPoint.x;
			var dify:int=msy-lastPoint.y;
			var sqDist:Number=difx*difx+dify*dify;
			var sqPrec:Number=DEFAULT_PRECISION*DEFAULT_PRECISION;
					
			if (sqDist>sqPrec){
				points.push(new Point(msx,msy));
				addMove(difx,dify);
				lastPoint.x=msx;
				lastPoint.y=msy;
				
				if (msx<rect.minx)rect.minx=msx;
				if (msx>rect.maxx)rect.maxx=msx;
				if (msy<rect.miny)rect.miny=msy;
				if (msy>rect.maxy)rect.maxy=msy;
			}
			
			// event
			dispatchEvent (new GestureEvent(GestureEvent.CAPTURING));
			
		}
		
		/**
		*	Add a move 
		*/
		protected function addMove(dx:int,dy:int):void{
			var angle:Number=Math.atan2(dy,dx)+sectorRad/2;
			if (angle<0)angle+=Math.PI*2;
			var no:int=Math.floor(angle/(Math.PI*2)*100);
			moves.push(anglesMap[no]);
		}
		
		/**
		*	Start the capture phase
		*/
		protected function startCapture(e:MouseEvent):void{
			
			// moves
			moves=[];
			points=[];
			rect={	minx:Number.POSITIVE_INFINITY,
					maxx:Number.NEGATIVE_INFINITY,
					miny:Number.POSITIVE_INFINITY,
					maxy:Number.NEGATIVE_INFINITY};
	
			// event
			dispatchEvent(new GestureEvent(GestureEvent.START_CAPTURE))
			
			// last point
			lastPoint=new Point(mouseZone.mouseX,mouseZone.mouseY);
			
			// start the timer
			timer.start();
		}
		
		/**
		*	Stop the capture phase
		*/
		protected function stopCapture(e:MouseEvent):void{
			
			// match 
			matchGesture();
			
			// event
			dispatchEvent(new GestureEvent(GestureEvent.STOP_CAPTURE))
			
			// stop the timer
			timer.stop();
			
		}
		
		/**
		*	Match the gesture
		*/
		protected function matchGesture():void{
			
			var bestCost:uint=1000000;
			var nbGestures:uint=gestures.length;
			var cost:uint;
			var gest:Array;
			var bestGesture:Object=null;
			var infos:Object={	points:points,
								moves:moves,
								lastPoint:lastPoint,
								rect:new Rectangle(	rect.minx,
													rect.miny,
													rect.maxx-rect.minx,
													rect.maxy-rect.miny)};

			for (var i:uint=0;i<nbGestures;i++){
				
				gest=gestures[i].moves;
				
				infos.datas=gestures[i].datas;
				
				cost=costLeven(gest,moves);
				
				if (cost<=DEFAULT_FIABILITY){
					if (gestures[i].match!=null){
						infos.cost=cost;
						cost=gestures[i].match(infos);
					}
					if (cost<bestCost){
						bestCost=cost;
						bestGesture=gestures[i];
					}
				}
			}
			
			
			if (bestGesture!=null){
				var evt:GestureEvent=new GestureEvent(GestureEvent.GESTURE_MATCH);
				evt.datas=bestGesture.datas;
				evt.fiability=bestCost;
				dispatchEvent(evt);
			}else{
				dispatchEvent(new GestureEvent(GestureEvent.NO_MATCH));
			}
		}
				
		/**
		*	dif angle
		*/
		protected function difAngle(a:uint,b:uint):uint{
			var dif:uint=Math.abs(a-b);
			if (dif>DEFAULT_NB_SECTORS/2)dif=DEFAULT_NB_SECTORS-dif;
			return dif;
		}
		
		/**
		*	return a filled 2D table
		*/
		protected function fill2DTable(w:uint,h:uint,f:*):Array{
			var o:Array=new Array(w);
			for (var x:uint=0;x<w;x++){
				o[x]=new Array(h);
				for (var y:uint=0;y<h;y++)o[x][y]=f;
			}
			return o;
		}
		
		/**
		*	cost Levenshtein
		*/
		protected function costLeven(a:Array,b:Array):uint{
			
			// point
			if (a[0]==-1){
				return b.length==0 ? 0 : 100000;
			}
			
			// precalc difangles
			var d:Array=fill2DTable(a.length+1,b.length+1,0);
			var w:Array=d.slice();
			
			for (var x:uint=1;x<=a.length;x++){
				for (var y:uint=1;y<b.length;y++){
					d[x][y]=difAngle(a[x-1],b[y-1]);
				}
			}
			
			// max cost
			for (y=1;y<=b.length;y++)w[0][y]=100000;
			for (x=1;x<=a.length;x++)w[x][0]=100000;
			w[0][0]=0;
			
			// levensthein application
			var cost:uint=0;
			var pa:uint;
			var pb:uint;
			var pc:uint;
			
			for (x=1;x<=a.length;x++){
				for (y=1;y<b.length;y++){
					cost=d[x][y];
					pa=w[x-1][y]+cost;
					pb=w[x][y-1]+cost;
					pc=w[x-1][y-1]+cost;
					w[x][y]=Math.min(Math.min(pa,pb),pc)
				}
			}
			
			return w[x-1][y-1];
		}		
	}
}
pixon ist offline   Mit Zitat antworten
Alt 11-02-2011, 03:54   #13 (permalink)
Keine Panik
 
Registriert seit: Apr 2010
Ort: Düsseldorf (im ernst)
Beiträge: 1.866
Zitat:
habe mal getraced, der error kommt direkt vor mg = new MouseGesture(stage);
nicht davor, genau in der Zeile.

und ich bleibe dabei. ich gehe davon aus, dass an der Stelle wo du das ausführst stage noch nicht bekannt ist, und somit null.

also, wie sieht dein code momentan aus?
__________________
greetz Thomas

plz RTFM & Coding Conventions
thomas_E ist offline   Mit Zitat antworten
Alt 11-02-2011, 08:09   #14 (permalink)
Flash-Designer
 
Benutzerbild von Martin Kraft
 
Registriert seit: May 2006
Ort: Wiesbaden
Beiträge: 6.162
Wenn Du den Code verwendest, denn Thomas Dir oben gepostet hat, und alles, was jetzt im Konstruktor steht, in die Funktion init verschiebst, solltest Du eigentlich kein Problem mehr haben?!
Zitat:
Zitat von thomas_E Beitrag anzeigen
bau das so um:
PHP-Code:
public function GestureNavi()
{
    if(
stageinit();
    else 
addEventListener(Event.ADDED_TO_STAGEinit);
}

private function 
init(e:Event=null):void
{
    
removeEventListener(Event.ADDED_TO_STAGEinit);
    
//entry Point

    //...

__________________
Viele Grüße // Martin

Martin Kraft // Interaktionsdesign

Hilfreiche Websites:
// Hilfe zur Adobe Flash Plattform
// ActionScript 2 Referenz
// ActionScript 3 Referenz
// ActionScript 3 Arbeitshandbuch
// weitere Flash Ressourcen

Bitte keine Flashfragen per PM oder Profilnachricht! Dafür ist das Forum da!
Martin Kraft 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


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
child-child-child-Element ansprechen? (jQuery) soundZ JavaScript & jQuery 3 02-02-2011 10:41
child ansprechen robot2006 ActionScript 3 5 04-05-2009 17:17
[Flash CS3] AS3: Child oder nicht Child.... Capri Flash Einsteiger 3 11-02-2009 16:45
child maskieren... ingrimm ActionScript 3 2 31-10-2008 10:48
second child ? RedSaint Flash mit XML und Webservices 23 03-11-2003 18:57


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:53 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele