PDA

View Full Version : And I thought I was soooo smart!!


LostInRecursion
09-20-2004, 04:14 AM
Hi all,

Thanks for all the help so far with this thing I'm building. It's really teaching me a lot and I am thrilled that actionscript.org has such an active forum.

I built a component. It's really just a movie clip symbol with some assets and a class file associated with it. It basically shows seats to a user. When I use the component on its own, everything works as expected.

However, when I create 3 instances of it on the stage, suddenly when I interact with one, the others start behaving oddly!! Can anyone see what I am doing here. I was very careful to use only relative addressing (this) when referring to the component clip in the class file.

Maybe I should look into adding some focus considerations??

class com.dticket.components.StadiumView extends MovieClip{
private var _rsSeats:Object;
private var _rsLength:Number;
private var _sectionclip:MovieClip;
private var _dragflag:MovieClip;
private var _downX:Number;
private var _downY:Number;
private var _upX:Number;
private var _upY:Number;
private var _clicktest:Number;

private var _dragtest:Boolean;

private var nCounter:Number;
private var nBuildInterval:Number;

function StadiumView(){

}

public function set dataProvider(seatRecords:Object):Void {
_rsSeats = seatRecords;
_rsLength = seatRecords.length - 1;
refreshView();
}

private function refreshView():Void {
var classPath = this;
_sectionclip = this.createEmptyMovieClip("mcSection",1);
_sectionclip.setMask(this["mcSectionMask"]);
_sectionclip.moveTo(0,0);
nCounter = 0;
nBuildInterval = setInterval(buildView,5,_rsLength,_rsSeats,classPa th);
}

private function clearView():Void {
}

private function buildView(numRecords:Number,seatData:Object,path): Void {
var iname = "s_"+seatData[path.nCounter].seat_id;//DBNAME
var seat:MovieClip = path._sectionclip.attachMovie("seat",iname,path._sectionclip.getNextHighestDepth());
seat._x = seatData[path.nCounter].seatX;
seat._y = seatData[path.nCounter].seatY;
seat["mcFlag"]._visible = false;//Set FLAG to invisible.*/

seat.onEnterFrame = function(){
var seathit = this.hitTest(path["mcDragFlag"]);
if(seathit){this["mcFlag"]._visible = seathit;}
}

if(path.nCounter == numRecords){
clearInterval(path.nBuildInterval);
}
updateAfterEvent();
path.nCounter++;

}

private function onMouseDown(){
_dragflag = this.createEmptyMovieClip("mcDragFlag", 1000);
_downX = _xmouse;
_downY = _ymouse;
_clicktest = 1;
_dragflag.setMask(this["mcFlagMask"]);
if(_dragtest==true){
_dragtest = false;
}else{
_dragtest = true;
}
}

private function onMouseUp(){
_upX = this._xmouse;
_upY = this._ymouse;
_clicktest = 0;
_dragflag.removeMovieClip();
}

private function onMouseMove(){
var path = this;
trace(_xmouse + " " + path._xmouse);
path._dragflag.clear();
if (path._clicktest == 1) {
with(path._dragflag){
lineStyle(2, 0x00ee00, 100);
beginFill(0x00cc00, 25);
moveTo(path._downX, path._downY);
lineTo(path._downX, _ymouse);
lineTo(_xmouse, _ymouse);
lineTo(_xmouse, path._downY);
endFill();
}
//Check to see if USER has dragged beyond MASK
if(path._xmouse >= path["mcFlagMask"]._width){
path._sectionclip._x = path._sectionclip._x - 2;
}else if(path._xmouse < path["mcFlagMask"]._x){
path._sectionclip._x = path._sectionclip._x + 2;
}
//END CHECK
}
}

public function moveSectionClip(drc:String,path){
switch(drc){
case 'right':
path.mcSection._x = path.mcSection._x - 10;
break;
case 'left':
path.mcSection._x = path.mcSection._x + 10;
break;
case 'up':
path.mcSection._y = path.mcSection._y + 10;
break;
case 'down':
path.mcSection._y = path.mcSection._y - 10;
break;
}
updateAfterEvent();
}


//END CLASS
}

Xeef
09-20-2004, 05:50 AM
"And I thought I was soooo smart!! "
you woud by even more if you give some topic which has at least a litle bit to do whit you problem (ok is the case)

on the first wiew
onMouseDown(){blabla
will hapens so ofthen you have it on screen

mcFlagMask ??? i put 1 on my self ?? shoud i ?

_dragflag.setMask(this["mcFlagMask"]); is inside of the mouse event which is trigered by all instance of component

next time not a COOL topic beter a smart description of problem

dr.swank
09-20-2004, 08:43 AM
public function set dataProvider(seatRecords:Object):Void {
_rsSeats = seatRecords;
_rsLength = seatRecords.length - 1;
refreshView();
}


I think the problem has toi do with missing internal refrences...

the above function needs to refer to its privat properties using the this keyword as well as in:


ublic function set dataProvider(seatRecords:Object):Void {
this._rsSeats = seatRecords;
this._rsLength = seatRecords.length - 1;
this.refreshView();
}



if not then you method call could inadvertenly call all instances of the method.

cheers, doc

LostInRecursion
09-20-2004, 01:21 PM
I was thinking that too. But here is what I came up with. See how it uses its width and _xmouse to make some things happen? Well since the conditions evaluate based on the instance, it makes the instances react.

How can I ensure that the component only reacts when it has focus? I think that may be my key here.

-Kenny

dr.swank
09-20-2004, 03:28 PM
the whole class file is lacking proper path statements. path_mc is not as proper as this.path_mc. as for the _xmouse, I assume you are refering to the root position of the mouse, so use _root._xmouse instead.

cheers, doc

LostInRecursion
09-20-2004, 04:47 PM
I am looking for the _xmouse that is relative to the clip. But when I use globalToLocal, the other instances still respond. I just need to make them not respond when it doesn't have focus I think.

deadbeat
09-20-2004, 05:14 PM
onMouseUp and onMouseDown are events that are broadcast to all objects with corresponding listener methods...

If you switch these for onPress and onRelease, the methods should only trigger for that particular instance...alternately, you could use hitTest to check whether the mouse is over a particular instance when the mouse button is pressed...

HTH,

K.