MOUSE_UP MOUSE_DOWN

OK, so im trying to get an image to change its source on the mouse, click on to the bottom, and then change to his original on the release.

<>cript >

public var CS: Sound = new Sound (new URLRequest ('CS.mp3'));

protected function btnBlack1_clickHandler(event:MouseEvent):void
{
btnBlack1.addEventListener (MouseEvent.MOUSE_DOWN, btnBlack1_clickHandler)
{
btnBlack1.source = "blackKey_pressed.png".
CS.play ();

}
btnBlack1.addEventListener (MouseEvent.MOUSE_UP, btnBlack1_clickHandler)
{
btnBlack1.source = "blackKey.png".
}

}

]]>

cript >


Click = "btnBlack1_clickHandler (Event)" / > "

So all that happens is when I press on toward the bottom: nothing

When I release the button: it flashes the image of the invisible

on the mouse up and down: he plays the sound that it should do so only on the mouse down

It's just executing all code in the original handler.  If you want to make an event to the mouse down and the other to the mouse upward, they must be separated.


protected function MouseDown(event:MouseEvent):void
{
  btnBlack1.addEventListener(MouseEvent.MOUSE_UP, MouseUp );
  btnBlack1.source = "blackKey_pressed.png"
  CS.play();
}        

protected function MouseUp( event : MouseEvent )
{
  btnBlack1.removeEventListener(MouseEvent.MOUSE_UP, MouseUp );
  btnBlack1.source = "blackKey.png"
}

Tags: BlackBerry Developers

