| |||||||
Du magst keine Werbung? Wir auch nicht!
Einfach registrieren und die Werbung ist weg. Diese Nachricht sehen nur nicht registrierte Nutzer.
![]() |
| | LinkBack | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| | ||[ 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();
}
}
} |
| | |
| | #2 (permalink) |
| whatever Registriert seit: May 2008
Beiträge: 419
|
da hilft dir eine weitere variable weiter... ActionScript:
ActionScript:
ActionScript:
ps: das "var tIn:Tween =" und "var tOut:Tween =" kannst du auch weglassen, ist überflüßig |
| | |
| | #3 (permalink) |
| | ||[ 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? |
| | |
| | #4 (permalink) |
| whatever Registriert seit: May 2008
Beiträge: 419
|
dafür gibt das loader objekt... ActionScript:
ActionScript:
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. |
| | |
| | #5 (permalink) |
| | ||[ 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() |
| | |
| | #6 (permalink) |
| 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. |
| | |
| | #7 (permalink) |
| | ||[ 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);
}
}
} |
| | |
| | #8 (permalink) | |
| Keine Panik Registriert seit: Apr 2010 Ort: Düsseldorf (im ernst)
Beiträge: 1.866
| Zitat:
Code: stage.scaleMode = "noScale"; bau das so um: PHP-Code: Geändert von thomas_E (11-02-2011 um 02:21 Uhr) | |
| | |
| | #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); |
| | |
| | #11 (permalink) |
| 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:
ActionScript:
|
| | |
| | #12 (permalink) |
| | ||[ 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() 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];
}
}
} |
| | |
| | #13 (permalink) | |
| Keine Panik Registriert seit: Apr 2010 Ort: Düsseldorf (im ernst)
Beiträge: 1.866
| Zitat:
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? | |
| | |
| | #14 (permalink) |
| Flash-Designer 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?!
__________________ 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! |
| | |
![]() |
| Lesezeichen |
| Themen-Optionen | |
| Ansicht | |
| |
Ä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 |