how 'this.' reference in AS3 functions?

In the days of good old AS2, it was pretty easy to make a simple function that when mouse over:

this.gotoAndPlay (2);

For a lot of different buttons that I wanted to do the same thing on mouse.

Now, with the EventListeners being at stake, which obviously doesn't work as 'this' will reference my main movie.  So, how do I, in code if I had 10 movieclips and wanted CEC to gotoAndPlay (2) on their rolling individual would do this job without writing 10 different functions named each of them individually?

Button1.addEventListener (MouseEvent.ROLL_OVER, onOver1);

function onOver1(event:MouseEvent):void
{
Button1.gotoAndPlay (2);
}

Button2.addEventListener (MouseEvent.ROLL_OVER, onOver2);

function onOver2(event:MouseEvent):void
{
Button2.gotoAndPlay (2);
}

etc... that can't be good.

"This" refers to the timeline, as it is written.  If you have written your listeners in the scenario of the (internal) button, you can use 'this' to tell them where to go (assuming that they are used as buttons from movieclips)

this.addEventListener (MouseEvent.ROLL_OVER, onOver1);

function onOver1(event:MouseEvent):void
{
this.gotoAndPlay (2);
}

Otherwise, if you write them in the timeline containing the buttons, then you can write all the listener/function separated at sunset (as you started earlier), or assign them all event listeners individually and have them share a function...

Button1.addEventListener (MouseEvent.ROLL_OVER, sharedHandler);

Button2.addEventListener (MouseEvent.ROLL_OVER, sharedHandler);

function sharedHandler(evt:MouseEvent):void {}

event.currentTarget.gotoAndPlay (2);

}