Similar Questions

  • Deliver the mouse_down mouse_up actions

    Hello

    I placed this code in the actionscript code so I could drag the mucles and place them in their objectives. My problem is that once the mouse is down on the 'temporal' muscle, the temporal muscle rises but does not drop when the mouse is in place. I put functions to drop it and pick up when the mouse is down and when the mouse is in place. Also I created this choice proved so the temporal muscle is taken from the Middle, but it is not picking up the middle. I don't see anything wrong with my code can someone help please? Here is the Code:

    1 temporalis_mc.addEventListener (MouseEvent.MOUSE_DOWN, Pick-up);
    2 temporalis_mc.addEventListener (MouseEvent.MOUSE_UP, dropIt);

    3

    4 function pickUp(event:MouseEvent):void {}
    5 event.target.startDrag (true);
    6     }
    7 function dropIt(event:MouseEvent):void {}
    8 event.target.stopDrag ();
    9     }

    10

    11 temporalis_mc.buttonMode = true;

    Thank you

    A student.

    use:

    1 temporalis_mc.addEventListener (MouseEvent.MOUSE_DOWN, Pick-up);
    2

    3

    4 function pickUp(event:MouseEvent):void {}


    5 event.target.startDrag (true);

    stage.addEventListener (MouseEvent.MOUSE_UP, dropIt);

    6     }
    7 function dropIt(event:MouseEvent):void {}
    8 stopDrag();

    stage.removeEventListener (MouseEvent.MOUSE_UP, dropIt);

    9     }

    10

    11 temporalis_mc.buttonMode = true;

  • After a MOUSE_DOWN MouseEvent.MOUSE_OVER

    I know that the Playbook will not normally support MOUSE_OVER in the way that it is generally used on a desktop (e.g. because there is no cursor).  But no one knows if the Playbook will meet MOUSE_OVER while the user touch screen (i.e. after a MOUSE_DOWN and before a MOUSE_UP)?

    My goal is to create a color picker.  I want the user to be able to slide his finger on the squares of color and generate a response (MOUSE_OVER), as they do.

    The Simulator is of no assistance, answering my question because it meets MOUSE_OVER before even I MOUSE_DOWN because he has a slider.

    Thank you!

    I don't know that it is obvious that you could catch MOUSE_MOVE for this?  Or, in a Manager ENTER_FRAME, just monitor the position of the mouse when it is within the region of interest?

    A week ago I found this article on content in Flash Player, mouse events and touch, which can be applied directly to it.  Indeed, it is said that you should probably see MOUSE_OVER as you want.

  • Continuous values @MOUSE_DOWN!

    Hi friends,

    I'm trying to move the object (video Clip) @ the blouse of the event,

    So I'll try to increase the X position of movieclip to button 10 pixels every time is pressed,

    that I'm able to do

    but I want this movie clip countiniously move 10 pixels while the button is pressed.

    I was able to do when @ keypress for any key event,

    but able nob of doi it @ Press Conference of the mouse over the button.

    my code is like this

    myBtnl.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandlerleft);


    function mouseDownHandlerleft(event:MouseEvent):void {}

    {}

    cube.x = cube.x - 10;

    } while(event.buttonDown==true);

    }

    I've tried to do... While loop for continuous valuse, but do not get it...

    thnks in advance!

    Here's a way to approach a solution...

    myBtnl.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandlerleft);
    myBtnl.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandlerleft);

    function mouseDownHandlerleft(event:MouseEvent):void {}
    cube.addEventListener (Event.ENTER_FRAME, handlerleft);
    }

    function handlerleft(event:Event):void {}
    Cube.x = cube.x - 10;
    }

    function mouseUpHandlerleft(event:MouseEvent):void {}
    cube.removeEventListener (Event.ENTER_FRAME, handlerleft);
    }

  • addEventListener (MouseEvent.MOUSE_DOWN, myFunction)

    Hello

    I drag and drop game.i create dynamic video clips.

    This is the code:

    recipesArray is ["Steak", 'Chicken Neeaps', 'Bread', 'Beans', 'Jam'];.

    Create some Movieclips & & set their text
    var mcArray:Array = new Array();
    for (var i: int = 0; i < recipesArray.length; i ++) {}
    var mc:MovieClip = new MovieClip();
    MC. Name = "mc" + i;

    mc.graphics.beginFill (0xFFE1C4);
    mc.graphics.drawRect (0, 0, 150, 25);
    mc.graphics.endFill ();
    MC.x = recipeBox_mc.x + 25;
    MC.y = recipeBox_mc.y + 20 + (50 * i);

    var t:TextField = new TextField();
    t.Text = recipesArray [i];

    var tf:TextFormat = new TextFormat();
    TF. Color = 0x000000;
    TF. Size = 10;
    TF.font = 'Arial ';

    t.setTextFormat (tf);
    mc.addChildAt (t, 0);

    addChild (mc);
    mcArray [i] = mc;

    stage.addChild (mc);
    mcArray [i] .alpha is. 5;
    mcArray [i] .mouseChildren = false;
    mcArray [i] .buttonMode = true;
    mcArray [i] .addEventListener (MouseEvent.MOUSE_DOWN, createInstant);


    now, I want to know which video clip is clicked. HOW?

    Thanks in advance

    :

    VARs.
    var startX:Number;
    var startY: number;
    var recipesArray:Array = new Array();
    Work.
    createInitialMovieClips();

    Functions.

    function createInitialMovieClips() {}
    later, the DB will fill text fields
    recipesArray is ["Steak", 'Chicken Neeaps', 'Bread', 'Beans', 'Jam'];.

    Create some Movieclips & set their text
    var mcArray:Array = new Array();
    for (var i: int = 0; i
    var mc:MovieClip = new MovieClip();
    MC. Name = "mc" + i;

    mc.graphics.beginFill (0xFFE1C4);
    mc.graphics.drawRect (0, 0, 150, 25);
    mc.graphics.endFill ();
    MC.x = recipeBox_mc.x + 25;
    MC.y = recipeBox_mc.y + 20 + (50 * i);

    var t:TextField = new TextField();

    t.Name = "t";
    t.Text = recipesArray [i];

    var tf:TextFormat = new TextFormat();
    TF. Color = 0x000000;
    TF. Size = 10;
    TF.font = 'Arial ';

    t.setTextFormat (tf);
    mc.addChildAt (t, 0);

    addChild (mc);
    mcArray [i] = mc;

    stage.addChild (mc);
    mcArray [i] .alpha is. 5;
    mcArray [i] .mouseChildren = false;
    mcArray [i] .buttonMode = true;
    mcArray [i] .addEventListener (MouseEvent.MOUSE_DOWN, createInstant);
    }
    }

    function createInstant(event:MouseEvent):void {}
    var mc:MovieClip = new MovieClip();
    mc.graphics.beginFill (0xFFE1C4);
    mc.graphics.drawRect (0, 0, 150, 25);
    mc.graphics.endFill ();
    MC.x = mouseX;


    MC.y = mouseY;

    var t:TextField = new TextField();

    t.Text = TextField (MovieClip (event.currentTarget) .getChildByName ("t")) .text;

    var tf:TextFormat = new TextFormat();
    TF. Color = 0x000000;
    TF. Size = 10;

    TF.font = 'Arial ';

    t.setTextFormat (tf);
    mc.addChildAt (t, 0);

    addChild (mc);
    stage.addChild (mc);
    MC.alpha =. 5;
    mc.mouseChildren = false;
    mc.buttonMode = true;

    mc.addEventListener (MouseEvent.MOUSE_DOWN, Pick-up);
    mc.addEventListener (MouseEvent.MOUSE_UP, dropIt);
    mc.addEventListener (Event.ENTER_FRAME, moveInstant);

    }
    function moveInstant(event:Event):void {}
    Event.Target.x = mouseX;
    Event.Target.y = mouseY;

    }
    function pickUp(event:MouseEvent):void {}
    event.target.removeEventListener (Event.ENTER_FRAME, moveInstant);
    event.target.startDrag (true);
    event.target.parent.addChild (event.target);
    startX = event.target.x;
    startY = event.target.y;
    }

    function dropIt(event:MouseEvent):void {}

    event.target.removeEventListener (Event.ENTER_FRAME, moveInstant);
    event.target.stopDrag ();

    }

  • MouseEvent.Mouse_Down problem

    Hi Eo,

    I need to create a MC that I can drag on the screen as you click the left mouse button. Then when I do this:

    import flash.events.MouseEvent;

    function handlerMM(e:MouseEvent) {}
    Punt.y = e.stageY;
    trace (e.stageY);
    }

    function handlerMU(e:MouseEvent) {}
    punt.removeEventListener (MouseEvent.MOUSE_MOVE, handlerMM);
    }

    function handlerMD(e:MouseEvent) {}
    punt.addEventListener (MouseEvent.MOUSE_MOVE, handlerMM);
    punt.addEventListener (MouseEvent.MOUSE_UP, handlerMU)
    trace ("OK");
    }
    punt.addEventListener (MouseEvent.MOUSE_DOWN, handlerMD);

    It does not work. If I click once, and then the MC maintains the movement mouse next, even if the click is completed...

    You can look at what I mean here:

    http://www.syndesign.EU/Flash/sito/sito.swf

    your

    Punt.y = e.stageY;

    originally probably is a problem.

    Use startDrag() If you want to drag the boat.

  • Dynamically display the contents of xml based on the method addEventListener (MouseEvent.MOUSE_DOWN, displayContent);

    Hello

    I have been working for a few days now with this script and got up to a point almost finished, but I can't go to the final stage of script. I have an xml file that is being scanned in my .fla file. There are 3 buttons that are created dynamically based on a tag called < navItem >. "DisplayContent" function should display the appropriate block of xml in various text boxes, but instead, it does show that the last song (the 3rd song) no matter which button I click on. I pasted my code on pastebin here:

    http://pastebin.com/mb3e3cd9

    If someone could take a look at my code, especially the last function, "displayContent" and suggest what I could do to fix the code, or point out where I did wrong, I would be very grateful.

    ~ Chipley

    IF you use the movieclip buttons:

    1. myText.condenseWhite = true;
    2. var paragraphText = xml.mpu.bodyText.page.p;
    3. myText.htmlText = paragraphText;
    4.               
    5. trace (MyText.Text);
    6. for (var i = 0; i)
    7. {
    8. trace ("xml.mpu.bodyText.page.navItem.length =" + i);
    9. var mcMenuItem:mcMenu = new mcMenu();
    10. mcMenuItem.x = button_mc.x;
    11. mcMenuItem.y = button_mc.y + i * 50;
    12. addChild (mcMenuItem);
    13. mcMenuItem.btnTxt.htmlText = navItemText [i];
    14. mcMenuItem.ivar = i;
    15. mcMenuItem.buttonMode = true;
    16. mcMenuItem.addEventListener (MouseEvent.MOUSE_DOWN, displayContent);
    17. }
    18. }
    19. }
    20. function displayContent(event:MouseEvent):void {}
    21. for (var i = 0; i)
    22. {
    23.                         titleText var = xml.mpu.bodyText.page.h1 [event.currentTarget.ivar];
    24. myTitle.htmlText = Text;
                            var paragraphText = xml.mpu.bodyText.page.p [event.currentTarget.ivar];
    1. myText.htmlText = paragraphText;
    2. }
    3. }
  • Load an image rather than another click on... ??

    I am trying to load an image on another click on... (to give the effect of the click of..) Anyone has an idea... Thanks in advance...

    If you want a simple solution, just two superimposed images

    example: 'Volume On' preceding 'Volume Off '.

    Event listener MouseEvent.CLICK on 'Volume On' - button (or MouseEvent.MOUSE_DOWN, according to your needs)

    and then something like

    private var clicked: Boolean

    function eventHandler(e:Event):void {}

    clicked =! clicked

    VolumeOn.alpha = clicked? 0.0: 1.0;

    }

    -----------------------------------------------------

    If you don't want to do this, add a listener for MouseEvent.MOUSE_DOWN, in which the image of the button is defined, and another auditor for MouseEvent.MOUSE_UP, when you set the image to the original

  • Problems of implementation of Swipe_Down

    Hi all

    I build an App with a screen hit in FB4.6 as a Flex Mobile application.  Main application file is stock.mxml, as shown here:

    
    http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   xmlns:utils="utils.*"
                   splashScreenImage="@Embed('assets/images/stock_splash.png')">
    
        
    
        
            
    
        
    
        
            
            
            
    
        
    
            
                
                    
                
            
    
            
            
                
                    
            
            
        
    
        
    
    

    I hang on, the menu is displayed on the right side of the screen in Portrait Mode.  The menu is run by a .as file in the utils directory.  This is called in stock.mxml at the bottom of the above code

    It's the .as file called:

    package utils {
        import caurina.transitions.Tweener;
    
        import flash.display.Shape;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.geom.Point;
    
        import qnx.events.QNXApplicationEvent;
        import qnx.system.QNXApplication;
        import qnx.ui.text.Label;
    
        public class TopSwipeMenu extends Sprite {
            // minimize distance to swipe before menu slides open by itself
            public var swipe_region:int = 21;
    
            // duration in seconds for full slide (e.g. when closing)
            public var slide_time:Number = 0.3;
    
            public function TopSwipeMenu(width:int, height:int, bgcolor:int=0xcccccc) {
                var bg:Shape = new Shape();
                bg.graphics.beginFill(bgcolor, 1);
                bg.graphics.drawRect(0, 0, width, height);
                addChild(bg);
    
                this.y = -height;
    
                QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_START, onEvent);
            }
    
            private var state:int;
            private const ST_IDLE:int = 0;
            private const ST_SWIPE_START:int = 1;
            private const ST_FIRST_DOWN:int = 2;
            private const ST_SWIPING:int = 3;
            private const ST_OPENING:int = 4;
            private const ST_OPEN:int = 5;
            private const ST_CLOSING:int = 6;
    
            private var swipe_start_pos:Point;
    
            private function onEvent(event:Event):void {
                var prev_state:int = state;
                var p:Point = new Point(stage.mouseX, stage.mouseY);
                trace(state, event.type, "@", p);
    
                switch (state) {
                    case ST_IDLE:
                        if (event.type == QNXApplicationEvent.SWIPE_START)
                            state = ST_SWIPE_START;
                        break;
    
                    case ST_SWIPE_START:
                        if (event.type == MouseEvent.MOUSE_MOVE) {
                            swipe_start_pos = new Point(stage.mouseX, stage.mouseY);
                            state = ST_FIRST_DOWN;
                        }
                        // anything but mouseMove
                        else
                            state = ST_IDLE;
                        break;
    
                    case ST_FIRST_DOWN:
                        if (event.type == MouseEvent.MOUSE_DOWN) {
                            // check whether pos is same as it was for first move
                            var pos:Point = new Point(stage.mouseX, stage.mouseY);
                            if (pos.equals(swipe_start_pos))
                                state = ST_SWIPING;
                            else // not a top-swipe if positions don't match
                                state = ST_IDLE;
                        }
                        else if (event.type == QNXApplicationEvent.SWIPE_START)
                            state = ST_SWIPE_START;
                        else
                            state = ST_IDLE;
                        break;
    
                    case ST_SWIPING:
                        if (event.type == MouseEvent.MOUSE_UP) {
                            if (stage.mouseY > swipe_region)
                                state = ST_OPENING;
                            else
                                state = ST_CLOSING;
                        }
                        break;
    
                    case ST_OPENING:
                        if (event.type == Event.COMPLETE)
                            state = ST_OPEN;
                        else if (event.type == Event.CLOSE)
                            state = ST_CLOSING;
                        break;
    
                    case ST_OPEN:
                        if (event.type == Event.CLOSE)
                            state = ST_CLOSING;
                        else if (event.type == QNXApplicationEvent.SWIPE_START)
                            state = ST_SWIPE_START;
                        break;
    
                    case ST_CLOSING:
                        if (event.type == Event.COMPLETE)
                            state = ST_IDLE;
                        else if (event.type == QNXApplicationEvent.SWIPE_START)
                            state = ST_SWIPE_START;
                        break;
                }
    
                // handle state change
                if (state != prev_state) {
                    trace(prev_state, "-->", state);
                    var duration:Number;
                    var slide_closed:Boolean;
    
                    // leaving state
                    switch (prev_state) {
                        case ST_FIRST_DOWN:
                            stage.removeEventListener(MouseEvent.MOUSE_MOVE, onEvent);
                            stage.removeEventListener(MouseEvent.MOUSE_DOWN, onEvent);
                            break;
    
                        case ST_SWIPING:
                            stage.removeEventListener(MouseEvent.MOUSE_UP, onEvent);
                            stage.removeEventListener(Event.ENTER_FRAME, onSwiping);
                            break;
    
                        case ST_OPEN:
                            stage.removeEventListener(MouseEvent.MOUSE_DOWN, outsideClick, true);
                            slide_closed = true;
                            break;
                    }
    
                    // entering state
                    switch (state) {
                        case ST_SWIPE_START:
                            stage.addEventListener(MouseEvent.MOUSE_MOVE, onEvent);
                            break;
    
                        case ST_FIRST_DOWN:
                            stage.addEventListener(MouseEvent.MOUSE_DOWN, onEvent);
                            break;
    
                        case ST_SWIPING:
                            stage.addEventListener(MouseEvent.MOUSE_UP, onEvent);
                            stage.addEventListener(Event.ENTER_FRAME, onSwiping);
                            break;
    
                        case ST_OPENING:
                            stage.addEventListener(MouseEvent.MOUSE_DOWN, outsideClick, true);
                            duration = slide_time * -this.y / height;
                            Tweener.addTween(this, {y: 0, time: duration, transition: "linear",
                                onComplete: onEvent,
                                onCompleteParams: [new Event(Event.COMPLETE)]
                                });
                            break;
    
                        case ST_CLOSING:
                            stage.removeEventListener(MouseEvent.MOUSE_DOWN, outsideClick, true);
                            slide_closed = true;
                            break;
                    }
    
                    if (slide_closed) {
                        duration = slide_time * (height + this.y) / height;
                        Tweener.addTween(this, {y: -height, time: duration, transition: "linear",
                            onComplete: onEvent,
                            onCompleteParams: [new Event(Event.COMPLETE)]
                            });
                    }
                }
            }
    
            private function onSwiping(e:Event):void {
                var y:int = stage.mouseY;
                if (y >= height)
                    y = height;
    
                this.y = y - height;
            }
    
            private function outsideClick(e:MouseEvent):void {
                if (stage.mouseY > this.y + this.height)
                    onEvent(new Event(Event.CLOSE));
            }
    
            public function close():void {
                onEvent(new Event(Event.CLOSE));
            }
        }
    }
    

    The problem is the menu appeared permanently and does not slip too, the colors are not what expected as can be seen in the image below:

    Can someone tell me where I went wrong, I'm not a professional programmer, just an enthusiastic amateur older!

    Thank you very much

    Bob

    I can confirm, you should only use:
    QNXApplication.qnxApplication.addEventListener (QNXApplicationEvent.SWIPE_DOWN, application_SwipeDownHandler);
    On color, it is advisable to use the form that you don't really need to expand all methods of sprite to draw a shape. But, please, try to use 'uint' as a type of the variable 'bgcolor', that I see now - it is an ' int '.

  • question of sizing qnx.ui.display.Image

    I found something weird on qnx.ui.display.Image setSize. I have an Image object do not show the expanded size that I put in the constructor, but appear in its place in the resolution of the image. But he did show well with expansion of size during the function of mouse event. I really have no idea what's going on... Thanks in advance for the help

    package
    {
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import qnx.ui.display.Image;
    
        [SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
        public class AIRHelloWorld extends Sprite
        {
            private var image1:Image;
    
            public function AIRHelloWorld()
            {
                image1 = new Image;
                image1.setImage('assets/abc.png'); // image resolution 57 x 57
                image1.setPosition(200, 10);
                image1.setSize(77, 77); // it does NOT display 77 x 77 size, but 57 x 57 instead
                image1.addEventListener(MouseEvent.MOUSE_DOWN, downWindow);
                image1.addEventListener(MouseEvent.MOUSE_UP, upWindow);
                addChild(image1);
    

    Hey,.

    so I have found that when you first declare the image and add it to the parent object fair instructions telling what to do. However, you give instructions to an empty object. That's how rule where a sprite has no dimension of width or height unless you add children. If this applies to this case as well. until the image is loaded to define its width and height does nothing because he has no "children" in the object. Once the image is loaded from the application he finally has dimension and can be changed. So what I recommend is to attach an event listener to listen to when the image is loaded as below:

    var myImage:Image;
    
    (...)
    
    myImage = new Image();
    myImage.addEventListener(Event.COMPLETE, onLoad);
    myImage.setImage("images/ball.png");
    myImage.setPosition(600,300); //dont mind this just random
    addChild(myImage);
    
    (...)
    
    public function onLoad(e:Event):void
    {
        var myImageObject:Image = (e.target as Image);
        myImageObject.setSize(myImageObject.width*2,myImageObject.height*2);
    
    }
    

    We load instantly, but in execution, it's not even load so nothing do for her before loading. so, once its loading you should be able to handle it if you wish. hope that helps! Good luck!

  • Creating custom UIComponent

    Hello

    I want to create a custom user interface controls. What I need is not only the counting or changing the appearance but creating new types of controls (these controls can possibly be skinnable components).

    What I aim to is to have, for example, controls such as a vertical sliders or knobs. I wonder if these could be achieved by a cursor skinning.

    Finally, I would like to a Jog-Wheel or the wheel, with a button in the Center, something like the old ipod.

    I did several searches on custom components or controls interface user etc but so far could not find info on the count.

    Anyone has any experience on the creation of new UIComponents reusable or you know some good examples or tutorials?

    Thank you!

    I'm not sure of the qnx.ui.slider. Personally, I tend to avoid the libs qnx for portability reasons, and as I skinned my components anyway there is little reason to use them.

    Here is my code for the knob on base. Its value is from 0 (completely to the left) to 100 (all the right way). It is not customizable and probably not usable in design mode, but it should help you get started.

    Cheers, - Jon-

    /**
     * TKnob
     * Rotary knob component
     *
     * @author Jon Webb, http://www.webbsites.nl
     * @version 1.0.0 * @date 06-apr-2011
     *
     * Licensed under MPL - Mozilla Public License - http://www.mozilla.org/MPL/
     */
    package components
    {
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.filters.DropShadowFilter;
        import flash.geom.Point;
    
        import mx.core.UIComponent;
        import mx.managers.IFocusManagerComponent;
    
        [Event(name="change", type="flash.events.Event")]
    
        public class TKnob extends UIComponent implements IFocusManagerComponent
        {
    
            private const DEGTORAD:Number = Math.PI/180; // used for angle conversion
            private const _maxAngle:Number = 180; // maximum angle
            private const _minAngle:Number = 0; // minimum angle
            private var   _currentAngle:Number = 0; // current angle
            private var   _value:Number = 0; // current value
            private var   _valueChanged:Boolean; // track when value is changed
    
            // constructor
            public function TKnob()
            {
                super();
                this.buttonMode=true;
                this.filters = [new DropShadowFilter(5,70,0, 0.66,4,4,3,3)];
                this.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
            }
            // value property setter
            public function set value(v:Number):void {
                if(v != _value) { // if changed
                    if(!isNaN(v)) { // if valid
                        _value = v;
                        _valueChanged = true;
                        invalidateProperties();
                        invalidateDisplayList();
                        dispatchEvent(new Event(Event.CHANGE, true, false));
                    }
                }
            }
            // value property getter
            public function get value():Number {
                return _value;
            }
            // mouse event handlers
            protected function handleMouseDown(e:MouseEvent):void {
                stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
                stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
            }
            protected function handleMouseMove(e:MouseEvent):void {
                _currentAngle = calculateAngle(e);
                value = (calculateValue (_currentAngle)); // use setter
            }
            protected function handleMouseUp(e:MouseEvent):void {
                stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
                stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
            }
            // calculate angle of mouse relative to center point
            private function calculateAngle(e:MouseEvent):Number {
                var cp:Point;
                var mp:Point;
                // get center point
                cp = new Point (this.x+this.width/2, this.y+this.height/2);
                // convert to global
                cp = this.parent.localToGlobal(cp)
                // get mouse point
                mp = new Point(e.stageX, e.stageY);
                // freedom of movement is limited to top half of knob, similar to mixer
                if(mp.y _maxAngle || r < -90) {
                        r = _maxAngle;
                    } else if (r < _minAngle && r > -90) {
                        r = _minAngle;
                    }
                    return r;
                } else {
                    return _currentAngle;
                }
            }
            // convert angle to value
            private function calculateValue(rotation:Number):Number {
                return (_currentAngle - _minAngle) / (_maxAngle - _minAngle) * 100;
            }
            // convert value to angle
            override protected function commitProperties():void {
                if (_valueChanged) {
                    _currentAngle = _value/100 * (_maxAngle - _minAngle);
                    _valueChanged = false;
                }
                super.commitProperties();
            }
            // redraw component
            override protected function updateDisplayList(uw:Number, uh:Number):void {
                super.updateDisplayList(uw, uh);
    
                var hw:Number = this.width/2; // half width
                var hh:Number = this.height/2; // half height
                var sx:Number = Math.cos(_currentAngle*DEGTORAD); // indicator x
                var sy:Number = Math.sin(_currentAngle*DEGTORAD); // indicator y
    
                graphics.clear();
                // draw the knob
                graphics.lineStyle(0,0);
                graphics.beginFill(0xDCDEE7, 1);
                graphics.drawCircle(hw, hh, hw*0.9);
                graphics.endFill();
                // draw the indicator
                graphics.lineStyle(2,0);
                graphics.moveTo(hw-(sx*hw/2), hh-(sy*hh/2));
                graphics.lineTo(hw-(sx*hw), hh-(sy*hh));
    
            }
        }
    }
    
  • multi touch capabilities

    The Simulator allows to simulate the features simple touch.  Two questions:

    1. is there a way to test the multi touch on the Simulator capabilities?

    2. is there a way to disable the multi-touch functionality in my application since I could not yet test what happens if two or more simultaneous 'touch' to happen.

    Thanks for all of you who have some ideas about these issues.

    ... Jim

    JRab and I actually just discussed this point, way back (Jan?  Dec?).  I could try to find the thread if it mattered much.

    Our conclusion, I seem to remember that there are two main options.  Be the first point of contact is considered to be a mouse (MOUSE_DOWN, MOVING, etc.) and any secondary or points of contact (simultaneous) later would be ignored, or a secondary touch would effectively trigger the first to get false MOUSE_UP and then the new touch would get a MOUSE_DOWN, becoming the new position of the mouse.

    The latter option was rejected as fundamentally insane, so we thought that this is the first.

    It would mean that once you touch and keep your finger down, no other keys are recognized until you release the first finger.

    It seems likely that it is essentially as a special case of what would happen with touch input, where only four points of contact are supported and you try to hit a fifth point at the same time.  It would be unwise for the fifth point to be recognized... doing so would imply that even a simple wandering 'brush' the finger could screw up recognition of the actual keys.

    We would have guessed quite wrong, however, and there may be a third or fourth possibility that we hadn't thought about.

  • I have advice on a problem

    Hi all

    I need some advice on a problem, I'm going to. In my application, I'm working, I want to use b.filters = [new DropShadowFilter ()] filter to give the effect of a sprite being picked up and moved. I use this code to move the sprite:

    cardSprites[card].addEventListener(MouseEvent.MOUSE_DOWN, onDown);
    cardSprites[card].addEventListener(MouseEvent.MOUSE_UP, onUp);
    addChild(cardSprites[card]);
    
    private function onDown(e:MouseEvent):void
    {
        b = Sprite(e.currentTarget);
    
        ...
    
        b.filters = [ new DropShadowFilter() ];
        addChild(b);
    
        b.startDrag(false, new Rectangle(0, 0, 1024 - CARD_WIDTH, 594 + CARD_HEIGHT));
    }
    
    private function onUp(e:MouseEvent):void
    {
        b.stopDrag();
    
        ...
    }
    

    The problem is sometimes the event MouseEvent.MOUSE_UP does not draw the sprite is not stop moving. This doesn't happen very often. Maybe 1 out of 100 times or more. I think that the problem is related to the speed of the Simulator because it is not all the time. I hope that it does on a real device. I noticed that when I remove the filter to DropShadowFilter () I don't have the problem. I like the shadow effect. I was thinking of doing a second series of images with a drop shadow, but that would mean I would have twice as many images and I have a lot. I want RIM to send me my PlayBook so I can test this on a real device.

    Do you think I should present my application for approval or rework my application and add all the images?

    Hey PBDev,

    try changing your code as follows:

    cardSprites[card].addEventListener(MouseEvent.MOUSE_DOWN, onDown);
    
    addChild(cardSprites[card]);
    
    private function onDown(e:MouseEvent):void{  b = Sprite(e.currentTarget);
    
        ...
    
     b.filters = [ new DropShadowFilter() ];   addChild(b);
    
        b.startDrag(false, new Rectangle(0, 0, 1024 - CARD_WIDTH, 594 + CARD_HEIGHT));
    
      stage.addEventListener(MouseEvent.MOUSE_UP, onStageMouseUp);
    
    }
    
    private function onStageMouseUp(e:MouseEvent):void{  b.stopDrag();
    
       stage.removeEventListner(MouseEvent.MOUSE_UP, onStageMouseUp);
    
     ...}
    

    Basically instead of make a mouse event on the object itself, do on the stage. It doesn't matter where the user makes mouseup, he's always going to be picked up. the best way to go without compromise. hope that helps. Good luck!

  • Wait for the sprite press / clicked

    Hi, I am trying to display graphics when the user touches the sprite first which I reproduce, then another graphic when the user releases the sprite (raises their finger). I don't know how to go on this subject! Please help me!

    Thanks in advance

    On the Sprite that you draw in, add an event listener for mouse down and mouse upwards.  This will work only on drawn graphs and not areas of the sprite which pulled anything in.

    private var sprite: Sprite = new Sprite();

    //...

    addChild (sprite);

    make the drawing

    sprite.addEventListener (MouseEvent.MOUSE_DOWN, MouseDown);

    //...

    private function MouseDown (event: MouseEvent): void

    {

    this.sprite.addEventListener (MouseEvent.MOUSE_UP, MouseUp);

    do something

    }

    private void MouseUp (event: MouseEvent): void

    {

    this.sprite.removeEventListener (MouseEvent.MOUSE_UP, MouseUp);

    do something

    }

  • Help user interface

    In an application that I create, Inc. (which are the sprites) must be moved around, connected and disconnected by the user. Right now I use Mouse_Down, Mouse_Move and Mouse_Up for movement, and I implemented a double click for working with the connection. I need another gesture / to the user to disconnect. I don't want to add a button to switch between the connection / disconnection, because I wish they were able to do both on the fly.

    Suggestions for the type of event that I should plug disconnection up to?

    Now be sure you could do something like this to avoid any gesture API stuff probably:

    On a mouse down the value of a state variable and save the mouse coordinates down.  On a mouse to get the coordinates of the mouse upwards and calculate the segment of the line of the mouse to the bottom of the location of the mouse to the high place.  Calculate if this segment of the line crosses a line segment, which represents a connection between your two connected sprites.

    Just thinking "aloud.

Maybe you are looking for