我需要一些帮助。我花了两周的时间尝试在cs4 actionscript 3.0中进行拖放游戏,我即将放弃。到目前为止我得到了帮助,但我得到的最好的建议是尝试从头开始而不是反编译其他人的工作。所以在这里 我有一个看起来像这样的数组
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
我需要三个目标, 并且能够在屏幕上放置项目名称(这只是它的一小部分),如果它被放置在目标上,与该项目放在列中的应答号码相匹配,并且下一项我的数组出现。如果不是,则返回其起始位置。这看起来应该很容易,但我不是一名计算机老师我是一名科学老师,正在努力为学生提供一些东西。我有cs4的基本编码技能。
这是我已经得到但无法弄清楚如何获取拖放部分以检查它是否在正确的位置。如果答案是正确的,那就去创建一个新的可拖动的。 我创建了一个名为"答案1",
的答案目标var objectoriginalX:Number;
var objectoriginalY:Number;
Atom.buttonMode = true;
Atom.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Atom.addEventListener(MouseEvent.MOUSE_UP, dropObject);
Matter.buttonMode = true;
Matter.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Matter.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void {
event.target.startDrag();
event.target.parent.addChild(event.target);
}
var dropCount:int = 0;
var dbCount:int=0;
var dbutton0;
function dropObject (event:MouseEvent):void
{
{
event.target.stopDrag();
var targetName = Answer1;
trace (targetName);
var matchingTarget:DisplayObject = getChildByName(targetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == answerdest[1])
{
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
alpha = .8
dropCount ++;
event.target.x = 10
event.target.y = (Number(dropCount) * 100);
trace ("hit");
trace (dropCount);
} else
{
event.target.x = 100;
event.target.y = 111;
trace ("miss");
}
}
}
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];
var myText:TextField = new TextField();
Atom.addChild(myText);
myText.text = answername[1] ;
感谢您的帮助。我不知道我是否在正确的轨道上做我需要做的事情。
答案 0 :(得分:1)
部分回答
b[2]
这非常混乱。我将展示一种更好的方式。即使我的方法在这里也不是最好的,但它与你正在做的事情相似,不难采用。
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];
我知道这不能直接帮助解决您的问题,但让我们清理您的代码,最终我们会弄清楚。我只是在评论中无法解释这一点。
var answer:Array = [
{_name:"gravel",dest:"1"},
{_name:"Nuts and bolts",dest:"Answer1"},
{_name:"water",dest:"2"},
{_name:"gold",dest:"3"},
{_name:"Iron",dest:"4"}
];
text3 // what is this supposed to do? I didn't get rid of it. But just a string sitting in the middle of your code should be throwing an error. I'd get rid of it.
//text3.text = answername[1]; // now we have a better way!
text3.text = answer[1]._name;