AS 2 Line between 2 points
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 35

Thread: Line between 2 points

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    38

    Line between 2 points

    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);

    var x0:Number = _xmouse;
    var y0:Number = _ymouse;


    this.onMouseMove = function()
    {
    mc.clear();
    mc.lineStyle(1);
    mc.moveTo(x0,y0);
    mc.lineTo(_xmouse,_ymouse);

    updateAfterEvent();
    };
    };

    this.onMouseUp = function()
    {
    delete this.onMouseMove;
    };

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Actionscript Code:
    down = false;

    this.onMouseDown = function()
    {

        n = this.getNextHighestDepth();
        mc = this.createEmptyMovieClip("mc" + n, n);
       
        x0 = _xmouse;
        y0 = _ymouse;

    }


    this.onMouseMove = function()
    {
        if(down){
            mc.clear();
            mc.lineStyle(1);
            mc.moveTo(x0,y0);
            mc.lineTo(_xmouse,_ymouse);
           
            updateAfterEvent();
        }
    }

    this.onMouseUp = function()
    {
        x0 = _xmouse;
        y0 = _ymouse;
        down = !down;
    };
    };
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    38
    Standalone thats works a treat. However I tried to add to the attched movie and it only works after i have clicked 4 times....
    Last edited by milanoli; 06-10-2012 at 04:09 PM.

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Please post in CS5 or lower
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Member
    Join Date
    Oct 2011
    Posts
    38
    cheers. here it is.
    Attached Files Attached Files

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    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:

    Actionscript Code:
    down = false;

    this.onMouseMove = function()
    {
        if(down){
            mc.clear();
            mc.lineStyle(1);
            mc.moveTo(x0,y0);
            mc.lineTo(_xmouse,_ymouse);
           
            updateAfterEvent();
        }
    }
     
    onMouseDown = function(){
        if(i < 4){
            attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
            i++;
            if(rump_bt.hitTest(_xmouse, _ymouse, true)){
                rump = 1;
            } else if(crown_bt.hitTest(_xmouse, _ymouse, true)){
                crown = 1;
            } else if(sides_bt.hitTest(_xmouse, _ymouse, true)){
                sides = 1;
            } else if(Yolk_bt.hitTest(_xmouse, _ymouse, true)){
                yolk = 1;
            }
        }
       
        n = this.getNextHighestDepth();
        mc = this.createEmptyMovieClip("mc" + n, n);
       
        x0 = _xmouse;
        y0 = _ymouse;
    }
     
    onMouseUp = function(){
        if((rump == 1) && (yolk== 1)) {
        i = 4;
        submit_bt._visible = true;
        }
        if((rump == 1) && (sides== 1)) {
        i = 4;
        submit_bt._visible = true;
        }
        if((sides == 1) && (crown== 1)) {
        i = 4;
        submit_bt._visible = true;
        }
        if((yolk == 1) && (crown== 1)) {
        i = 4;
        submit_bt._visible = true;
        }
        if((rump == 1) && (crown == 1)) {
     ab_dash._visible = true;
        }
        if((sides == 1) && (yolk == 1)) {
     cd_dash._visible = true;
        }
        if(i == 4 && ended == false){       
            submit_bt._visible = true;
        }
       
        x0 = _xmouse;
        y0 = _ymouse;
        down = !down;
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  7. #7
    Member
    Join Date
    Oct 2011
    Posts
    38
    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.

    AHHHHHH help!!!!!!

  8. #8
    Member
    Join Date
    Oct 2011
    Posts
    38
    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?

    i = 0;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;

    down = false;

    this.onMouseMove = function()
    {
    if(down && i < 4){
    mc.clear();
    mc.lineStyle(5, 0xFFFFFF, 100);
    mc.moveTo(x0,y0);
    mc.lineTo(_xmouse,_ymouse);
    updateAfterEvent();
    }
    };


    onMouseDown = function(){
    if(i < 4){
    attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
    i++;
    if(rump_bt.hitTest(_xmouse, _ymouse, true)){
    rump = 1;
    } else if(crown_bt.hitTest(_xmouse, _ymouse, true)){
    crown = 1;
    } else if(sides_bt.hitTest(_xmouse, _ymouse, true)){
    sides = 1;
    } else if(Yolk_bt.hitTest(_xmouse, _ymouse, true)){
    yolk = 1;
    }
    }

    n = this.getNextHighestDepth();
    mc = this.createEmptyMovieClip("mc" + n, n);

    x0 = _xmouse;
    y0 = _ymouse;
    }



    onMouseUp = function(){
    if(i == 4){
    submit_bt._visible = true;
    }

    x0 = _xmouse;
    y0 = _ymouse;
    down = !down;
    }


    background_bt._visible = false;
    reveal_a._visible = false;
    reveal_b._visible = false;
    reveal_bt._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    submit_bt._visible = false;
    yolk_arrow._visible = false;
    cover_bt._visible = false;
    submit_cover._visible = false;
    cd_dash._visible = false;
    ab_dash._visible = false;


    cover_bt.useHandCursor = false;
    ended = false;

    Yolk_bt._visible = false;
    rump_bt._visible = false;
    crown_bt._visible = false;
    sides_bt._visible = false;

    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;
    } else if((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;
    }
    }


    reveal_bt.onRelease = function () {
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);
    }
    ended = true;
    feedback.htmlText = "";
    ab_dash._visible = true;
    cd_dash._visible = true;
    retry_bt._visible = false;
    cover_bt._visible = true;
    reveal_bt._visible = false;
    submit_bt._visible = false;
    reveal_a._visible = true;
    reveal_b._visible = true;
    yolk_arrow._visible = false;
    };

    retry_bt.onRelease = function (){
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);
    }
    i = 0;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;
    cd_dash._visible = false;
    ab_dash._visible = false;
    ended = false;
    cover_bt._visible = false;
    yolk_arrow._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    feedback.htmlText = "";
    submit_bt._visible = false;
    }

  9. #9
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Change this line:

    Code:
    n = this.getNextHighestDepth();
    to this:

    Actionscript Code:
    n = this.getNextHighestDepth()+4;

    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

  10. #10
    Member
    Join Date
    Oct 2011
    Posts
    38
    Excellent, thank you! Just need the retry button to clear all draw lines now. I thought ‘mc.clear();’ would achieve this but it doesn’t?

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    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;

    down = false;

    this.onMouseMove = function()
    {
    if(down && i < 4){
    mc.clear();
    mc.lineStyle(5, 0xFFFFFF, 100);
    mc.moveTo(x0,y0);
    mc.lineTo(_xmouse,_ymouse);
    updateAfterEvent();
    }
    };


    onMouseDown = function(){
    if(i < 4){
    attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
    i++;
    if(rump_bt.hitTest(_xmouse, _ymouse, true)){
    rump = 1;
    } else if(crown_bt.hitTest(_xmouse, _ymouse, true)){
    crown = 1;
    } else if(sides_bt.hitTest(_xmouse, _ymouse, true)){
    sides = 1;
    } else if(Yolk_bt.hitTest(_xmouse, _ymouse, true)){
    yolk = 1;
    }
    }
     
    mc = this.createEmptyMovieClip("mc" + n, n);
    n++;

    x0 = _xmouse;
    y0 = _ymouse;
    }



    onMouseUp = function(){
    if(i == 4){
    submit_bt._visible = true;
    }

    x0 = _xmouse;
    y0 = _ymouse;
    down = !down;
    }


    background_bt._visible = false;
    reveal_a._visible = false;
    reveal_b._visible = false;
    reveal_bt._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    submit_bt._visible = false;
    yolk_arrow._visible = false;
    cover_bt._visible = false;
    submit_cover._visible = false;
    cd_dash._visible = false;
    ab_dash._visible = false;


    cover_bt.useHandCursor = false;
    ended = false;

    Yolk_bt._visible = false;
    rump_bt._visible = false;
    crown_bt._visible = false;
    sides_bt._visible = false;

    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;
    } else if((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;
    }
    }


    reveal_bt.onRelease = function () {
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);
    }
    ended = true;
    feedback.htmlText = "";
    ab_dash._visible = true;
    cd_dash._visible = true;
    retry_bt._visible = false;
    cover_bt._visible = true;
    reveal_bt._visible = false;
    submit_bt._visible = false;
    reveal_a._visible = true;
    reveal_b._visible = true;
    yolk_arrow._visible = false;
    };

    retry_bt.onRelease = function (){
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);

    }
    for(k=4;k<n+1;k++){
        removeMovieClip(_root["mc"+k]);
    }
    n = 4;

    i = 0;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;
    cd_dash._visible = false;
    ab_dash._visible = false;
    ended = false;
    cover_bt._visible = false;
    yolk_arrow._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    feedback.htmlText = "";
    submit_bt._visible = false;
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  12. #12
    Member
    Join Date
    Oct 2011
    Posts
    38
    Perfect, thank you!

    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.

  13. #13
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Actionscript Code:
    i = 0;
    n = 4;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;

    points = 0;
    correct = false;

    down = false;

    this.onMouseMove = function()
    {
    if(down && i < 4){
    mc.clear();
    mc.lineStyle(5, 0xFFFFFF, 100);
    mc.moveTo(x0,y0);
    mc.lineTo(_xmouse,_ymouse);
    updateAfterEvent();
    }
    };


    onMouseDown = function(){
        if(i < 4){
            attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
            if(rump_bt.hitTest(_xmouse, _ymouse, true)){
                rump = 1;
            } else if(crown_bt.hitTest(_xmouse, _ymouse, true)){
                crown = 1;
            } else if(sides_bt.hitTest(_xmouse, _ymouse, true)){
                sides = 1;
            } else if(Yolk_bt.hitTest(_xmouse, _ymouse, true)){
                yolk = 1;
            }
           
            if(i == 0){
                if(sides == 1){
                    points++;
                }
            } else if(i == 1){
                if(yolk == 1){
                    points++;
                }
            } else if(i == 2){
                if(rump == 1){
                    points++;
                }
            } else if(i == 3){
                if(crown == 1){
                    points++;
                }
            }
            if(points == 4){
                correct = true;
            }
            i++;
        }
     
    mc = this.createEmptyMovieClip("mc" + n, n);
    n++;

    x0 = _xmouse;
    y0 = _ymouse;
    }



    onMouseUp = function(){
    if(i == 4){
    submit_bt._visible = true;
    }

    x0 = _xmouse;
    y0 = _ymouse;
    down = !down;
    }


    background_bt._visible = false;
    reveal_a._visible = false;
    reveal_b._visible = false;
    reveal_bt._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    submit_bt._visible = false;
    yolk_arrow._visible = false;
    cover_bt._visible = false;
    submit_cover._visible = false;
    cd_dash._visible = false;
    ab_dash._visible = false;


    cover_bt.useHandCursor = false;
    ended = false;

    Yolk_bt._visible = false;
    rump_bt._visible = false;
    crown_bt._visible = false;
    sides_bt._visible = false;

    submit_bt.onRelease = function() {
    ended = true;
    if((rump == 1) && (crown == 1) && (yolk == 1) && (sides == 1)) {
        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\nCorrect spots, wrong order.";
            reveal_bt._visible = true;
            retry_bt._visible = true;
            submit_bt._visible = false;
        }
    } else if((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;
    }
    }


    reveal_bt.onRelease = function () {
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);
    }
    ended = true;
    feedback.htmlText = "";
    ab_dash._visible = true;
    cd_dash._visible = true;
    retry_bt._visible = false;
    cover_bt._visible = true;
    reveal_bt._visible = false;
    submit_bt._visible = false;
    reveal_a._visible = true;
    reveal_b._visible = true;
    yolk_arrow._visible = false;
    };

    retry_bt.onRelease = function (){
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);

    }
    for(k=4;k<n+1;k++){
        removeMovieClip(_root["mc"+k]);
    }
    n = 4;
    points = 0;

    i = 0;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;
    cd_dash._visible = false;
    ab_dash._visible = false;
    ended = false;
    cover_bt._visible = false;
    yolk_arrow._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    feedback.htmlText = "";
    submit_bt._visible = false;
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  14. #14
    Member
    Join Date
    Oct 2011
    Posts
    38
    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?

  15. #15
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    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.

    In the onMouseUp function, find this:

    Actionscript Code:
    if(i == 4){
    submit_bt._visible = true;
    }

    Change it to this:

    Actionscript Code:
    if(i == 4){
    submit_bt._visible = true;
       
        diff1X = marker1._x - marker0._x;
        diff1Y = marker1._y - marker0._y;
        diff2X = marker3._x - marker2._x;
        diff2Y = marker3._y - marker2._y;
        diff1 = (Math.atan2(diff1Y, diff1X)*180/Math.PI)+180;
        diff2 = (Math.atan2(diff2Y, diff2X)*180/Math.PI)+180;
        difference = Math.abs(diff1-diff2);
        trace(difference);

    }

    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 01:58 PM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  16. #16
    Member
    Join Date
    Oct 2011
    Posts
    38
    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;
    }
    }

  17. #17
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Code:
    if(difference > 80 || < 100) {
    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

  18. #18
    Member
    Join Date
    Oct 2011
    Posts
    38
    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;

    points = 0;
    correct = false;

    down = false;

    this.onMouseMove = function()
    {
    if(down && i < 4){
    mc.clear();
    mc.lineStyle(2, 0xFFFF00, 100);
    mc.moveTo(x0,y0);
    mc.lineTo(_xmouse,_ymouse);
    updateAfterEvent();
    }
    };


    onMouseDown = function(){
    if(i < 4){
    attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
    if(rump_bt.hitTest(_xmouse, _ymouse, true)){
    rump = 1;
    } else if(crown_bt.hitTest(_xmouse, _ymouse, true)){
    crown = 1;
    } else if(sides_bt.hitTest(_xmouse, _ymouse, true)){
    sides = 1;
    } else if(Yolk_bt.hitTest(_xmouse, _ymouse, true)){
    yolk = 1;
    }

    if(i == 0){
    if(sides == 1){
    points++;
    }
    } else if(i == 1){
    if(yolk == 1){
    points++;
    }
    } else if(i == 2){
    if(rump == 1){
    points++;
    }
    } else if(i == 3){
    if(crown == 1){
    points++;
    }
    }
    if(points == 4){
    correct = true;
    }
    i++;
    }

    mc = this.createEmptyMovieClip("mc" + n, n);
    n++;

    x0 = _xmouse;
    y0 = _ymouse;
    }



    onMouseUp = function(){
    if(i == 4){
    submit_bt._visible = true;
    diff1X = marker1._x - marker0._x;
    diff1Y = marker1._y - marker0._y;
    diff2X = marker3._x - marker2._x;
    diff2Y = marker3._y - marker2._y;
    diff1 = (Math.atan2(diff1Y, diff1X)*180/Math.PI)+180;
    diff2 = (Math.atan2(diff2Y, diff2X)*180/Math.PI)+180;
    difference = Math.abs(diff1-diff2);
    trace(difference);
    degree.text = difference;
    }
    x0 = _xmouse;
    y0 = _ymouse;
    down = !down;
    }


    background_bt._visible = false;
    reveal_a._visible = false;
    reveal_b._visible = false;
    reveal_bt._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    submit_bt._visible = false;
    yolk_arrow._visible = false;
    cover_bt._visible = false;
    submit_cover._visible = false;
    cd_dash._visible = false;
    ab_dash._visible = false;


    cover_bt.useHandCursor = false;
    ended = false;

    Yolk_bt._visible = false;
    rump_bt._visible = false;
    crown_bt._visible = false;
    sides_bt._visible = false;

    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;
    }}


    reveal_bt.onRelease = function () {
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);
    }
    for(k=4;k<n+1;k++){
    removeMovieClip(_root["mc"+k]);
    }
    ended = true;
    feedback.htmlText = "";
    ab_dash._visible = true;
    cd_dash._visible = true;
    retry_bt._visible = false;
    cover_bt._visible = true;
    reveal_bt._visible = false;
    submit_bt._visible = false;
    reveal_a._visible = true;
    reveal_b._visible = true;
    yolk_arrow._visible = false;
    };

    retry_bt.onRelease = function (){
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);

    }
    for(k=4;k<n+1;k++){
    removeMovieClip(_root["mc"+k]);
    }
    n = 4;
    points = 0;
    degree.text = ""
    i = 0;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;
    cd_dash._visible = false;
    ab_dash._visible = false;
    ended = false;
    cover_bt._visible = false;
    yolk_arrow._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    feedback.htmlText = "";
    submit_bt._visible = false;
    }

  19. #19
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    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:

    Actionscript Code:
    if((difference < 85) || (difference > 95) && (correct == true))

    Instead, join the OR statements together:

    Actionscript Code:
    if((difference < 85 || difference > 95) && (correct == true))

    and see if that makes any difference. And please, if you post anymore code, please put it in AS tags (press the button that looks like this; AS )
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  20. #20
    Member
    Join Date
    Oct 2011
    Posts
    38
    OK sorry about that.

    I am now getting errors on line 120, 128 and 137. saying there is 'else' encountered without matching 'if'?

    Actionscript Code:
    i = 0;
    n = 4;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;

    points = 0;
    correct = false;

    down = false;

    this.onMouseMove = function()
    {
    if(down && i < 4){
    mc.clear();
    mc.lineStyle(2, 0xFFFF00, 100);
    mc.moveTo(x0,y0);
    mc.lineTo(_xmouse,_ymouse);
    updateAfterEvent();
    }
    };


    onMouseDown = function(){
    if(i < 4){
    attachMovie("marker_mc", "marker"+i, i, {_x:_xmouse, _y:_ymouse});
    if(rump_bt.hitTest(_xmouse, _ymouse, true)){
    rump = 1;
    } else if(crown_bt.hitTest(_xmouse, _ymouse, true)){
    crown = 1;
    } else if(sides_bt.hitTest(_xmouse, _ymouse, true)){
    sides = 1;
    } else if(Yolk_bt.hitTest(_xmouse, _ymouse, true)){
    yolk = 1;
    }

    if(i == 0){
    if(sides == 1){
    points++;
    }
    } else if(i == 1){
    if(yolk == 1){
    points++;
    }
    } else if(i == 2){
    if(rump == 1){
    points++;
    }
    } else if(i == 3){
    if(crown == 1){
    points++;
    }
    }
    if(points == 4){
    correct = true;
    }
    i++;
    }

    mc = this.createEmptyMovieClip("mc" + n, n);
    n++;

    x0 = _xmouse;
    y0 = _ymouse;
    }



    onMouseUp = function(){
    if(i == 4){
    submit_bt._visible = true;
    diff1X = marker1._x - marker0._x;
    diff1Y = marker1._y - marker0._y;
    diff2X = marker3._x - marker2._x;
    diff2Y = marker3._y - marker2._y;
    diff1 = (Math.atan2(diff1Y, diff1X)*180/Math.PI)+180;
    diff2 = (Math.atan2(diff2Y, diff2X)*180/Math.PI)+180;
    difference = Math.abs(diff1-diff2);
    trace(difference);
    degree.text = difference;
    }
    x0 = _xmouse;
    y0 = _ymouse;
    down = !down;
    }


    background_bt._visible = false;
    reveal_a._visible = false;
    reveal_b._visible = false;
    reveal_bt._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    submit_bt._visible = false;
    yolk_arrow._visible = false;
    cover_bt._visible = false;
    submit_cover._visible = false;
    cd_dash._visible = false;
    ab_dash._visible = false;


    cover_bt.useHandCursor = false;
    ended = false;

    Yolk_bt._visible = false;
    rump_bt._visible = false;
    crown_bt._visible = false;
    sides_bt._visible = false;

    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;
    }
    //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.
    else if ((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;
    }}


    reveal_bt.onRelease = function () {
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);
    }
    for(k=4;k<n+1;k++){
    removeMovieClip(_root["mc"+k]);
    }
    ended = true;
    feedback.htmlText = "";
    ab_dash._visible = true;
    cd_dash._visible = true;
    retry_bt._visible = false;
    cover_bt._visible = true;
    reveal_bt._visible = false;
    submit_bt._visible = false;
    reveal_a._visible = true;
    reveal_b._visible = true;
    yolk_arrow._visible = false;
    };

    retry_bt.onRelease = function (){
    for(a=0;a<i;a++){
    removeMovieClip(_root["marker"+a]);

    }
    for(k=4;k<n+1;k++){
    removeMovieClip(_root["mc"+k]);
    }
    n = 4;
    points = 0;
    degree.text = ""
    i = 0;
    rump = 0;
    crown = 0;
    sides = 0;
    yolk = 0;
    cd_dash._visible = false;
    ab_dash._visible = false;
    ended = false;
    cover_bt._visible = false;
    yolk_arrow._visible = false;
    reveal_bt._visible = false;
    retry_bt._visible = false;
    feedback.htmlText = "";
    submit_bt._visible = false;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com