Why add a listener for an Event object?

Hello


I just read something that I do not understand in a book and, of course, I need help...


stage.addEventListener (MouseEvent.MOUSE_DOWN, clicSouris);

function clicSouris (pEvt:MouseEvent): void
{
var positionX:Number = pEvt.stageX;
var positionY:Number = pEvt.stageY;
monDessin.graphics.moveTo (positionX, positionY);
pEvt.currentTarget.addEventListener (MouseEvent.MOUSE_MOVE, bougeSouris);
}

function bougeSouris (pEvt:MouseEvent): void
{
var positionX:Number = pEvt.stageX;
var positionY:Number = pEvt.stageY;
monDessin.graphics.lineTo (positionX, positionY);
pEvt.updateAfterEvent ();
}


My question is what appens when I add an event listener for the event of the object? And why it does this?


Following the logic with the AS3 display list, I thought that only Classes that inherit from flash.display.InteractiveObject might react to events from mouse (or keyboard).


You can subscribe itself in any event an event? Am I wrong?


Can someone explain to me this point because I'm really confused!


Thank you!

Basically function clicSouris is in itself an event listener and has pEvt as event event object argument.

When you call .currentTarget pEvt it refers to the current object where the pEvt event is dispatched.

Event.target and Event.currentTarget will always return the interactive objects where the event is currently being distributed.

Tags: Adobe Animate