(no idea why this is indented, but I can't cancel)

Tags: Adobe Animate

Similar Questions

  • My iPhone 6 s Plus the function to rotate the screen how this return

    My iPhone only more 6 used to rotate the screen, it is more the fact how this function returns

    Swipe up from the bottom of the screen to bring up the control center. Then press the icon that looks like a padlock inside a circular arrow. https://support.Apple.com/en-us/HT204547

    -AJ

  • How to reference functions JavaScript stored in a script on a different page object?

    Hello

    I have a form that contains 2 pages. I have a bunch of JavaScript functions in script on page 1 objects. How can I access these functions on page 2?

    I tried the following, but none of it works:

    Form1.Page2 #variables [0]. TestScript.doThisNow ();

    Form1.Page2.variables [0]. TestScript.doThisNow ();

    Form1.Page2.variables.TestScript.doThisNow ();

    Help, please.

    Hello

    Way the easiest would be to drag the script object to be under the node root (form1). On the two pages would be would be able to refer to the function of:

    testScript.doThisNow();
    

    If you leave the object of script as page 1, then page 2, the following should work:

    page1.testScript.doThisNow();
    

    Hope that helps,

    Niall

  • How to reference cells other cells in a different worksheet?

    OK, so here is my problem. On sheet 1, I have a table similar to the one below. It contains thousands of names, telephone numbers, emails, etc...

    Name E-mail
    John [email protected]
    Mary [email protected]
    Roger [email protected]

    On the sheet 2 to my table looks like this:

    Name E-mail

    I goal is to have the automatic filling of electronic mail, if I had to type a name on sheet 1.  How to do this, and it is even possible.

    Thanks for any advice, because I am an extreme novice.

    Hi Joey,

    I created the tables on the same sheet. You can cut and paste the 'Customer' table to another worksheet.

    Formula in B2 of the 'customer '.

    = VLOOKUP($a2,contacts::$A:$D,2,0)

    Formula C2 (if you wish)

    = VLOOKUP($a2,contacts::$A:$D,3,0)

    Formula in D2

    = VLOOKUP($a2,contacts::$A:$D,4,0)

    Type = in any cell to start the formula and bring up the browser functions. Type the VLOOKUP function to see how to use the VLOOKUP function:

    The VLOOKUP function returns a value from a collection of columns using the values in the left column to choose a line and column number to select a column in the same row.

    • VLOOKUP (for research, range of columns, column back, closing-match)
      • search for: the value to search for. Research-valuecan contain any value.
      • columns-range: a collection of cells. range columns must contain a reference to a single range of cells, which can contain any values.
      • return-column: a numeric value that specifies the number of the column of the cell where to return the value. The left in the collection column is column 1.
      • closing-match: a modal value that determines if an exact match is required.
        • close match (TRUE, 1, or omitted): If there is no exact match, select the line with the largest value of the left column that is less than or equal to the search value. If you use a close match, you cannot use wildcards in the search for.
        • exact match (FALSE or 0): If there is no exact match, returns an error. If you use the exact match, you can use wildcards in the search to.

    Notes

    • VLOOKUP compares a value to search for values in the column on the left of a specified collection. If an exact match is required, the line containing the largest value of the left column that is less than or equal to the search value is selected. Then, the value of the specified column in the same row is returned by the function. If an exact match is required, and none of the left column values match the value of the research, the function returns an error.

    Kind regards

    Ian.

  • AS3 - function passed as an argument brought bad when it is called

    Hi all

    I'm new to flex. I tried this: http://seancode.blogspot.com/2008/07/flex-injection-passing-function-to.html

    This message essentially has a MyBox component that gets a function as an argument and calls the function on a button click.

    There another component main , which has defined a function func and MyBox as a child and gives the MyBox service.

    The problem is: func accesses the properties of the hand. So when he gets called it is supposed to work at hand , but in my application is running in the scope of MyBox and give a reference to property not found error.

    I read that in AS2, mx.utils.Delegate was used to specify the scope in which a function must run. This has been used to define event listeners. And AS3 is supposed to do this automatically - magic closures/methods. I had no problem setting of event listeners, and they run in the correct scope...

    Please tell me where I'm wrong... There is no delegate to work around this problem now. And I couldn't find anyone else facing this problem in AS3.

    Thanks in advance...

    Hello

    The problem is that you use a function inline instead of a bound method. In this case, when you use an inline function, this function will be the scope of the caller (following the example of the appellant will be to the MyBox component) and not to the scope of the creator (hand). You can find more information about the scopes of service here: http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_21.html

    If you do not need the Bindable part, you can work around the problem by using a method/function related:

    (using the same example you provided)

    private function backToViewZero():void {
         viewStack.selectedChild = viewZero
    }
    

    Another way (without throwing the binding mechanism) is to use the method of the function call and specify the thisArg as being the parent (main).

    
    
  • [AS] IDCS4 - how to reference rectangle tagged in layer

    Hello

    What I'm trying to do is access a tagged rectangle called IMAGE, with a title of IMAGE script in a group on a locked layer and replace the contents of rectangles with a new image and did not have much success.

    When I unlock the layer and no collective group, I can then access the rectangle labeled
    with the code below.
    (the code was cobbled together from here http://www.macosxautomation.com/applescript/datapublish/index.html( )

    Could someone please show me how to reference a rectangle labeled on a layer that is locked in a prayer group, if I need to unlock the layer, then that's fine.

    Tell application "Adobe InDesign CS4"
    According to the active document
    value of the rectangle_list each rectangle of each spread ¬
    where the label is not "" and the type of content is graphic
    If the rectangle_list is {}, then
    error "there no rectangles tagged image."
    end if
    If the rectangle_list class is not in the list then
    define the rectangle_list to the rectangle_list as list
    end if
    tell the end
    Repeat with i from 1 to the count of the rectangle_list
    Try
    error_indicator Set 1
    the value this_rectangle to article i of the rectangle_list
    the value this_tag to the name of this_rectangle

    value this_image to 'PATH to IMAGE' as an alias - tests

    error_indicator Set of 2
    say this_rectangle
    the value this_image to set this_image
    If the class of this_image is the defined list then this_image to article 1 of the this_image
    adjustment, given the content in the frame
    the value image_h to the horizontal scale this_image
    the value of the image_v to the vertical scale of the this_image
    If the image_v is greater than or equal to image_h then
    Set the horizontal scale this_image to image_v
    on the other
    Set the vertical scale this_image to image_h
    end if
    Insert the contents of given Center
    tell the end
    on error error_message
    If the error_indicator is 1 then
    the error_message value function "Image" "& this_tag & ¬»
    ""is not found in the database. »
    end if
    activate
    beep
    display the default button on dialog error_message buttons {"Cancel", "Continue"} 2
    try to end
    end repeat
    tell the end

    see you soon
    KeV

    Something like this should help you get started:

    Tell application "Adobe InDesign CS4"

    Tell document 1

    Set theRects to every element of all page elements whose class is rectangle and the label is 'IMAGE '.

    Repeat with i from 1 to the number of theRects

    oneRect the value of item i of theRects

    -unlock the layer if necessary

    If it is locked layer of oneRect point is true then

    lockFlag set to true

    locked set of layer of point of oneRect to false

    on the other

    Set lockFlag false

    end if

    place the value on oneRect this_image this_image

    -do your stuff to the image

    If lockFlag is set to true then together closed of true point of oneRect layer -relock the layer

    end repeat

    tell the end

    tell the end

  • How to reference clips video parent/child with event handlers?

    I wonder how to reference correctly clips video parent/child, creating event handlers?

    I have a button in a movie clip, which is located in a clip.

    That's what my manager looks like now:

    This. DropMenus.DMSeats.ButtonSeats.addEventListener ("click", SeatsOver);

    The button instance name is ButtonSeats

    It is, I get this:

    TypeError: Error #1009: cannot access a property or method of a null object reference.

    Any idea where I could go wrong?

    Also, if I were to move the listener to drain directly into the clip where the button, how could I make reference to the parent/parent timeline (the main timeline)? Am I right to understand that .This refers only to the current clip?

    Thank you!

    You can place your code in a function that is called when your objects exist.

  • How can I create a function using variables TestStand and call from Meadow step Expression?

    In one sequence, I have dozens of prior Expressions, which are almost the same thing, like this...

    Locals.tagID = (Parameters.singlePhaseEnabled? ('L': "D") & Str (Locals.phase) & "006".

    .. and the only thing different is this three-digit string in the end ("006" may vary). How can I write a function that I can call from Meadow step Expression then it should look like this? ...

    Locals.tagID = MyNewFunction("006")

    You can not write custom expressions for commands.

    That being said, there are two options:

    • Create a sous-suite with a single step. Use a setting of the sequence as "function parameter.

    • Create a step type custom including a lower level module that implements the function. Add a step edit to allow the user to the steptype graciously change the setting.

    • Store the variable setting in a local global variable / file and change the value in each step. This will, at least, keep the same 'function' for each step.

    Norbert

  • Can I use data value references with a functional overall?

    Can I use data value references with a functional global?  I am trying, but it causes problems:  I run the attached VI with "new DVR" selected.  Then I run it again with "return array" and I get the error 1556: "The reference is invalid. This error might occur because the reference has been deleted."  It seems to have forgotten the DVR, but I thought it should be stored in the shift register.
    
    Another odd thing:  In my VI, if I try to connect the wire shown in "something strange", then the type changes (from U16 array to DBL), i.e. it doesn't recognize the type referenced by the DVR.
    
    I want to pass a very large 4-dimensional array between parallel loops with a functional global.  To avoid memory problems, I want to use a DVR and in-place element structures.  If that's not allowed in Labview, I will try passing it through a user event or notifier.  Any problems with those alternatives?
    
    Thanks.
    

    I received a response from an engineer applications OR on this subject, and it seems that it is perhaps a problem with Labview.  They are working on it, so I'll go ahead and close this discussion.

    Thanks for the help,

    Allan

  • How to use the node function call library for a function in the dll with the data SUB type

    Hi all

    I would ask for your kind help

    I am facing a problem with the call library node.

    I have a C++ (stdcall) function, which has Sub as data type

    XXXX error code (hwnd, lid, getValue, * Sub data1, * Sub data2)

    data1 and data2 types are constantly changing based on the value of 'getValue '.

    Mainly I can use the call library node several times and adapt each node according to the types of data data1, data2 and extract the values and use in the code. Here is no question. Real question is:

    My question:

    How can I use a node of library time call and make a case according to the 'getvalue', who will control the data1, data2 data type. Here I really seeking solutions.

    My tests:

    I used varaints as entry to the libray call node of the data1, data2 and selected parameters in the call libraby node as "Adapt to type. Here labview just crashed.

    I appreciate your suggestions to feedbackand.

    Thank you

    Karine

    You must allocate enough space for data1 and data2, and then pass a pointer to this space. An easy way to do this is the function to initialize table. Set the U8 type and size for the number of bytes required. Pass this array to the function as a pointer of table data.

    After the function call returns, you need to extract the data in the table. You can do it manually, but a simple approach is to use the array of bytes to a string. Then, in a housing structure, use Unflatten chain to convert the string to the correct data type. This method also converts the "endianness" which will be probably necessary; Be sure to only set all entries for unflatten correctly.

  • How to reference an object in a cluster?

    I have a cluster that contains a few digital paintings and several Boolean.  I would like to connect a single reference for the entire cluster to a Subvi and have the Subvi individually controll Boolean values.  How this is done?  I worked with specfic opbject references but I don't know how to work with references within the groups.  I'm under the impression that this has something to do with the strict property nodes but I'm stuck on his approach.  I'm using Win - XP and LV 2009 SP1.

    Thank you

    Dave

    dj143 wrote:

    I have a cluster that contains a few digital paintings and several Boolean.  I would like to connect a single reference for the entire cluster to a Subvi and have the Subvi individually controll Boolean values.  How this is done?  I worked with specfic opbject references but I don't know how to work with references within the groups.  I'm under the impression that this has something to do with the strict property nodes but I'm stuck on his approach.  I'm using Win - XP and LV 2009 SP1.

    Thank you

    Dave

    I posted a nugget on the subject here.

    You don't understand everything in this nugget. I wrote it to be entertaining at all levels of experience LV if just take what you need and leave the rest of the latter.

    Ben

  • How to activate the Sleep function to put the computer to sleep if a program is open?

    I have Windows Vista basic on a desktop Dell 530.  I found that if I have a program or application running (such as I-tunes or windows media player) then the Sleep function will not put the computer to sleep.  How to activate the Sleep function to replace these programs and put the computer to sleep?

    Note: This is how it was with windows XP, the Sleep function would put the computer to sleep no matter what was running, he was reliable, if you left the computer and I forgot that you had something running.

    Thanks for your help.

    Hi kevino4130,

    If you disable sharing on your computer (not only the power settings) of media, it should allow him to enter the mode 'sleep'.

    See if that does not solve your problem and let us know.

    Dave D

    Dave D
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How to associate the key function on thinkpad T61p

    How to associate the key function on thinkpad__Fn Key__Hibernate mapping of keys for Lenovo Thinkpads

    How to map the keys "Fn F4" on my Thinkpad T61p to keyboard MS Wireless Comfort Keyboard 5000 to Hibernate?

    Your Thinkpad keyboard doesn't have access to the MS Wireless Comfort Keyboard 5000 drivers, firmware and add the functioon of Microsoft for the Thinkpad (and vice versa).

    Here is an article on how to remap the keys in Vista (with a link to a program that will help): http://www.howtogeek.com/howto/windows-vista/map-any-key-to-any-key-on-windows-xp-vista/. I don't know if this works with the function keys, but it's worth a try.

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • How can I disable the function on my v5 acer inspire?

    OT : How can I disable the function on my v5 acer inspire where when you click on the mouse somehow your whole page disappears? It wasn't like this in one of my computers before windows 8.

    How can I activate noff functionality of mouse that causes your entire page to disappear when you click on it the wrong way .i have an acer v5 inspire.please help. Ive had a lot of computers, but this feature never appeared until the windows 8

    Please help its driving me crazy

    James m

    Hello

    Thanks for posting your query on the Microsoft Community.

    According to the description, I understand that you are facing problems with your mouse.

    I suggest you to refer to suggestions of Mohammad_Imran replied on 5 April 2013 and check if that helps.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_8-TMS/how-to-disable-swipe-gesture-on-touchpad/77c9e8c5-0C5A-4527-a60e-81e8168aec52

    You can also check:

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_8-TMS/how-do-i-change-the-settings-for-my-Windows-8/a0349e35-B090-42fb-A586-feac551a0100

    Hope this information helps. Please let us know if you need any other help with Windows in the future. We will be happy to help you.

  • How to use the @accum function in the calculation script

    Dear all.

    I'm new in essbase - calculation script so don't know how to use the @accum function.

    I want the aggregation value of child to parent

    Hierarchy

    Product

    100 > Storage Dimensions marked as stored (marked as intentionally as I want to calculate the value using the calculation script)

    100. 10 (+)

    100-20 (+)

    100-30 (+)

    I'm trying calculation Script

    100 = @Accum (@children("100"), jan: Feb);

    It works when I use below

    100 = @Accum("100-10",Jan:Feb);

    Error:-number of Dimensions [1] does not match number of gen/lev [3] office [@Dim]

    Don't know how I can roll up to an aggregate value of all the members of the child to the parent.

    Error.PNGhierachy.PNG

    you do this more difficult it must be. If you want to accumulate up to 100 then you could just make your calc

    '100 '.

    but that would be only 100, to make the OU any dimension would

    AGG (Product);

    Or better yet

    AGG (Product, Market);

Maybe you are looking for