Calling a Function in a Component

Hi I know this is simple but I can not get this to work I ahve looked for example but come uo with nothing
I want to call a function in a  Component
I created  acompoinent based on a label
<?xml version="1.0" encoding="utf-8"?><mx:Label 
xmlns:mx="http://www.adobe.com/2006/mxml"> 
   <mx:Script>
     <![CDATA[
       public var mp3:String; 
     private var soundChannel:SoundChannel; 
// this function will load and play the sound 
    public function playSound():void{ 
       var urlRequest:URLRequest = new URLRequest(mp3);  
      var sound:Sound = new Sound();     sound.load(urlRequest);
// will stop sound of no device is found  
     if(soundChannel != null ) {         soundChannel.stop();
     soundChannel = sound.play();
// this function stops the sound from playing, this need tos work on the sound channel  
    private function stopSound():void
     {        soundChannel.stop();
     ]]>
  </mx:Script>
</mx:Label>
calling looks like  
<?xml version="1.0" encoding="utf-8"?><mx:Application 
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:uofs="uofs.*" > 
<uofs:ulable text="hellow" id="b21" x="200" y="300" mp3="jazz.mp3" click="playSound()" /> 
 </mx:Application>
also how wolud you pass a string in the click
click="playSound(jazz.mp3)"  or click="playSound("jazz.mp3")"
do not work  

ok, thanks i got it
becouse is called the instance of the component id="b21"  the the click ="b21.playsound()"
ie use the function playSound in the instance of the compinent b21
still does not work
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at uofs::ulable/playSound()[C:\Documents and Settings\Administrator\My Documents\Flex Builder 3\CompinentTest\src\uofs\ulable.mxml:17]
at CompinentTest/__b21_click()[C:\Documents and Settings\Administrator\My Documents\Flex Builder 3\CompinentTest\src\CompinentTest.mxml:4]
but that is something diffrent that I will look at next
thanks for the help

Similar Messages

  • Unexplained Error #1009 when calling a function in a component.

    I created a component that allows you to display a song
    listing.
    I need to create various instances using it's constructor,
    then add them to a main scrollbar control.
    Before putting it in a loop, I wanted to make sure I could
    add a single instance, with this code:
    var NewListing:mediaUnit = new mediaUnit();
    NewListing.setArtist("In Flames");
    NewListing.setAlbum("Come Clarity");
    NewListing.addSong(1,"Take This Life");
    mediaLib.addObject(NewListing);
    Compiled, ran, got this:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    at mediaUnit/addSong()
    at MC3_PORT_fla::MainTimeline/MC3_PORT_fla::frame36()
    Okay, maybe it's the code of addSong, right? So I commented
    it out so it's basically:
    public function addSong(id:int,song:*):int {
    return 0;
    Still gives the error.
    Why do setArtist and setAlbum, being in the SAME exact scope,
    not give this error? It just doesn't make sense to me.

    Alright, I got it pinpointed. addSong calls
    var movie:MovieClip = new units.mediaUnit.songItem();
    Which Flash seems to consiter null.
    Not like anyones going to bother reading this, everyone on
    this forum tends to be lazy as hell, but anyone willing to help,
    I'd appreciate it.

  • Standard Component in CRM that will call RFC Function Module

    HI all,
    Is there any Standard Component in CRM that will call RFC Function Module from ECC and that called RFC FM should Fetch the data from ECC.

    You can call RFC from different places, like programs, function modules, web dynpros, classes...
    So you just have to have appropriate RFC on ERP side and call it from CRM side. To call it you use the following statement...
          CALL FUNCTION 'YOUR RFC FUNCTION'
            DESTINATION i_dest "name of server
            EXPORTING
              your export parameters
            IMPORTING
              your import parameters
    Regards.

  • Is it possible to call a function in a parent component from a child component in Flex 3?

    This is probably a very basic question but have been wondering this for a while.
    I need to call a function located in a parent component and make the call from its child component in Flex 3. Is there a way to access functions in a parent component from the child component? I know I can dispatch an event in the child and add a listener in the parent to call the function, but just wanted to know if could also directly call a parent function from a child (similar to how you can call a function in the main mxml file using Application.application). Thanks

    There are no performance issues, but it is ok if you are using the child component in only one class. Suppose if you want to use the same component as a child to some bunch of parents then i would do like the following
    public interface IParentImplementation{
         function callParentMethod();
    and the parent class should implement this 'IParentImplementation'
    usually like the following line
    public class parentClass extends Canvas implements IParentImplementation{
              public function callParentMethod():void{
         //code
    in the child  you should do something like this.
    (this.parent as IParentImplementation).callParentMethod();
    Here using the Interfaces, we re decoupling the parent and the child
    If this post answers your question or helps, please mark it as such.

  • Calling a function from a custom component

    I got source files from another company that did a flex project for us before I started working here.  They have custom compenents (mxml files) that they are currently calling public functions in, but when I add a new public function to the mxml component, it won't allow me to call that function.  It tells me it can't access a property of a method of a null object reference... but it still calls the function that was there before I started working with the file..
    I cleaned the project, and did a "build all" but can't figure out why it won't allow me to create new public functions to call.... can anyone tell me why?

    I have the partsLocator_panel in the mxml
    not sure what "new" is with that... first time working with custom components, but it looks like your just working with custom classes in AS3...
    <mx:Panel 
    width="100%" height="100%" layout="absolute" styleName="DashboardPanel" title="PARTS LOCATER" backgroundAlpha=".6" id="partsLocater_panel">
    <mx:Image x="10" y="38" source="assets/icons/gear.png"/>  
    <mx:Image x="10" y="63" source="assets/icons/gear.png"/>  
    <mx:Image x="10" y="89" source="assets/icons/gear.png"/>  
    <mx:Label x="40" y="39" text="Block 30" width="227" styleName="DashboardText" click="openParts()"/>  
    <mx:Label x="40" y="63" text="Block 40" width="227" styleName="DashboardText" color="#9D9D9D"/>  
    <mx:Label x="40" y="88" text="Block 50" width="227" styleName="DashboardText" color="#9D9D9D"/>  
    </mx:Panel>

  • Calling a function every time a canvas component is viewed

    hi all,
    i have a function in a canvas component which i need to call
    every time i view that component. is there a way to generate an
    event each time a i view that component.. 'show' works only when
    the component turns from invisble to visible..
    thanx in advance

    the code is
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns:custom=".*"
    backgroundColor="#ccccccc" width="100%" height="100%"
    creationComplete="findCreatePermission(); addListeners();"
    show="findCreatePermission();"
    >
    <mx:Script>
    <![CDATA[
    private function findCreatePermission():void
    if(myPermission & 2)
    createPermission = true;
    else
    createPermission = false;
    ]]>
    </mx:Script>
    <mx:ViewStack id="mainStack" width="100%" height="100%"
    >
    <mx:Canvas id="mainCanvas"
    show="createPatient.visible=false;patientList.visible=true;sample2();">
    <mx:VBox width="100%" height="100%">
    <custom:patientInfo id="patientList" label="Room search"
    backgroundColor="#ECECD9" width="100%" height="100%"
    visible="true" />
    <mx:HBox horizontalAlign="center" width="100%" >
    <mx:Button id="create" label="Create New Patient"
    height="30" styleName="buttonBlue"
    enabled="{createPermission}"
    click="{mainStack.selectedChild=createPatient;}" />
    </mx:HBox>
    </mx:VBox>
    </mx:Canvas>
    <custom:create_patient id="createPatient" label="Create
    Patient" width="100%" backgroundColor="#ECECD9" visible="false"
    returnStack="{mainStack}" returnCanvas="{mainCanvas}"
    show="patientList.visible=false;createPatient.visible=true;"/>
    </mx:ViewStack>
    </mx:Canvas>
    i need to call findcreatePermission() every tme this
    component is viewed

  • How I can call controller's functions from another component?

    Hi again!
    I make a few web Dynpro components, for example first for user-data processing, second - for project-data processing. In the controller of 1-st controller there is a function getUserById(). In the controller of 2-nd component I need such function. And I don't want to make a dublicate for this function in the controller of 2-nd component. Is there a way to call function in one component from another?

    Hi,
         Yes, you can reuse the component. There are two basic types of component communication. 1. Intra Component communication 2.Inter Component communication.
    1. Intra Component  communication: The two components must be in same DC(project).
    Procedure:Say there are C1,C2 components in a DC.
    Open C2, Open interface controller, create a similar (_parameters and return type_) method to the method C2. Call C2's method in this Interface method.   
    Open C1, select and right click  Used Web Dynpro Components -> Add Used Component. In the wizard, you can browse and select the C2 component,and enter a name to the usage. Then the usage of the interface <b>must </b>be added in properties required controllers of a view/component controller.
    Now we can use the method that is available in the C1 interface controller.     
    You must define method before declaring usage
    <b>2.Inter Component  communication:</b> The two components are in different DCs
    Open DC metadata of C2. Right click on Public part-> create new Public Part.Enter name-> Next -> Select entity type as Web Dynpro Component in wizard,in Select Entities  select the component ,Finish.
    A structure for public part is created.
    Open C1, Open DC metadata of C1. Right click on Used Dcs-> AddUsed DC. Browse to C2's public part.
    Select Finish.
    regards,
    Siva
    Edited by: Siva Rama Krushna on Dec 19, 2007 10:07 AM

  • Calling functions in a component before the component UI is used?

    I know this has been asked before, in fact I'm sure I've had this problem and resolved it in the past. However, I can't recall the solution off hand.
    I have a component, which contains a publich function and data. The component has a UI which can be loaded by another function call. Loading the UI works fine, and after its been loaded (and close) calling the first function works fine. However, before hte UI has been loaded calling the function does nothing.
    Any thoughts?

    Load the UI earlier but set the visible and includeInLayout properties to the component to false.
    Then in the function call that used to load the UI, just set those properties to true.
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services

  • Call Function From MXML Component

    I am using MXML to create components that I use within my
    application. I have one MXML file that contains a list with a
    custom itemRenderer that is in another MXML file. I have an
    actionscript file with a function that I want to call from the
    itemRenderer.
    If I call the function from my main application, everything
    works fine. If I try to call it from one of the other MXML files, I
    get a 1180 Call to a possibly undefined function error.
    Is there a special way that I need to use to call the
    function?
    The main MXML file is in the root directory, the actionscript
    file is in a folder called functions, and the MXML files are in a
    folder called components.
    Thank you for any help.

    I was able to figure out my problem. It was just a simple
    typo of including the wrong file in a Script tag. However, this
    caused more issues and I ended up having to rewrite a large section
    of code to get everything working.
    Thank you for your help.

  • Upload data from excel with vba by calling a function module

    Hello all,
    i have a problem with the function module "ALSM_EXCEL_TO_INTERNAL_TABLE". I will call this function module with vba to load data from excel to sap with a Buttonclick. I have copied this function module and set it remotable. But i can´t call it from excel.
    Can you give me some tips how can i
    upload data from excel with vba by click a button.
    The problem seems the function: call method cl_gui_frontend_services=>clipboard_import in the function module, because when i comment this function call the vba-call is true but no results. 
    How can I call the function module correct with vba?
    Thanks a lot for your tips!!!!
    Chris
    Message was edited by:
            Christoph Kirschner

    HI
    Uploading data directly from Excel file format
    * Upload data direct from excel.xls file to SAP
    REPORT ZEXCELUPLOAD.
    PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
                begcol TYPE i DEFAULT 1 NO-DISPLAY,
                begrow TYPE i DEFAULT 1 NO-DISPLAY,
                endcol TYPE i DEFAULT 100 NO-DISPLAY,
                endrow TYPE i DEFAULT 32000 NO-DISPLAY.
    * Tick don't append header
    PARAMETERS: kzheader AS CHECKBOX.
    DATA: BEGIN OF intern OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern.
    DATA: BEGIN OF intern1 OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern1.
    DATA: BEGIN OF t_col OCCURS 0,
           col LIKE alsmex_tabline-col,
           size TYPE i.
    DATA: END OF t_col.
    DATA: zwlen TYPE i,
          zwlines TYPE i.
    DATA: BEGIN OF fieldnames OCCURS 3,
            title(60),
            table(6),
            field(10),
            kz(1),
          END OF fieldnames.
    * No of columns
    DATA: BEGIN OF data_tab OCCURS 0,
           value_0001(50),
           value_0002(50),
           value_0003(50),
           value_0004(50),
           value_0005(50),
           value_0006(50),
           value_0007(50),
           value_0008(50),
           value_0009(50),
           value_0010(50),
           value_0011(50),
           value_0012(50),
           value_0013(50),
           value_0014(50),
           value_0015(50),
           value_0016(50),
           value_0017(50),
           value_0018(50),
           value_0019(50),
           value_0020(50),
           value_0021(50),
           value_0022(50),
           value_0023(50),
           value_0024(50),
           value_0025(50),
           value_0026(50),
           value_0027(50),
           value_0028(50),
           value_0029(50),
           value_0030(50),
           value_0031(50),
           value_0032(50),
           value_0033(50),
           value_0034(50),
           value_0035(50),
           value_0036(50),
           value_0037(50),
           value_0038(50),
           value_0039(50),
           value_0040(50),
           value_0041(50),
           value_0042(50),
           value_0043(50),
           value_0044(50),
           value_0045(50),
           value_0046(50),
           value_0047(50),
           value_0048(50),
           value_0049(50),
           value_0050(50),
           value_0051(50),
           value_0052(50),
           value_0053(50),
           value_0054(50),
           value_0055(50),
           value_0056(50),
           value_0057(50),
           value_0058(50),
           value_0059(50),
           value_0060(50),
           value_0061(50),
           value_0062(50),
           value_0063(50),
           value_0064(50),
           value_0065(50),
           value_0066(50),
           value_0067(50),
           value_0068(50),
           value_0069(50),
           value_0070(50),
           value_0071(50),
           value_0072(50),
           value_0073(50),
           value_0074(50),
           value_0075(50),
           value_0076(50),
           value_0077(50),
           value_0078(50),
           value_0079(50),
           value_0080(50),
           value_0081(50),
           value_0082(50),
           value_0083(50),
           value_0084(50),
           value_0085(50),
           value_0086(50),
           value_0087(50),
           value_0088(50),
           value_0089(50),
           value_0090(50),
           value_0091(50),
           value_0092(50),
           value_0093(50),
           value_0094(50),
           value_0095(50),
           value_0096(50),
           value_0097(50),
           value_0098(50),
           value_0099(50),
           value_0100(50).
    DATA: END OF data_tab.
    DATA: tind(4) TYPE n.
    DATA: zwfeld(19).
    FIELD-SYMBOLS: <fs1>.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                mask      = '*.xls'
                static    = 'X'
           CHANGING
                file_name = filename.
    START-OF-SELECTION.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                filename                = filename
                i_begin_col             = begcol
                i_begin_row             = begrow
                i_end_col               = endcol
                i_end_row               = endrow
           TABLES
                intern                  = intern
           EXCEPTIONS
                inconsistent_parameters = 1
                upload_ole              = 2
                OTHERS                  = 3.
      IF sy-subrc <> 0.
        WRITE:/ 'Upload Error ', SY-SUBRC.
      ENDIF.
    END-OF-SELECTION.
      LOOP AT intern.
        intern1 = intern.
        CLEAR intern1-row.
        APPEND intern1.
      ENDLOOP.
      SORT intern1 BY col.
      LOOP AT intern1.
        AT NEW col.
          t_col-col = intern1-col.
          APPEND t_col.
        ENDAT.
        zwlen = strlen( intern1-value ).
        READ TABLE t_col WITH KEY col = intern1-col.
        IF sy-subrc EQ 0.
          IF zwlen > t_col-size.
            t_col-size = zwlen.
    *                          Internal Table, Current Row Index
            MODIFY t_col INDEX sy-tabix.
          ENDIF.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE t_col LINES zwlines.
      SORT intern BY row col.
      IF kzheader = 'X'.
        LOOP AT intern.
          fieldnames-title = intern-value.
          APPEND fieldnames.
          AT END OF row.
            EXIT.
          ENDAT.
        ENDLOOP.
      ELSE.
        DO zwlines TIMES.
          WRITE sy-index TO fieldnames-title.
          APPEND fieldnames.
        ENDDO.
      ENDIF.
      SORT intern BY row col.
      LOOP AT intern.
        IF kzheader = 'X'
        AND intern-row = 1.
          CONTINUE.
        ENDIF.
        tind = intern-col.
        CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
        ASSIGN (zwfeld) TO <fs1>.
        <fs1> = intern-value.
        AT END OF row.
          APPEND data_tab.
          CLEAR data_tab.
        ENDAT.
      ENDLOOP.
      CALL FUNCTION 'DISPLAY_BASIC_LIST'
           EXPORTING
                file_name     = filename
           TABLES
                data_tab      = data_tab
                fieldname_tab = fieldnames.
    *-- End of Program
    <b>Excel Upload Alternative - KCD_EXCEL_OLE_TO_INT_CONVERT</b>
    *Title : Excel Uploading
    TYPES:   BEGIN OF t_datatab,
             col1(25)  TYPE c,
             col2(30)  TYPE c,
             col3(30)  TYPE c,
             col4(30)  TYPE c,
             col5(30)  TYPE c,
             col6(30)  TYPE c,
             col7(30) TYPE c,
             col8(30)  TYPE c,
             col9(30)  TYPE c,
             col10(30)  TYPE c,
             col11(30)    TYPE c,
           END OF t_datatab.
    DATA: it_datatab TYPE STANDARD TABLE OF t_datatab INITIAL SIZE 0,
          wa_datatab TYPE t_datatab.
    Data : p_table type t_datatab occurs 0 with header line.
    DATA : gd_scol   TYPE i VALUE '1',
           gd_srow   TYPE i VALUE '1',
           gd_ecol   TYPE i VALUE '256',
           gd_erow   TYPE i VALUE '65536'.
    DATA: it_tab TYPE filetable,
          gd_subrc TYPE i.
    field-symbols : <fs>.
    *Selection screen definition
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS:  p_file LIKE rlgrap-filename
                   DEFAULT 'c:test.xls' OBLIGATORY.   " File Name
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      REFRESH: it_tab.
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title     = 'Select File'
          default_filename = '*.xls'
          multiselection   = ' '
        CHANGING
          file_table       = it_tab
          rc               = gd_subrc.
      LOOP AT it_tab INTO p_file.
    *    so_fpath-sign = 'I'.
    *    so_fpath-option = 'EQ'.
    *    append so_fpath.
      ENDLOOP.
    START-OF-SELECTION.
      PERFORM upload_excel_file TABLES   it_datatab
                                 USING   p_file
                                         gd_scol
                                         gd_srow
                                         gd_ecol
                                         gd_erow.
    * END-OF-SELECTION.
    END-OF-SELECTION.
      LOOP AT it_datatab INTO wa_datatab.
        WRITE:/ wa_datatab-col1,
                wa_datatab-col2,
                wa_datatab-col3,
                wa_datatab-col4,
                wa_datatab-col5,
                wa_datatab-col6,
                wa_datatab-col7,
                wa_datatab-col8,
                wa_datatab-col9,
                wa_datatab-col10,
                wa_datatab-col11.
      ENDLOOP.
    *&      Form  UPLOAD_EXCEL_FILE
    *       upload excel spreadsheet into internal table
    *      -->P_TABLE    Table to return excel data into
    *      -->P_FILE     file name and path
    *      -->P_SCOL     start column
    *      -->P_SROW     start row
    *      -->P_ECOL     end column
    *      -->P_EROW     end row
    FORM upload_excel_file TABLES   p_table
                           USING    p_file
                                    p_scol
                                    p_srow
                                    p_ecol
                                    p_erow.
      DATA : lt_intern TYPE  kcde_cells OCCURS 0 WITH HEADER LINE.
    * Has the following format:
    *             Row number   | Colum Number   |   Value
    *      i.e.     1                 1             Name1
    *               2                 1             Joe
      DATA : ld_index TYPE i.
    * Note: Alternative function module - 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
        EXPORTING
          filename                = p_file
          i_begin_col             = p_scol
          i_begin_row             = p_srow
          i_end_col               = p_ecol
          i_end_row               = p_erow
        TABLES
          intern                  = LT_INTERN
        EXCEPTIONS
          inconsistent_parameters = 1
          upload_ole              = 2
          OTHERS                  = 3.
      IF sy-subrc <> 0.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        WRITE:/ 'Error Uploading file'.
        EXIT.
      ENDIF.
      IF lt_intern[] IS INITIAL.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        WRITE:/ 'No Data Uploaded'.
        EXIT.
      ELSE.
        SORT lt_intern BY row col.
        LOOP AT lt_intern.
         MOVE lt_intern-col TO ld_index.
         assign component ld_index of structure
         p_table to <fs>.
    move : lt_intern-value to <fs>.
    *     MOVE lt_intern-value TO p_table.
          AT END OF row.
            APPEND p_table.
            CLEAR p_table.
          ENDAT.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    "UPLOAD_EXCEL_FILE
    Regards
    Pavan

  • Calling a method in Parent component from Title Window

    Hi all,
    I have a parent component that opens up a Title window when I
    click a button. Now I want to call a method in that parent
    component from the Title window. How do I do this in Flex? Could
    anyone give me a hint please.
    Thank you in advance for the help

    "happybrowndog" <[email protected]> wrote in
    message
    news:gctmql$4t5$[email protected]..
    > That's goddamned ridiculous. What were Flex developers
    thinking that you
    > have
    > to write a custom event to call back to a parent
    component?? Other GUI
    > libraries such as WxWidgets, Fox, Qt, Delphi, MFC,
    WinForms, etc., all
    > allow
    > you to either call via a reference to the parent object
    or submit a
    > callback
    > function into the child object. That's just basic OO
    programming. Flex
    > is
    > looking more and more ridiculous and more like Swing -
    tons of unnecessary
    > coding to do simple things.
    You absolutely _do_ have the capability to pass in a
    reference to the parent
    component, or to create a "hard" reference to
    Application.application. But
    these are not recommended practices, because anything you
    create this way is
    then tied to an environment that implements those properties
    and methods.
    Q (3): I want to run a function in my main application from
    inside my
    custom component. But when I try to refer to myFunction() in
    that
    component, I get a compile time error Call to a possibly
    undefined function
    myFunction. How can I fix this?
    A: Your component has its own scope, so it doesn't know
    anything
    about the functions in the main file. You can get around this
    by directly
    referencing the main application scope like this:
    Application.application.myFunction(). However, this makes
    your component
    tightly coupled, which is a quick way of saying that your
    component is only
    usable in an application that has a myFunction() function in
    it. You're
    better off dispatching an event from your component and
    letting the
    application decide how to handle it. For more information,
    check out the
    following resources:
    http://www.adobe.com/devnet/flex/articles/loose_coupling.html
    http://www.adobe.com/devnet/flex/articles/graduating_pt1.html
    From
    http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

  • Calling a function in an external actionscript

    Hi. First of all I'd like to put my hands up and say that what I know about Flash is antiquated (I used to work with Flash 4 / 5), and have now been thrown into the deep end, as it were.
    I have an application that has a button component. In an external actionscript file there's an event listener that calls a function when this button is pressed. I want to replace the button with a graphic that switches according to whether the button is 'on' or 'off'. I've created a movie clip that cycles back and forth between the on and off states when clicked, but the trouble I'm having is getting it to call the function. I have no idea how to do it, other than to just include function_name(); (or call.function_name();) in the onRelease handler (which doesn't work). Is it possible to use event listners for movie clips (rather than components?) Or else how can I call this function? It should be really simple and I'm tearing my hair out trying to get it to work! The function is declared 'public', by the way...
    Oh yes, this is ActionScript 1 (I think...)
    Eternal thanks and gratitude to anyone who can help me...

    Do you mean to copy it here, or copy it into the fla? I've already tried doing the latter, which doesn't work - the script imports other external as files and I think that that's messing things up. The function only seems to work when it's located in this external file. The function I'm trying to call is
    public function toggleAudio() {
           //if (btnAudio.label == "Sound Off") {
           if (_root.audio == "mute" or btnAudio2.label == "Sound Off") {
               trace("toggleAudio AUDIO: Off");
               //btnAudio.label = "Sound On";
               _root.audio = "unmute";
                         // stop recieving audio from in stream
               ServiceLocator.getInstance().getService("nsService").returnInStream().receiveAudio(false) ;
               // stop sending audio on out stream
               ServiceLocator.getInstance().getService("nsService").returnOutStream().attachAudio(null);
                     } else {
               trace("toggleAudio AUDIO: On");
               btnAudio2.label = "Sound Off";
               _root.audio = "mute";
                         // start recieving audio from in stream
               ServiceLocator.getInstance().getService("nsService").returnInStream().receiveAudio(true);
               // start sending audio on out stream
               ServiceLocator.getInstance().getService("nsService").returnOutStream().attachAudio(Servic eLocator.getInstance().getService("camService").returnMic());
    The bit at the beginning where I've commented some stuff out is where I've been trying out different things to get it to work.
    For all intents and purposes though the function could be
    public function please_work() {
    trace("I work!");
    All I need is for a way to call this from the main flash movie

  • Calling a function in a flex app from a loaded SWF

    How can I call a function in a flex application from a loaded
    swf file?

    Two ways:
    Application.application returns a reference to the top-level
    application scope. You can access any public member, var, function,
    component, etc through that reference.
    Dispatch an event event form the loaded swf and use a event
    handler in the main app. All the gurus advise this as best
    practice, to ensure "loose coupling" It is also pretty easy,
    especially if you use a bubbling event.
    Tracy

  • Calling a function in the application

    Whats the best way to call a function that is in the main application file from a custom component that is nested several layers down
    thanks

    Try to use FlexGlobals.topLevelApplication

  • Calling a function in another .swf, possible?

    I have two movies... main.swf and content.swf, and I'm trying to call a function in my main.swf from my content.swf. Here is the code..
    //function in main.swf
    function appear (event:MouseEvent):void{
         TweenLite.to(title1, 1, {autoAlpha:1, overwrite:false});
    //try to call from loaded content.swf
    close_btn.addEventListener(MouseEvent.CLICK, btnClick);
    function btnClick(event:MouseEvent):void {
         MovieClip(parent.parent).appear();
    I got an error message as soon as i click on close_btn. It says appear() is not a property or method.
    Would someone help me out on this please?
    Thank you very much.

    I think it is not a good OOP design. It is much better to design applications in a such way that they do not depend on placements (especially parents). Particularly, if your application acts as a component that can be consumed in some unpredictable fashion. Theoretically, if you write something that will become a stand alone swf - it should perform with no errors both as stand-alone and when loaded.
    You are already dealing with the results of this design flow. The most cumbersome and inflexible aspect of your approach is to capture parents chain.
    In your case I would totally dissociate you loaded swf from the placement and couple it with the parent via events.
    The best way would be for your loaded swf to dispatch and event that is consequently captured by it parent(s) no matter, again, where it is placed. For instance it can be done the following way:
    // in your top movie
    // say the loaded swf is set to a variable:
    import flash.display.MovieClip;
    import flash.events.Event;
    var loadedSWF:MovieClip;
    // your loading routine
    // once it is loaded
    // note that capture is set to true so that
    // no matter depth of event origination
    // it will be captured by this scope
    loadedSWF.addEventListener("close", onCloseClick, true);
    function onCloseClick(e:Event):void {
         // do whatever
    // IN YOUR LOADED SWF
    close_btn.addEventListener(MouseEvent.CLICK, btnClick);
    function btnClick(event:MouseEvent):void {
        // dispatch event
         dispatchEvent(new Event("close"));

Maybe you are looking for