Similar Questions

  • Is possibility and DragComplete on a list scroll bar thumb - possible to add a listener for those events?

    can't seem to find the real element to: addEventListener (DragEvent.DRAG_COMPLETE, callback) in a List component. It seems that there should be a way to write something like: myList.scroller.thumb.addEventListener (...) Any ideas? Thank you b

    Spark scrollbar thumbRelease, Halo scrollbar as thumbPosition.

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

  • The proper way to remove a listener for loader events

    Hello.

    I´d would like to know what is the rigth way to remove a listener for loader events?

    Like this?

    loader.contentLoaderInfo.removeEventListener (ProgressEvent.PROGRESS, onProgressData)
    loader.contentLoaderInfo.removeEventListener (Event.INIT, onInit)

    Thank you

    I find the best way to remove them is to make them the same way you added, replacing 'Add' with 'delete'... it seems that you did in your example.

  • How to add a listener for a TextFrame BEFORE_PLACE / events AFTER_PLACE?

    Using Creative Suite Extension Builder 2.0 I am trying to automate some behavior once a text block is created, or when a text block is bound to an xml element. I'm not able to add the right event listener.

    The States of documentation that there is a BEFORE_PLACE and an AFTER_PLACE event on the text frame... these events bubbles. I tried listening on the events using IDScriptingEventAdapter by adding global listeners and listeners on the application or the document like this:

    IDScriptingEventAdapter.getInstance () .addEventListener ("afterPlace", handler);

    IDScriptingEventAdapter.getInstance () .addEventListener ("beforePlace", handler);

    IDScriptingEventAdapter.getInstance () .addEventListenerToObject ("afterPlace", handler);

    IDScriptingEventAdapter.getInstance () .addEventListenerToObject ("beforePlace", handler);

    The handler is not called when I create a text block.

    Anyone know what I'm doing wrong?

    BEFORE_PLACE and AFTER_PLACE is placed only for assets. (that is, items that appear in the links Panel).

    Substances

  • Listener for the event of a forwarding

    Hello

    I had a problem the majority of had sorted with the help of other people, but it left me with the last part, I do not understand...

    I have a main.swf that loads an external swf called menu1.swf into a charger. I'm trying to get a function triggered when it receives an event dispatched from the menu1.swf in the main.swf. The main problem I had was getting the event leave the premises of the swf loaded, but it is now sorted. My main problem now is where to add the listener to the main.swf listening event.

    I have been informed that it is not the charger, that I should be attaching the listener, but rather its content (the function I want to call is to unload the charger once the event from the contents of this charger was sent). The content is now menu1.swf, but I don't think that you can attach a listener to a swf file? We also said that once the charger charge, the swf file is no longer a SWF, but becomes rather content.data...

    So which join I have a listener? If it is loader.content.data.addEventlistener (...);

    It has left me speechless?

    loader.content.addEventListener (...);

    (add loader after loading is complete.)

  • Listen for main events outside the java application

    I'm automating a procedure with the class Robot, sending mouse clicks and keys all around the BONE. I wish I could stop this procedure with a combination of keys, but the active window may not something to do with java at that time.

    Is there a way for my java application to listen a touch in this way?

    sabre150 wrote:

    Smigh wrote:
    Is there a way for my java application to listen a touch in this way?

    I would be very uncomfortable if it were possible without some big restrictions because it would allow a rogue program record passwords entered in other programs.

    Although keyloggers are available on any platform.

    The reason why you will not do using Java is because it is cross-platform and isolates your applications from the OS, rather than provide a pleasant environment and comfortable sandbox; to system events is exactly the opposite of isolation. Use a native language of the OS to be able to have the opportunity to do such things (and even then it will probably not possible without jumping through hoops first).

  • To listen for the event click on a tag af:image

    Dear all,

    Can someone help me why my code does not work.

    Use cases, using an Image, I wanted to call a method of bean managed whenever I clicked on the image. So, here's what I did, I added a clientlistner
    and wait than the click event. Also, a server listener is attached to the image.
    <af:image >
         <af:clientListener type="click" method="handleImageClick"/>
         <af:serverListener type="ImageEvent"
                           method="#{viewScope.MyBean.handleImageEvent}"/>
    </af:image>
    .. and here's my javascript...
    <f:facet name="metaContainer">
         <af:resource type="javascript">
           function handleImageClick(evt)
           {
                var comp = evt.getSource();
                AdfCustomEvent.queue(comp, "ImageEvent",{ fvalue : comp.getSubmittedValue()},false);
                evt.cancel();
           }
         </af:resource>
    </f:facet>
    .. and here's my managed bean method.
    public void handleImageEvent(ClientEvent ce)
    {
    
    }
    I don't know why he's not calling my managed bean method. Is there a any error in my code?

    JDEV 11G PS5

    Thank you

    the problem is in Javascript. delete "fvalue: comp.getSubmittedValue ()" and works perfectly.

     AdfCustomEvent.queue(comp, "ImageEvent",{ },false);
    

    comp.getSubmittedValue ()? model is a picture

  • How to add a function for calculating dragged objects on board animate?

    Hi guys! Need your help! I need to connect the rrotation and animation of numbers in Adobe Edge button animate, I did the button moved and don't know how to do the rest...

    Add a scrins:

    1.jpg2.jpg


    and edge files animate Dropbox - dc_power_supply_animate.zip to better explain what I mean

    Turning the knob with extension 'Draggable' of GreenSock. And there is little help I receive from GreenSock:

    Drag and rotate the demo


    and copy the following code:


    Draggable.Create (".dial", {}

    type: "rotation."

    limits: {minRotation:0, maxRotation:360}, / / value min/max limits of the beach

    throwProps:true,

    onDrag:Calc,

    onThrowUpdate: Calc / / if you want to use ThrowProps, you must onThrowUpdate fn to run your function to throw

    });

    function Calc() {}

    Console.log (this.rotation)

    You can do any calc math with 'this.rotation' to get your serial number of desire as: this.rotation/360

    var R = this.rotation/360;

    document.getElementById("myText").innerHTML = R;

    }

    But I can't take it aboard an animation to make an entire animation

    Thanks in advance for any help! Concerning

    Misha.

    Draggable.Create (".knob1, .knob2," {type: 'rotation', throwProps:true, bounds: {minRotation:0, maxRotation:270}});}})

    Draggable.Create (".knob1", {}

    type: "rotation."

    limits: {minRotation:0, maxRotation:270}, / / value min/max limits of the beach

    throwProps:true,

    onDrag:Calc,

    onThrowUpdate: Calc / / if you want to use ThrowProps, you must onThrowUpdate fn to run your function to throw

    });

    function Calc() {}

    Console.log (this.rotation)

    You can do any calc math with 'this.rotation' to get your serial number of desire as: this.rotation/360

    var R = this.rotation/360;

    SYM.$("AmperText").html (R);

    document.getElementById("myText").innerHTML = R;

    }

  • Listener for ObjectChoiceField

    I am trying to add a listener for an ObjectChoiceField in the same way I did for a ButtonField in this code. But I get an error in this line ObjectChoiceField choiceSelected = field (ObjectChoiceField);

    For now I check to headset ObjecChoiceField with a dialog.alert. If it works then I intend to add a BitmapField to the screen that would alter the images with different selections in the drop-down list (ObjectChoiceField).

    Any help would be appreciated!

    SerializableAttribute public class TestListeners extends UiApplication {}

    Public Shared Sub main (String [] args) {}

    PAP TestListeners = new TestListeners();

    theApp.enterEventDispatcher ();

    }

    public TestListeners() {}

    pushScreen (new TestListenersScreen());

    }

    final TestListenersScreen class extends form {}

    public TestListenersScreen() {}

    HorizontalFieldManager _fieldManagerBottom = new HorizontalFieldManager();

    Add (_fieldManagerBottom);

    ButtonField canadaButton = new ButtonField ("Canada");

    ButtonField ukButton = new ButtonField ("UK");

    ButtonField usButton = new ButtonField ("USA");

    FieldChangeListener buttonListener = new FieldChangeListener() {}

    ' Public Sub fieldChanged (field field, int context) {}

    ButtonField buttonPressed = field (ButtonField);

    Status.Show (buttonPressed.getLabel () + "button has been pressed");

    }};

    canadaButton.setChangeListener (buttonListener);

    ukButton.setChangeListener (buttonListener);

    usButton.setChangeListener (buttonListener);

    _fieldManagerBottom.Add (canadaButton);

    _fieldManagerBottom.Add (ukButton);

    _fieldManagerBottom.Add (usButton);

    String [] choiceArray = {'image1', 'image2', 'image3'};

    ObjectChoiceField choice = new ObjectChoiceField ("Drop-down list for choosing" choiceArray, 1);

    ChoiceListener myChoiceListener = new ChoiceListener();

    choice.setChangeListener (myChoiceListener);

    Add (Choice);

    }

    }

    }

    / public class ChoiceListener implements FieldChangeListener {}

    ' Public Sub fieldChanged (field field, int context) {}

    ObjectChoiceField choiceSelected = (ObjectChoiceField) field.<-->

    Dialog.Alert ("choice" + choiceSelected.getSelectedIndex () + "has been pressed");

    }

    };

    What is the error you get?

    I have field listeners that listen on the buttons and the ObjectChoiceFields.  I use code like:

    ' Public Sub fieldChanged (field field, int context) {}

    If (field instanceof ObjectChoiceField) {}

    ObjectChoiceField test = field (ObjectChoiceField);

    Dialog.Alert ("choice" + test.getSelectedIndex () + "has been pressed");

    }

    }

  • PIM listener for memo change

    I read through the API to find out how to add a listener for memos.  I want to take the changes/additions/deletions of memos using the MemoPad application. BlackBerryPIM has MEMO_LIST, butaddListChangeListener(ListChangeListener listener) has:

    pimListType - the type of PIM list to open; valid values include CONTACT_LIST, EVENT_LIST and TODO_LIST.

    Can I set a listener to the evolution of the memo? If so, how?

    use BlackBerryPIM.MEMO_LIST

  • Listener for slider

    I have 8 sliders in an HBox, and I want to add a listener for each one that will allow me to know what cursor is somehow. Each slider represents a channel for a device, and even if I can add a listener which relays a number that represents the new value of the slider, he didn't tell me what cursor is. Although I can add an int value that represents the number of the channel of the cursor to its user data, it doesn't seem to be a way to extract the return type (number). The code looks like this:

    HBox hbox = new HBox (8); spacing of
    for (int i = 0; i < gain.length; i ++) / / for each output
    {
    [i] gain = SetLook (new Slider (0,100,0));
    gain .setUserData (i + 1); / / the number of input
    hbox.getChildren () .add (gain [i]);
    .valueProperty () .addListener (new ChangeListener < number > () [i] gain
    {
    @Override
    public void changed (ObservableValue <? extends number > ov, oldValue, newValue number number)
    {
    makeGainChange ((int) newValue.getUserData (), newValue.intValue ());
    makeGainChange (1, newValue.intValue ());
    }
    });
    }
    HBox hbox = new HBox(8); // spacing
    for(int i = 0; i < gain.length; i++) // for each output
    {
      gain = SetLook(new Slider(0,100,0));
      // gain.setUserData(i+1); // the input number
      hbox.getChildren().add(gain);
    
      // Add this:
      final int inputNumber = i+1 ;
    
      gain.valueProperty().addListener(new ChangeListener()
      {
        @Override
        public void changed(ObservableValue ov, Number oldValue, Number newValue)
        {
          // now pass the input number to your method:
          makeGainChange(inputNumber, newValue.intValue());
        }
      });
    }
    

    Edited by: James_D 7 April 2013 12:16

  • How do I listen for the change in the position of a node

    Hello

    I want to create a knot of thread/connection between two nodes of the scene. I want this thread node to be updated when one of the nodes is moving. In the common scenario I'd listen for change events in the nodes of the target of the post and update the thread:

    targetNode1.translateXProperty () .addListener (new ChangeListener < number > () {}
    public void changed (value of ObservableValue, oldValue, newValue number number) {}
    wire.setStartX (targetNode1.getTranslateX ());
    wire.setStartX (targetNode1.getTranslateY ());

    wire.setEndX (targetNode2.getTranslateX ());
    wire.setEndY (targetNode2.getTranslateY ());
    }
    });



    The problem is that the target nodes are children of a different container nodes (who are moving in fact). To listen for change events in the properties to translate target nodes does not work (their parent nodes are moving actually)

    Is there way of list of change in the overall position of the target relative to the scene nodes?

    That's right, it's not a super easy way to do. You need to connect listeners to each node in the parent hierarchy. The reason for which we do not have this feature built-in, is because it is extremely expensive (early versions of JavaFX 1.0 pre had "boundsInScene" but which was incredibly convenient, also completely killed performance). Do this for a few nodes is not a problem, but the fact for each node in the scene would be your 3 GHz machine to its knees :-).

    Richard

  • How to listen for the click to the button actionContent in view event

    Hello

    In doing so:

    FlexGlobals.topLevelApplication.addEventListener ('actionContentClick', showOptions);

    By calling showOptions() any time that the view had come out. Sticks of Manager and every time I get a view in the creationComplete for this turn I add the listener even over and over.

    How should this be done?

    1 FlexGlobals.topLevelApplication is the subject of the right to listen to?

    2. I can remove the listener on view turn off, but I don't know if that will be called whenever the view goes.

    3. check if an object already has an earpiece and who is he?

    Thank you.

    1 not sure; What exactly are you trying to do?

    2. Yes, every time you move to a separate view that will be dispatched to the VIEW_DEACTIVATE event. It would be a good place to remove the event listener.

    3. you can use hasEventListener(type:String) to test the presence of an event handler.

    -Tom Kraikit

    Flex SDK engineer

  • Tuned for PropertyChangeEvent events sent by objects related

    Hi all

    It is my understanding that when you link the two objects together (in my case, with a two-way link - but I think it would be the same thing with a one-way connection), the Flex compiler generates code that will send a PropertyChangeEvent object that you have linked to the update.

    I wonder how I can manually link to this event.  Here are my particular use case: whenever my value object is updated, I want to inspect it and see if the user has submitted a complete set of data for this particular value object.  If they have, I would like to raise an event that will be dealt with elsewhere in my application.  This event said "user has entered a complete set of value object data {all}.

    I am doing inside a component.  Here is the code for my component.  The user enters information on a candidate, and I was hoping that the "changeEventListener" function would fire whenever something in my value object is updated, but it never take a shot.  However, my value object (this.applicant:Applicant) Gets the data of the input controls, so the link should work.

    My guess is that I need addEventListener elsewhere, rather than on the component itself?  But where?

    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" width="650" height="90"
               creationComplete="group1_creationCompleteHandler(event)"
               >
         <fx:Script>
              <![CDATA[
                   import valueObjects.Applicant;
                   
                   import mx.controls.Alert;
                   import mx.events.FlexEvent;
                   import mx.events.PropertyChangeEvent;
                   
                   import spark.events.TextOperationEvent;
                   
                   [Bindable]
                   public var label:String;
                   
                   [Bindable]
                   public var applicant:Applicant = new Applicant();
    
    
                   protected function group1_creationCompleteHandler(event:FlexEvent):void
                   {
                        addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,changeEventListener);
                   }
                   
                   protected function changeEventListener(arg1:Object,arg2:Object,arg3:Object):void{
                        Alert.show("I got called");
                   }
                   
    
              ]]>
         </fx:Script>
         <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
         </fx:Declarations>
         <s:Label x="0" y="10" text="{this.label}" fontWeight="bold"/>
         <s:DropDownList x="0" y="62" width="60" id="TitleDropDownList" selectedItem="@{applicant.title}" />
         <s:TextInput x="73" y="62" id="firstname" text="@{applicant.firstname}"/>
         <s:TextInput x="213" y="62" id="middlename" text="@{applicant.middlename}"/>
         <s:TextInput x="353" y="62" id="lastname" text="@{applicant.lastname}" />
         <s:DropDownList x="493" y="62" width="60" id="SuffixDropDownList" selectedItem="@{applicant.suffix}" />
         <s:DropDownList x="565" y="62" width="60" id="UsCitizenDropDownList" selectedItem="@{applicant.usCitizen}">
              <s:dataProvider>
                   <s:ArrayList source="{[true,false]}"/>
              </s:dataProvider>
         </s:DropDownList>
         <s:Label x="0" y="47" text="Title"/>
         <s:Label x="73" y="47" text="First"/>
         <s:Label x="213" y="47" text="Middle (optional)"/>
         <s:Label x="351" y="47" text="Last"/>
         <s:Label x="494" y="47" text="Suffix"/>
         <s:Label x="565" y="47" text="US Citizen?"/>
    </s:Group>
    
     
    

    I guess what you want is to listen for changes to one of the properties of the object of the applicant. If this is the case, it may be easier for your class of applicant to simply extend EventDispatcher.

    [Bindable]
    Applicant/public class extends EventDispatcher
    {
    public var firstName:String;
    public var lastName:String;
    }

    And then you can have something like this:

    applicant.addEventListener (PropertyChangeEvent.PROPERTY_CHANGE, changeEventListener);

    Who will listen to all changes of ownership in the applicant.

  • Canvas, click events for the child objects

    I am trying to record an event for each child object.
    and I use the following code

    http://livedocs.Adobe.com/Flex/3/HTML/Help.HTML?content=events_08.html
    in the part of the examples (second example)

    However, I am dynamically add custom Image objects extended and when click on a displayed Image and check for its type if its correct type, it would just return false.
    Alert.Show ((event.target_est_dans_MyAClass).toString ());

    When clicking on one of the children is opposed and display the event.target.name and it's just also displays a silly 'FlexLoader74' or whatever number. Somehow, it loses its properties or the type of the object.

    Is there something that I am missing?

    The loaded image, you click on IS what would return with event.target. It is added to your image class extended as a child of this class. So it's probably that you want to do:

    Alert.Show ((event.target.parent_est_dans_MyAClass).toString ());

    Keep in mind that if EMBED you your images in your image personalized instead compile-time class, then you can check for this as you did before:

    Alert.Show ((event.target_est_dans_MyAClass).toString ());

    TS

Maybe you are looking for

  • I can't send email from a remote location, why?

    Home Thunderbird works fine. When I go to my sons or daughters of the House I can get emails but can't send them. I get an error message the connection times out. I can send and receive e-mails on my iPad using the standard MAC e-mail program. They u

  • Can not activate ipad 2 which follows download od iso9

    I have read reports that the problem is maybe that the server is actually busy? Cannot bind to the iTunes account as it says that my account is not verified? I did the tests checked my details and turned on my computer. Go on vacation tomorrow so rea

  • Z10 BB Z 10 blackBerry flash Adobe

    I did the last update 10.3.1.1565 but how do I activate the browser adobe flash?

  • How to remove blackBerry smartphones configured email

    Mr President, I have the BB curve 9300, I want to delete my emails configured but unable to do so, please suggest me.

  • Remove the entry from Add/Remove programs

    I uninstalled Adobe Photoshop Elements 9 and Adobe first Elements 9 my Windows 7 64-bit. Uninstall succeeded.  However, references to them are still show in Add/Remove programs in Control Panel. I checked in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wind