A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: equality, inequality (confused)...

Hybrid View

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Smile equality, inequality (confused)...

    Good day to all of you experts out there,

    I am quiet new to as3 and I am trying to write my code as efficient as possible and I have a scenario where I am not familiar with all the operators and need advice.

    Here is the scenario:


    Actionscript Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.events.Event;



    //functions
    function animate():void {
        var squareTweenX:Tween = new Tween(square_mc,"x",Elastic.easeOut,square_mc.x,mouseX,1,true);
        var squareTweenY:Tween = new Tween(square_mc,"y",Elastic.easeOut,square_mc.y,mouseY,1,true);
    }

    function anim(evt:Event):void {
        if (   (mouseX > 0) && (mouseX < 550)  ,   (mouseY > 0) && (mouseY < 400)   )
        {
            animate();
            trace("whitin boundary");
        }
        else
        {
            var reset:Tween = new Tween(square_mc,"x",Elastic.easeOut,square_mc.x,256.5,2,true);
        }


    }

    //listeners
    stage_mc.addEventListener(MouseEvent.MOUSE_MOVE, anim);


    Now this piece of code never reaches the else condition. I want it to go to "else" condition as soon as either one of those initial 4 values returns false.

    Which operator would do the job or am I missing something else entirely?

    Thanks in advance to anyone who replies.

    Aeson
    Last edited by aeson; 11-23-2010 at 09:19 AM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The conditional of your if is invalid. It shouldn't even compile.

    You have this:
    Code:
    if ((mouseX > 0) && (mouseX < 550)  ,   (mouseY > 0) && (mouseY < 400)){
    The comma in the middle there is nonsense. comma just separates expressions to evaluate, it does not combine them. You want another &&, the logical AND operator, there.

    Code:
    if ((mouseX > 0) && (mouseX < 550)  &&  (mouseY > 0) && (mouseY < 400)){

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    15
    Quote Originally Posted by 5TonsOfFlax View Post
    The conditional of your if is invalid. It shouldn't even compile.

    You have this:
    Code:
    if ((mouseX > 0) && (mouseX < 550)  ,   (mouseY > 0) && (mouseY < 400)){
    The comma in the middle there is nonsense. comma just separates expressions to evaluate, it does not combine them. You want another &&, the logical AND operator, there.

    Code:
    if ((mouseX > 0) && (mouseX < 550)  &&  (mouseY > 0) && (mouseY < 400)){





    It compiles fine and even works (maybe partially). As I said I am new to as or programming for that matter.

    I had already tried your method and it still doesn't reach "the else" condition. And that's where my problem lies in the first place.
    Last edited by aeson; 11-23-2010 at 11:05 AM.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You misread me. I'm not attacking you.

    If your stage size is 550 by 400, then that would explain why you never get mouse events with coordinates outside that range. You won't get mouse move events when the cursor isn't over the swf.

    You may also want to use the event's stageX and stageY properties rather than mouseX and mouseY because the latter will be evaluated in the coordinate space of whatever timeline instance has that code, which could be different from the stage coordinate space. But if it's the main timeline, then those are probably equivalent.

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    15
    Quote Originally Posted by 5TonsOfFlax View Post
    You misread me. I'm not attacking you.

    If your stage size is 550 by 400, then that would explain why you never get mouse events with coordinates outside that range. You won't get mouse move events when the cursor isn't over the swf.

    You may also want to use the event's stageX and stageY properties rather than mouseX and mouseY because the latter will be evaluated in the coordinate space of whatever timeline instance has that code, which could be different from the stage coordinate space. But if it's the main timeline, then those are probably equivalent.

    Thank you!
    That makes more sense. My stage is indeed 550 by 400. I didn't know flash doesn't register mouse coordinates beyond the stage dimensions.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You probably want to use the Event.MOUSE_LEAVE event which is dispatched by the stage when the mouse leaves the stage area.

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    15
    I haven't done you justice I have to admit.
    You are trying to help (I have removed the silly comment made earlier and apologize).

    Yes you are right the Event.MOUSE_LEAVE would be the solution for part of my problem but its too confusing right now and I guess I need to hit the books hard before bothering someone here about silly basic questions.

    Thanks Mr 5TonsOfFlax infinitely though for your time

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