Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : Drag & Drop Array


pickle jar
2/26/2006 10:55:31 PM
Hi guys,

I got this issue with this test where I am trying to basically drag items onto
a canvas. If the correct items are dragged onto it then obviously you score
correctly.

The trouble started when I considered people may wanna drag items back off the
canvas if they change their mind. So I built and array and had the items added
to array if on canvas, then taken from array if dropped back off the canvas.

Thing is I thought I had cracked it but once the correct items are on the
canvas, it still scores correctly if incorrect items are dragged onto it also,
and if you click a correct piece when it is off the canvas it will score
correctly. Any ideas please????

Cheers Si


stop();

index=0;

// BUILD DEFAULT TITLES ARRAY

titles = [];

titles.push ("a");

titles.push ("b");

titles.push ("c");

titles.push ("d");

titles.push ("e");

titles.push ("f");

titles.push ("g");

titles.push ("h");

//==================

// STOP THINGS ON PAGE 1

content_mc.stop ();

//==================

//build icons from each img on key frames in icon mc

show = [];

_global.nameOf = new Object ();

function buildIconList () {

var spacing:Number = 50;

var iconY:Number = 340;

var iconX:Number = 50;

//Creates a parent movie clip to hold the container

this.createEmptyMovieClip ("mc_1", 0);

//creates a child movie clip inside of "mc_1"

mc_1.attachMovie ("contentmc", "content_mc", 1);

mc_1.content_mc._x = -138;

mc_1.content_mc._y = 860;

mc_1.content_mc.stop ();

mc_1.content_mc._height = 30;

mc_1.content_mc._width = 30;

for (var i = 0; i < mc_1.content_mc._totalframes; ++i) {

var newName:String = "icon_mc" + i;

var clip:MovieClip = mc_1.content_mc.duplicateMovieClip (newName, 10000 + i);

show.push (clip);

clip.gotoAndStop (i + 1);

clip._y = iconY;

clip._x = iconX + i * spacing;

clip.homeX = clip._x;

clip.homeY = clip._y;

clip._alpha = 80;

clip.icon_btn.onPress = function () {

removeImage (this._parent);

startDrag (this._parent);

};

clip.icon_btn.onRollOver = function () {

iconRollOver(this._parent);

this._parent._alpha = 100;

title_txt.text = titles[this._parent._currentframe - 1];

};

clip.icon_btn.onRollOut = function () {

this._parent._alpha = 80;

this._parent._height = 30;

this._parent._width = 30;

};

clip.icon_btn.onRelease = function () {

iconReleased (this._parent);

stopDrag ();

};

}

}

buildIconList ();

//==================

function iconRollOver (icon:MovieClip) {

var newName:String = "object" + iconDepth + "_mc";

var clip:MovieClip = icon.duplicateMovieClip (newName, 1999);

clip.gotoAndStop (icon._currentFrame);

clip.icon_btn.enabled = false;

clip._x = 70;

clip._y = 120;

clip._height = 100;

clip._width = 120;

}

function iconReleased (icon:MovieClip) {

ansSuccess();

if (eval (icon._droptarget) != canvas_mc) {

icon._x = icon.homeX;

icon._y = icon.homeY;

addImage (icon);

}

}

//==================

var tArray:Array = show.slice ();

//function to remove elements of array

function removeImage (clip) {

for (var j = 0; j <= tArray.length; j++) {

if (clip == tArray[j]) {

tArray.splice (j, 1);

break;

}

}

}

function addImage (clip) {

tArray.push (clip);

tArray.sort ();

}

function ansSuccess () {

var tArrayStr:String=tArray.toString();

tArrayStr+=",";

var startIndex=0;

var c=1;

var RArray:Array=new Array();

for(var i=0;i<tArray.length;i++){

trace("startIndex="+startIndex);

index=tArrayStr.indexOf(",", startIndex);

var a=tArrayStr.charAt(index-1);

if(a==2||a==7){

}else{

c=0;

}

startIndex=index+1;

}

if (c) {

_level0.answer = "1";

trace ("q right");

} else {

_level0.answer = "2";

trace ("q wrong");

}



}
SyranideX
2/27/2006 12:00:00 AM
I haven't read through your code, but, the process should be simple, when it is
in, you put in the array (easier would be to have an object perhaps and just
set the respective key to true or false), and when they leave you remove it
again... but don't forget to remove it.

All I can say is debug and see why, perhaps it isn't registering that they
have moved it outside etc.
pickle jar
2/27/2006 12:00:00 AM
Hey thanks, I think I am going to start again on this one and rewrite the
blimen thing, if any one has any suggestions on how to do it I would appreciate
the input if any people can do it simpler. Cheers All
AddThis Social Bookmark Button