I have 4 shapes which fit into 4 boxes and would like to modify my code so when a shape is placed in the correct box a movie clip appears e.g. if a triangle is placed into a triangle shape the movieclip for triangle appears. if the shape is placed into the wrong box a message appears saying try again. can somebody please help me with my flash file.
Need to give your message movie clips instance names ('msgGoodsquare_mc', 'msgBadsquare_mc', msgGoodflower_mc', etc) and under properties, color effect set the alpha to zero and set the display blending to normal.
Code:
var startX:Number;
var startY:Number;
var counter:Number=0;
var objs:Array=[square_mc,triangle_mc,flower_mc,pentagon_mc];
var info:Dictionary = new Dictionary();
var msgs:Dictionary = new Dictionary();
for (var i:* in objs) {
objs[i].addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
objs[i].addEventListener(MouseEvent.MOUSE_UP, dropIt);
info[objs[i]]={t:getChildByName("target"+objs[i].name),sX:objs[i].x,sY:objs[i].y};
msgs[getChildByName("target"+objs[i].name)]={good:getChildByName("msgGood"+objs[i].name),bad:getChildByName("msgBad"+objs[i].name)};
}
function pickUp(event:MouseEvent):void {
event.target.startDrag(true);
reply_txt.text="";
event.target.parent.addChild(event.target);
startX=event.target.x;
startY=event.target.y;
for (var i:* in msgs) {
msgs[i].bad.alpha=0;
}
}
function dropIt(e:MouseEvent):void {
e.target.stopDrag();
if (e.target.dropTarget!=null) {
if (e.target.dropTarget.parent==info[e.target].t) {
msgs[e.target.dropTarget.parent].good.alpha=1;
reply_txt.text="Good Job!";
e.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
e.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
e.target.buttonMode=false;
e.target.x=info[e.target].t.x;
e.target.y=info[e.target].t.y;
counter++;
} else {
if (msgs[e.target.dropTarget.parent]) {
msgs[e.target.dropTarget.parent].bad.alpha=1;
}
reply_txt.text="Missed, Try Again!";
e.target.x=info[e.target].sX;
e.target.y=info[e.target].sY;
}
} else {
reply_txt.text="Try Again!";
e.target.x=info[e.target].sX;
e.target.y=info[e.target].sY;
}
if (counter==4) {
reply_txt.text="Congrats, you're finished!";
}
}
square_mc.buttonMode=true;
flower_mc.buttonMode=true;
triangle_mc.buttonMode=true;
pentagon_mc.buttonMode=true;
That worked perfectly. Thank you.
Is there a way I can make the name of the shape remain under the shape after it has correctly been placed with the shape. So if the triangle is placed into the triangle box the word 'triangle' stays under the shape at al times.
at the end when all are done she should be able to see all the names of the shapes underneath the shapes. not sure how to adjust the code to do this.
Sorry yes, my mistake I am nearly there now. I have made a second and third level so it gets harder with more complex shapes and placed these on frame 2 and 3 of the timeline. If she puts all the shapes into the correct boxes I would like her to go to and stop on frame 2 where there are more shapes and a different board. I duplicated the code from frame 1 into frame 2 and I am getting;
Scene 1, Layer 'Actions', Frame 2, Line 48 1151: A conflict exists with definition i in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 10 1151: A conflict exists with definition msgs in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 9 1151: A conflict exists with definition info in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 8 1151: A conflict exists with definition objs in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 6 1151: A conflict exists with definition filt_shadow in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 5 1151: A conflict exists with definition filt in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 4 1151: A conflict exists with definition counter in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 3 1151: A conflict exists with definition startY in namespace internal.
Scene 1, Layer 'Actions', Frame 2, Line 2 1151: A conflict exists with definition startX in namespace internal.
I have tried to google the answer for this but I really don't know where to start. Is this an easy fix? Thanks
The issue I am having is with the following section of code. The dynamic text box displayed "Missed, Try Again!" perfectly every time but the movie clips displaying the try again error e.g. msgBadsquare_mc, msgBadtriangle_mc, etc, doe not seem to appear consistently when the wrong item is placed within a box.