I am trying to create an activity which will test the user’s ability to identify the correct areas to measure between of 4 separate points. So they click once and that is position 1, they then click again and that is position 2. A line would then be draw dynamically between the two points. The user would then be required to click a 3rd and 4th time with a separate line being drawn between these points. The following code is almost right but it requires the user to click and hold the mouse down rather than click and release:
this.onMouseDown = function()
{
var n:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("mc" + n, n);
Because you can only have one event handler (e.g., onMouseMove, onMouseDown, onMouseUp) per object, and if you just copied and pasted it, then you'd be overriding the current event handlers with the new ones (or vice versa). To solve this, simply add the codes to their respective current event handlers:
Mmmmmm I see what you mean. Few problems with this code now:
1. Hotspot areas that should not be visible at all are visible now
2. The fixed dotted lines that should only be visible once the user has clicked 'Reveal' are visible from the start.
3. The dynamic lines once drawn should not dissapear
4. Once two lines have been drawn (4 points) the submit button should appear and the user should not be able to continue drawing lines.
Ok, I am making slow progress. This now works perfectly after you have clicked the submit and then retry button. Eg the dynamic lines are created and stay visible. Any idea why they dissappear on the first attempt?
because the Plus marks are using the depths 0 through 3, and the first lines created overlap those, making the new Plus signs take over the first created lines, causing them to disappear (replacing them), so instead, you start at a higher depth
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
mc is just a variable which stores the latest created line, so clearing it would be futile. Instead, we give the lines a custom depth range, and remove them according to that and add new ones on those depths, full new code:
Actionscript Code:
i = 0; n = 4; rump = 0; crown = 0; sides = 0; yolk = 0;
submit_bt.onRelease = function(){ ended = true; if((rump == 1)&&(crown == 1)&&(yolk == 1)&&(sides == 1)){ cover_bt._visible = true; feedback.htmlText = "<b>Correct.</b>\n\nYou have correctly placed the two abdominal diameter measurements at right angles to each other."; submit_bt._visible = false; }elseif((rump == 1)||(crown == 1)||(yolk == 1)||(sides == 1)){ feedback.htmlText = "<b>Incorrect.</b>\n\nRemember that the two measurements should be at right angles to each other."; reveal_bt._visible = true; retry_bt._visible = true; submit_bt._visible = false; }else{ feedback.htmlText = "<b>Incorrect.</b>\n\nMake sure to select the two abdominal diameters in the correct order."; reveal_bt._visible = true; retry_bt._visible = true; submit_bt._visible = false; } }
One last thing.....what would be the best way to identify if the clicks have not only be made on the correct hotspots but also in the correct order? eg clicking point A then point B, then point C then point D is fine but if they click point A then C, then D then B? the end result in terms of variables is the same but it would be incorrect.
Hi Nig, that is awesome and exactly what I needed.....i say 'what' as the client has now changed their mind.....nice.
So what they want now is for the user to be able to click 4 points anywhere on the circumference and as long as the 2 lines the 4 points draw are more or less 90 degrees to each other it would be fine. Can this be done?
This one was hard to do, but with a bit of help from Google on how to find the angle between two points, I managed to do it, but not 100% though, as it counts if the first marker's coordinates is greater or less than the second's one.
The angle is in Degrees (not radians), but if you want it in radians, then just remove *180/Math.PI)+180, because Math.atan2 returns the angle of a vector in radians, but using the radians to degrees formula, I converted it, but that returned from 0 to 180 and -180 to 0, not from 0 to 360, which is why I've included +180, you may remove that as well if you wish to preserve the calculation in radians. See the image below for how the degrees work in the calculation above:
Hope it works though, I can't do anything further, sorry.
Last edited by Nig 13; 06-25-2012 at 12:58 PM.
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Thanks once again. Just to make sure i have got my head around this correctly; I now need to check the variable 'difference' is between say 80 and 100 (to give a bit of room for error) on submit?
Something like:
submit_bt.onRelease = function() {
ended = true;
if(difference > 80 || < 100) {
if(correct == true){
cover_bt._visible = true;
feedback.htmlText = "<b>Correct.</b>\n\nYou have correctly placed the two abdominal diameter measurements at right angles to each other.";
submit_bt._visible = false;
} else {
feedback.htmlText = "<b>Incorrect.</b>\n\nMake sure to select the two abdominal diameters in the correct order.";
reveal_bt._visible = true;
retry_bt._visible = true;
submit_bt._visible = false;
}
}
that is incorerct, as after the || sign, a new condition starts, meaning that it has no connection to the previous one. In other words, you need to specify the full condition again. Also, when you want to check if it's between 2 values, you use && (AND):
Actionscript Code:
if(difference >80&& difference <100){
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Thanks again. So close now.....just 2 issues left.
1. Is is possible to make the dynamic lines dotted?
2. All feedback appears at the correct time apart from when you get evrything wrong. eg the angle between the lines is incorrect as is the placement of the start and end points of the lines. I have ref the code below:
i = 0;
n = 4;
rump = 0;
crown = 0;
sides = 0;
yolk = 0;
submit_bt.onRelease = function() {
ended = true;
if((difference > 85) && (difference < 95) && (correct == true))
//The angle between the two lines is between 85 degrees and 95 degress and therefore correct and the 4 points are all correctly placed.
{
cover_bt._visible = true;
feedback.htmlText = "<b>Correct.</b>\n\nYou have correctly placed the two abdominal diameter measurements at the abdominal circumference and at right angles to each other.";
submit_bt._visible = false;
} else if((difference < 85) || (difference > 95) && (correct == true))
//The angle between the two lines is either less than 85 degrees or greater than 95 degress but the 4 points are all correctly placed.
{
feedback.htmlText = "<b>Incorrect.</b>\n\nRemember that the two measurements should be at right angles to each other.";
reveal_bt._visible = true;
retry_bt._visible = true;
submit_bt._visible = false;
}
else if((difference > 85) && (difference < 95) && (correct == false))
//The angle between the two lines is between 85 degrees and 95 degress and therefore correct but one/all of 4 points are incorrectly placed.
{
feedback.htmlText = "<b>Incorrect.</b>\n\nEach of the two measurements should touch the circumference of the abdomen.";
reveal_bt._visible = true;
retry_bt._visible = true;
submit_bt._visible = false;
}
else if((difference < 85) || (difference > 95) && (correct == false))
//The angle between the two lines is either less than 85 degrees or greater than 95 degress and one/all of 4 points are incorrectly placed.
{
feedback.htmlText = "<b>Incorrect.</b>\n\nRemember that the two measurements should be at right angles to each other and each of the two measurements should touch the circumference of the abdomen.";
reveal_bt._visible = true;
retry_bt._visible = true;
submit_bt._visible = false;
}}
1. Nope, not possible to make dotted lines (only in AS3), unless, of course if we drew many lines, but that'd require a lot of coding and also re-write the current coding, so let's just leave it as it is right now.
2. It's working perfectly here. For the 2 codes that are like this:
submit_bt.onRelease = function(){ ended = true; if((difference >85)&&(difference <95)&&(correct == true)) //The angle between the two lines is between 85 degrees and 95 degress and therefore correct and the 4 points are all correctly placed. { cover_bt._visible = true; feedback.htmlText = "<b>Correct.</b>\n\nYou have correctly placed the two abdominal diameter measurements at the abdominal circumference and at right angles to each other."; submit_bt._visible = false; } elseif((difference <85|| difference >95)&&(correct == true)) //The angle between the two lines is either less than 85 degrees or greater than 95 degress but the 4 points are all correctly placed. { feedback.htmlText = "<b>Incorrect.</b>\n\nRemember that the two measurements should be at right angles to each other."; reveal_bt._visible = true; retry_bt._visible = true; submit_bt._visible = false; } elseif((difference >85)&&(difference <95)&&(correct == false)) //The angle between the two lines is between 85 degrees and 95 degress and therefore correct but one/all of 4 points are incorrectly placed. { feedback.htmlText = "<b>Incorrect.</b>\n\nEach of the two measurements should touch the circumference of the abdomen."; reveal_bt._visible = true; retry_bt._visible = true; submit_bt._visible = false; } //The angle between the two lines is either less than 85 degrees or greater than 95 degress and one/all of 4 points are incorrectly placed. elseif((difference <85|| difference >95)&&(correct == false)) { feedback.htmlText = "<b>Incorrect.</b>\n\nRemember that the two measurements should be at right angles to each other and each of the two measurements should touch the circumference of the abdomen."; reveal_bt._visible = true; retry_bt._visible = true; submit_bt._visible = false; }}