Question of Event.Target

Hi, I think I wrote that this evil, but could not find a solution.

It works:

Parts1_mc.addEventListener (MouseEvent.CLICK, RunTraining);

function RunTraining(e:MouseEvent):void

{

Global.run = Parts1_mc. Parts1.text;

trace (Global.run);

};

When I do that, I get an undefined error message:

Parts1_mc.addEventListener (MouseEvent.CLICK, RunTraining);

function RunTraining(e:MouseEvent):void

{

Global.run = Parts1_mc.event.target.text;

trace (Global.run);

};

As you found, if the event target is the object textfield, so would you just to get the text value, since it is a direct link with it.  But the textfield object could not be the target of the event, since you have the listener assigned to Parts1_mc, not Parts1 textfield.  The target of the event could be any child of the Parts1_mc object.  You're better off assigning the listener to the target object and use e.currentTarget instead of e.target.

Tags: Adobe Animate

Similar Questions

  • event.target.buttonImportIcon ();

    First of all, let me say that I know just enough to be dangerous... so please be nice.

    FYI - I have Acrobat, full paid, more up-to-date version.

    I created a form and in this form, I have several boxes for the insertion of photos. I use the script event.target.buttonImportIcon (); to insert pictures. I am aware that in the free version, only the PDF files may be inserted. However, I have the full version. When the box opens for me to find the picture to be inserted, it takes by default showing only PDF files. I can change it to jpg and browse, but it is heavy, because every time I have to complete this form, I need to send pictures of 12-18 for documentation.

    My question is, is there a way so that the box which opens all to display jpg files? Or at least to show all file extensions? I know that this is not a huge deal, but I do 3 to 5 of these forms per day, with pictures of 12-18 each, so it would be nice not to change the file type, I'm looking at every time.

    Thanks a lot for your help!

    Someone asked more information, so here's a more complete script which can be placed in a folder level JavaScript file:

    var ASGJ_buttonImportIconAll = app.trustedFunction(function (doc, f_name) {
    
        // Get a reference to the specified field
        var f = doc.getField(f_name);
    
        // If the specified field does not exist...
        if (!f) {
    
            app.beginPriv();
            app.alert({
                cMsg: "The specified field [" + f_name + "] does not exist.",
                nIcon: 0,  // Error icon
                nType: 0,  // OK
                cTitle: "Field does not exist"
            });
            app.endPriv();
    
            return;
        }
    
        // If the specified field is not a button...
        if (f.type !== "button") {
    
            app.beginPriv();
            app.alert({
                cMsg: "The specified field [" + f_name + "] is not a button.\r\rField type: " + f.type + "\r\rCannot import icon.",
                nIcon: 0,  // Error icon
                nType: 0,  // OK
                cTitle: "Field is not a button"
            });
            app.endPriv();
    
            return;
        }
    
        // If the button layout is label only...
        if (f.buttonPosition === position.textOnly) {
    
            app.beginPriv();
            app.alert({
                cMsg: "The specified button [" + f_name + "] has a Text-only layout.\r\rCannot import icon.",
                nIcon: 0,  // Error icon
                nType: 0,  // OK
                cTitle: "Button layout is text-only"
            });
            app.endPriv();
    
            return;
        }
    
        // Prompt user to select a file to use as the source for the button icon
        app.beginPriv();
        var oFilespec = app.browseForDoc({
            cFileFilter: 2,
            cWindowTitle: "Select an image"
        });
        app.endPriv();
    
        // Deal with the selected file
        if (typeof oFilespec !== "undefined") {
    
            // Attempt to use the selected file as the source of the button icon
            app.beginPriv();
            var nReturn = f.buttonImportIcon({
                cPath: oFilespec.cPath
            });
            app.endPriv();
    
            switch (nReturn) {
            case -1 :
                app.beginPriv();
                app.alert({
                    cMsg: "The selected file: " + oFilespec.cPath + "\r\rcould not be opened." ,
                    nIcon: 0,  // Error icon
                    nType: 0,  // OK
                    cTitle: "Cannot open selected file"
                });
                app.endPriv();
                break;
            case -2 :
                app.beginPriv();
                app.alert({
                    cMsg: "The selected page is invalid.\r\rCannot import icon.",
                    nIcon: 0,  // Error icon
                    nType: 0,  // OK
                    cTitle: "Selected page invalid"
                });
                app.endPriv();
                break;
            default :
                // Import was successful or user canceled
                // so there's nothing to do
            }
    
        }
    
    });
    

    The function can be called like that in the mouse event to the top of a button:

    ASGJ_buttonImportIconAll(this, event.target.name);
    
  • testbox. Optimization of event.target listener and event name

    Is it possible to get the name of a TextBox of event.target?

    stage.addEventListener (MouseEvent.MOUSE_DOWN, clickHandler);

    function clickHandler(e:Event):void {}

    trace (e.Target.Name);

    }

    out to click on a text box is

    instance1111

    I am creating a clickHandler which takes care of everything by checking the name of which was clicked on instead of adding individual headphones to each object.

    (added)

    Another solution that I thought would be to separate the text and turn it into an object, but I prefer not to do that if it can be helped.

    (question 2)

    I worked on a menu, when you click on something it becomes visible and adds / removes event listeners to each button you change your location.

    Switching between menus causes a noticeable pause, which made me think to spend the 1 Manager of.

    Is there a reason to not just leave the active event listeners?  Even better if I can get the above responded and have 1 single active listener to the menu instead of 30.

    In order to get the name of the event.target text box you need

    Event.Target.parent.parent.Name

    A text box consists of 2 subobjects.

    (added)
    Your comment about having children made me put 2 and 2 together.  Initially, I tried e.target and she came back with TextLine, didn't think about it being a "child" until your comment.

    trace (e.Target); TextLine

    trace (e.Target.parent); Sprite

    trace (e.Target.parent.parent); TLFTextField

  • New in AS3: stupid question about event listeners...

    Hi all

    I am a newbie in Flash and have a question about event listeners. I have a site I'm developing with a movie clip navigation which is composed of several buttons. What is the right way to write the event listener?

    Here's a sample of what I have:

    I have a clip called 'buttons_mc' that contains the symbols of individual button with various names such as "btn_history". So far, I don't have an instance name for the clip of the film itself.

    My event listener:

    btn_history.addEventListener (MouseEvent.CLICK, history);

    I have to put something before the "btn_history" which refers to the video? I get this error message:

    1120: access of undefined property btn_history.

    Thank you!!!

    Julia

    Yes, it is preferable to have at least one layer dedicated to actionscript.  I often use a couple... one for code shared (functions and variables) and a level of the frame code (stop(), etc.).

    The code must be in a scenario where the button is directly accessible.  If your button is accessible in frame 1, which means that it does not animate in place such that it is not really intended to be used until you get somewhere near the bottom of the timeline, then you can target the button of the timeline that holds the buttons_mc movieclip.  So as I described earlier, if you give this movieclip an instance name of "buttons", and then to assign a code to the button on the inside you should use...

    Buttons.btn_history.addEventListener (MouseEvent.CLICK, history);

    But if the button exists somewhere down the timeline inside the buttons_mc due to the animation of the button, which means that there is more than one key image for the button, then you must place the code that you have initially shown in the last keyframe to the bottom of the timeline where he set the button in place.

    .

  • How to use the String with an external dispatchEvent event.target.name?

    ... I hope that the question of the title makes sense...

    On my stage, I have an external SWF loaded with a button. When you click the button dispatches the main event scene.

    On the main stage a listener can load a SWF it in a magazine called Gallery.

    The charger of the Gallery is also shared by the buttons on the main stage, who use the event.target.name chain to appeal to sovereign wealth funds with corresponding names.

    I use tweens to fade and, in the content of the Gallery when a key is pressed.

    --

    Loading of the FSV worked until I tried to create a universal function for the dispatchEvent buttons...

    The problem I have is that I don't know how to set the string to indicate to the newSWFRequest where the SWF file when triggered by external buttons.

    (I maybe do this wrong... but thought that the best way to load a SWF on the main stage from an external SWF was using dispatchEvent?)

    My code raises the event and the charger of the Gallery Faints, but then it does not find the new SWF:

    Error #2044: Unmanaged by the IOErrorEvent:. Text = Error #2035: URL not found.

    Please can someone help me understand how to make the point in the chain in the right direction? (I think that the errors only are in bold below)

    Code:

    var myTweenIn2:Tween;

    var myTweenOut2:Tween;

    var nextLoadS2:String;

    Listening external inclinometer shipped external event

    addEventListener ("contactStage", btnClickExtrnl);

    function btnClickExtrnl(e:Event):void {}

    nextLoadS2 =?

    myTweenOut2 = new Tween(gallery,"alpha",None.easeOut,gallery.alpha,0,0.2,true);

    myTweenOut2.addEventListener (TweenEvent.MOTION_FINISH, tweenOutCompleteF2);

    }

    Function universal BTNS

    function tweenOutCompleteF2(e:TweenEvent) {}

    myTweenOut2.removeEventListener (TweenEvent.MOTION_FINISH, tweenOutCompleteF2);

    myTweenOut2 = null;

    var newSWFRequest:URLRequest = new URLRequest ("SWFs /" + nextLoadS2 + ".swf");

    myTweenIn2 = new Tween (Gallery, "alpha", None.easeOut, gallery.alpha, 1, 0.2, true);

    Gallery.Load (newSWFRequest);

    Gallery.x = Xpos;

    Gallery.y = Ypos;

    }

    Thank you.

    If this code is on the timeline of a child of the main timeline of your external swf add parent 3rd in two lines with parent.parent.

  • run event.target from a page 1 button to run on page 4 of the form

    Hello

    I currently have a button on page four of the form which takes place this javascript.

    If (event.target.value! = 'Off') {}

    this.getField("strike5").display = display.visible;

    } else {}

    this.getField("strike5").display = display.hidden;

    }

    If (event.target.value! = 'Off') {}

    this.getField("strike6").display = display.visible;

    } else {}

    this.getField("strike6").display = display.hidden;

    }

    //

    If (event.target.value! = 'Off') {}

    this.getField("strike7").display = display.hidden;

    } else {}

    this.getField("strike7").display = display.visible;

    }

    If (event.target.value! = 'Off') {}

    this.getField("strike8").display = display.hidden;

    } else {}

    this.getField("strike8").display = display.visible;

    }

    I wish now to turn by a button on page 0 to do the same on page four.

    Is this possible?

    I hope so... See you soon

    I would create a document-level function to adjust the display of the fields when the box of cehck is not equal to 'Off '.

    function SetStrikeDisplay (cValue)
    {
    Set the fields to display when the value is 'Off' to the default value;
    this.getField("strike5").display = display.hidden;
    this.getField("strike6").display = display.hidden;
    this.getField("strike7").display = display.visible;
    this.getField("strike8").display = display.visible;
    If (cValue! = "Off")
    {
    this.getField("strike5").display = display.visible;
    this.getField("strike6").display = display.visible;
    this.getField("strike7").display = display.hidden;
    this.getField("strike8").display = display.hidden;
    }
    return;
    } / / end of function SetStrikeDisplay;

    For each field, you want this script to run to use the following code:

    SetStrikeDisplay (event.target.value);

  • How to get event.target/event.currentTarget for HTML 5 canvas for Manager click

    Hello

    I hope that everyone else is doing great.

    I belong to bottom Actionscript and just started on CC Flash HTML 5 Canvas.

    How to get event.target and event.currentTarget in CC Flash for HTML 5 canvas for the click event.
    As we used to do an ACE 3.0

    btn.addEventListener (MouseEvent.CLICK, GB);

    function GB (evt:MouseEvent) {}

    trace ("evt-" + evt.currentTarget); It will let us know the selected target
    }

    For HTML-5

    btn.addEventListener ('click', go.bind (this));

    function GB (evt) {}

    Console.log ("evt-" + evt.? t); What is the correct syntax here?

    }


    Thank you


    Hey guys found the answer to stackoverflow

    It's - evt.target

  • event.target.content.loaderInfo gives error if I'm to access images of the external field (SecurityErr

    I'm working on OSMF-based player. I added the image of the logo at the top right of my player. Now, I want to open a link when you click on the logo image.

    I wrote a script code Action in onMouse during the event

    CODE:

    private void onMainClick(event:MouseEvent):void {}

    If (Event.Target.hasOwnProperty ('Content'))

    {

    var info: LoaderInfo = event.target.content.loaderInfo;

    var imageUrl:String = configuration. LogoImage; Logo url to view the player

    imageUrl = imageUrl.split("/").splice(1).join("/"); "

    If (info. URL. Search (ImageUrl) > = 0)

    {

    var url: String = configuration. LogoLink; Logo link to open it in a new tab

    var request: URLRequest = new URLRequest (url);

    Try

    {

    navigateToURL (request, "_blank");

    }

    catch(Error:Error)

    {

    trace ("Error occurred!");

    }

    }

    }

    }

    When I give the url of the Logo of the same domain, it works very well (given the url will open in a new tab). Problem occure when I access the image of the external domain. A field that doesn't support request to my domain.

    More information: the Logo image appears correctly on the upper right of my player. On clcik logo url, I am getting error below. I am providing the url of the logo of my config file

    SecurityError: Error #2123: security sandbox violation: Loader.content: http://10.1.0.126/release/XYZPlayer.swf Can't access to http://www.esnipe.com/shared/help_icon.gif . Access granted to no political file.

    to flash. display::Loader / get content())

    to StrobeMediaPlayback / onMainClick)

    Please can someone help me out of this error.

    use:

    var info: LoaderInfo = event.target.contentLoaderInfo;

  • Y at - it another way to get the doc object other than event.target

    I have a situation where event.target returns undefined.

    I have JavaScript in the preSubmit event not firing when you click on the button Save in the workspace. I've been tracking this button across the bridge form called saveXML. The code I ran changes the XML, so I still need to run before a save. I've added a call to run the preSubmit event before the saveXML line. My code has failed because I discovered because when you use event.target in the preSubmit case, it is not defined when it is called from the form bridge code.

    I noticed that the form bridge code itself used event.target. I'm gathering from the comments that the event object is changed by this code for the target child is no longer there. I created a variable at the top and together event.target before where I think that it would be changed. I then used this variable, and it solved my problem.

  • Remove the MovieClip with event.target.content

    Hi everyone please I need your help I have this code and I want to delete baresClip but I cante removeit Please helpme

    var loaderBares:Loader = new Loader();

    loaderBares.unload ();

    loaderBares.load (new URLRequest("negocio/bares.swf"));

    loaderBares.contentLoaderInfo.addEventListener (Event.COMPLETE, loadBares);

    function loadBares(event:Event) {}

    var baresClip:MovieClip = event.target.content;

    baresClip.x =-474;

    baresClip.y = - 135;

    addChild (baresClip);

    baresClip.over1.receta1.addEventListener (MouseEvent.CLICK, prueba);

    function prueba(event:MouseEvent):void {}

    gotoAndStop ("receta1");

    removeChild (baresClip); / * Here is work * /.

    }

    MovieClip (root),.mc_negocio.menu_negocio.btn_botanas.addEventListener (MouseEvent.CLICK, goToBotanas);

    function goToBotanas(event:MouseEvent):void

    {

    removeChild (baresClip);   / * Here is not work * /.

    gotoAndPlay ("botanas");

    }

    Oh, I see what you're doing.  you entered baresClip local loadBares.

    to remedy this, use:

    var baresClip:MovieClip

    var loaderBares:Loader = new Loader();

    loaderBares.unload ();

    loaderBares.load (new URLRequest("negocio/bares.swf"));

    loaderBares.contentLoaderInfo.addEventListener (Event.COMPLETE, s loadBare);

    function loadBares(event:Event) {}

    baresClip = event.target.content;

    baresClip.x =-474;

    baresClip.y = - 135;

    addChild (baresClip);

    baresClip.over1.receta1.addEventListener (MouseEvent.CLICK, prueba);

    function prueba(event:MouseEvent):void {}

    gotoAndStop ("receta1");

    removeChild (baresClip); / * Here is work * /.

    }

    MovieClip (root).mc_negocio.menu_negocio.btn_botanas.addEventListener (ouseEvent.CLICK, goToBotanas M);

    function goToBotanas(event:MouseEvent):void

    {

    removeChild (baresClip);   / * Here is not work * /.

    gotoAndPlay ("botanas");

    }

  • Event.Target movieclip

    I have a movieclip named button1 containing dynamic text named txt inside.

    My problem is that if I try

    if(Event.Target==Button1)

    {

    ...

    }

    She won't recognize the click when it dosent meet the dynamic textfield

    So I have to do:

    If (event.target is button1| Event.Target == Button1.txt)

    {

    ...

    }

    do you have an explanation of why I can not only check whether the target is button1? because the textfield object is inside the key, so normally it is considered to be a part of it

    because the movieclip button1 is the container

    Use currentTarget instead of the target.

    The difference between them is that this target is the object having distributed the event, while currentTarget is the object with the listener entrusted to him.  Sometimes they are the same object, but the target can often be another object in the object that is the listener who are entrusted to him.

    If you want an explanation / with examples...

    http://www.wastedpotential.com/?p=10

  • Event.Target confusion?

    I try to reuse the function using event.target, but after research and try different method online, I found event.target belongs to the most difficult to understand part...

    can someone explain to me what is the difference between (the example to the right indicating where I meet these code):

    1.event.target

    2.event.target.name

    3.event.currentTarget / / e.g. event.currentTarget.addChild (myMc);

    4.event.currentTarget.name / / e.g. var newswf:URLRequest = new URLRequest (event.target.name + ".swf");

    5 MovieClip (event.currentTarget) / / e.g. addChild (MovieClip (event.currentTarget));

    I consider that the main culprit for the compiler and whoever decided to dumb it upward.  If you try what suggest you and manually place circles on the scene, you will probably see the same mistake to shut up... even if the circle is a resource of the library which is defined as a symbol of the MovieClip that the compiler must be able to refer to.

  • instances of addChild does not recognize event.target.name?

    I have a button that has been added to the stage using addChild when the page load, the button is supposed to be removed using removeChild and redirect in its specific page using event.target.name... somehow, I got this error:

    Error #2044: Unmanaged by the IOErrorEvent:. Text = Error #2035: URL not found.

    I try to replace this line.

    var newswf:URLRequest = new URLRequest (".") ("/ swf /" + event.target.name + ".swf");

    with that,.

    var newswf:URLRequest = new URLRequest("./swfs/about.swf");

    and everything works fine, but I don't want that since I want to dynamically load and use less code... is there a solution to do this, thanks for the help

    my code as below:

    //////////////////////////////////////////////////////////

    var subject: About = new About().

    about.x = 300;

    about.y = 200;

    addChild (about);

    function btnClick2(event:MouseEvent):void {}

    removeChild (about);

    removeChild (loader);

    var newswf:URLRequest = new URLRequest (".") ("/ swf /" + event.target.name + ".swf");

    Loader.Load (newswf);

    Loader.x = XPos;

    Loader.y = YPos;

    addChild (loader);

    SoundMixer.stopAll ();

    to stop all the background sound when click

    }

    about.addEventListener (MouseEvent.CLICK, btnClick2);

    //////////////////////////////////////////////////////////////////////////

    I missed the part where you create dynamically on the Forum...  You must assign a name because the name property is not the same as the var with that you instantiated...

    var subject: About = new About().

    about. Name = "a connection";

  • How to check the event.target type in the "if" statement

    Hi, I have "roll-over" event listener and I wish that only works with music videos (without textfields etc.). I would write something like this:

    if(Event.Target == MovieClip) {do something}

    else {do something}

    This does not work properly.

    How to check the event.target type in the "if"?

    Thanks for any help.

    :

    If (getQualifiedClassName (Event.Target) == 'flash. display::MovieClip') {do something}

    else {do something}

    .

  • Pages.gotoAndStop (event.target.name);

    I followed this tutorial

    http://www.YouTube.com/watch?v=AhsSQGcm46E

    I make a Web site with buttons but when I test the scene it scrolls and loops of each content page.

    This is the code I have for action script


    var myMenuArray = [which, video, photography, Web design];
    for each {(var btn in myMenuArray)

    btn.addEventListener (MouseEvent.CLICK, onBtnClick);

    }
    function onBtnClick(event:MouseEvent):void {}


    Pages.gotoAndStop (event.target.name);
    }

    When I test the scene, he said.

    1061: call to a Stop method maybe not defined through a reference with static type fl.motion:AnimatorFactory.

    Any ideas?

    The error would give the impression that Pages is not an object with a timeline

Maybe you are looking for

  • How can I reset the arrows to go back and forward

    The arrows in the upper-left corner of the screen that allows you to return to the previous screen and pass on to another screen, have disappeared. How can I restore them?

  • HP Photosmart M415 digital camera

    My digital camera makes strange photos that appear to be cut in half with blue stuff in them. Is it possible to keep my camera to do this PS how can I change my name to g-mister, my friend set up the account and I really don't like the name, he chose

  • Need drivers for Satellite 1110 (PS111E-0039Y)

    Hello I have this model laptop, which is quite old now, but I can't seem to find the drivers for it on the Toshiba site, maybe the drivers for my model come under another name? If anyone can help me it would be much appreciated.

  • Compaq cq60 pescario does not turn on please can any one help?

    Hello im new and not happy that my laptop doesn't boot, I was on the game world of warcraft and everything was going well then suddenly screen erased with no respons, I couldn't go back to windows simply nothing, if you press the stop button to stop.

  • 'Invalid WEP key' error on 7410 All in one wireless set in place

    My 7410 has been connected wireless for more than a year, but I just installed a new router (Linksys N600) and cannot get the connection Wireless upward.  All other wireless devices are connected to the new router.  Using WPA2-PSK [AES] security on t