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"));

Similar Messages

  • Can I call a function in another package?

    Dear all,
    Can I call a function in another package?
    Say I have package A, and package B.
    Is it possible for me to call a function in inside package A, within a function inside package B?
    If yes, what's the syntax.
    Thanks in advance!

    The variable in the calling package that will receive the value of the function in the other package needs to be defined based on that type in the other package directly:
    sql>create or replace package pkg_a
      2  is
      3    type testTable is table of varchar2(10) index by binary_integer;
      4 
      5    function f_a return testTable;
      6  end;
      7  /
    Package created.
    sql>create or replace package body pkg_a
      2  is
      3    function f_a
      4      return testTable
      5    is
      6      v_table testTable;
      7    begin
      8      v_table(1) := 'One';
      9      v_table(2) := 'Two';
    10      return v_table;
    11    end; 
    12  end;
    13  /
    Package body created.
    sql>create or replace package pkg_b
      2  is
      3    procedure p_b;
      4  end; 
      5  /
    Package created.
    sql>create or replace package body pkg_b
      2  is
      3    procedure p_b
      4    is
      5      v_table pkg_a.testTable;  -- this variable has to be based on the type in pkg_a
      6    begin
      7      v_table := pkg_a.f_a;
      8      for i in 1..v_table.count loop
      9        dbms_output.put_line( v_table(i) );
    10      end loop;
    11    end;
    12  end; 
    13  /
    Package body created.
    sql>exec pkg_b.p_b
    One
    Two
    PL/SQL procedure successfully completed.

  • Calling a function in another class that is not the App delegate nor a sngl

    Hi all-
    OK- I have searched and read and searched, however I cannot figure out an easy way to call a function in another class if that class is not the app delegate (I have that down) nor a singleton (done that also- but too much code)
    If you use the method Rick posted:
    MainView *myMainView = [[MainView alloc] init];
    [MyMainView goTell];
    That works, however myMainView is a second instance of the class MainView- I want to talk to the instance/Class already instantiated.
    Is there a way to do that without making the class a singleton?
    Thanks!

    I had some trouble wrapping my head around this stuff at first too.
    I've gotten pretty good at letting my objects communicate with one another, however I don't think my method is the most efficient or organized way but I'll try to explain the basic idea.
    When you want a class to be able to talk to another class that's initialized elsewhere, the class your making should just have a pointer in it to the class you want to communicate with. Then at some point (during your init function for example) you should set the pointer to the class you're trying to message.
    for example in the app-delegate assume you have an instance of a MainView class
    and the app-delegate also makes an instance of a class called WorkClass
    If you want WorkClass to know about MainView just give it a pointer of MainView and set it when it's instantiated.
    So WorkClass might be defined something like this
    //WorkClass.h
    @import "MainView.h"
    @interface WorkClass : NSObject
    MainView *myPointerToTheMainView;
    @property (retain) myPointerToTheMainView;
    -(void)tellMainViewHello;
    @end
    //WorkClass.m
    @import "WorkClass.h"
    @implementation WorkClass
    @synthesize myPointerToTheMainView;//this makes getter and setter functions for
    //the pointer and allows us to use the dot
    //syntax to refrence it.
    -(void)tellMainViewHello
    [myPointerToTheMainView hello]; //sends a message to the main view
    //assume the class MainView has defined a
    //method -(void)hello
    @end
    now somewhere in the app delegate you would make the WorkClass instance and pass it a reference to the MainView class so that WorkClass would be able to call it's say hello method, and have the method go where you want (to the single instance of MainView owned by the app-delegate)
    ex:
    //somewhere in app-delegate's initialization
    //assume MainView *theMainView exists and is instantiated.
    WorkClass *myWorkClass = [[WorkClass alloc] init];
    myWorkClass.myPointerToTheMainView = theMainView; //now myWorkClass can speak with
    // the main view through it's
    // reference to it
    I hope that gets the basic idea across.
    I'm pretty new to Obj-c myself so if I made any mistakes or if anyone has a better way to go about this please feel free to add
    Message was edited by: kodafox

  • VPD: Problems calling a function on another schema

    Here's the setup:
    I've create a schema called "AllYourBase".  It contains all of my tables, views, functions, procs, etc.
    These tables are protected by a DBMS_RLS policy.  The policy uses a function to define its predicate which looks like this:
    create or replace function tous_filter(schemaName varchar2, tableName varchar2)
    return varchar2 is
    begin
    return  'account = sys_context(''USERENV'', ''CLIENT_IDENTIFIER'')';
    end;
    All of the tables have an account column for this to work.  So far, this is a pretty basic VPD setup.
    I have other db users that login and view data in the "AllYourBase" schema.
    So when "ArbyLong" logs in, I set sys_context('USERENV', 'CLIENT_IDENTIFIER') to "ArbyLong", and when he runs a query, he gets back his rows.
    Now, "AllYourBase" has several functions.  Here's a very contrived, simplified example of one (but it illustrates the issue I'm running into just fine):
    create or replace function getUserID
    return integer is retval integer;
    begin
    select user_id into retval from users;
    return (retval);
    end;
    When "ArbyLong" runs the equivalent query (select user_id from users), he gets back the one row where the account column is equal to "ArbyLong", as expected.
    But this getUserID function lives in the "AllYourBase" schema.  And here's the catch: I've made "AllYourBase" exempt from the policies by running "grant exempt access policy to AllYourBase".
    When "ArbyLong" runs the function getUserID, it runs in the "AllYourBase" schema and pulls ALL of the rows from the users table.
    This particular function simply errors out (since it's only expecting one row), but other functions are returning data that the logged in user shouldn't see.
    So even though there are policies in place, by calling a function on another schema who is exempt from the policies, a user is able to see all returned data and not just the rows they are normally limited to.
    Ultimately my question is this: Is there a way to enforce VPD policies when a user calls a function that lives in another schema?
    Doing my own research, the answers I've come up with are:
    * Don't use "grant exempt policy"!
    * Put the function directly into the users' schemas.  So "ArbyLong" would have his own getUserID function that would look at the "AllYourBase" users table.
    I'd rather not do either of these, so does anyone have any other ideas?  If it turns out these are the only solutions, then I'll go with one of them.
    Thanks!

    Need more info. Are you using a ViewStack or other navigator container, and trying to access a view that has not been displayed yet, due to deferred instantiation?
    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 Training and Support Services

  • Calling one function in another function

    Hi,
    How to call one function in another function?
    regards,
    Kishore.

    example:
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    function bob(x number) return number is
      3    begin
      4      return x*x;
      5    end;
      6    function fred(x number) return number is
      7    begin
      8      return x+bob(x);
      9    end;
    10  begin
    11    dbms_output.put_line('Value: '||to_char(fred(5),'fm9999'));
    12* end;
    SQL> /
    Value: 30
    PL/SQL procedure successfully completed.
    SQL>

  • Calling javascript function to open SWF

    When the Captivate presentation ends, I'm trying to open
    another SWF in the same browser window.
    I have put the following code in the HTML document:
    <script type="text/javascript">
    <!--
    function changeMovie(filename)
    document.getElementById('Captivate1').movie=filename;
    alert(document.getElementById('Captivate1').movie);
    //-->
    </script>
    I am able to call the function from the Captivate file
    successfully because the alert window pops up with the name of the
    movie. I just can't get it to play. Can anyone help me on this?
    Not to be rude or anything, but I should note that:
    1) this is not my idea--it is my boss' idea, and any attempts
    to tell me that this is something not worth doing will
    unfortunately fall, not on deaf ears, but on ears connected to
    hands that have no freedom to choose how this project is completed.
    This is my master's bidding, and I must do what he says.
    2) I know very little JavaScript. This code was given to me
    by another guy on the project. So if you have advice for changing
    the code, please be as specific as possible.
    I would be very grateful for any help that you can
    offer.

    Two non javascript methods:
    Movie End Options -> Action ->> Open URL or file
    Button -> On Success ->> Open URL or file
    A method to load a new movie without completly reloading the
    page.
    1. Create two 200x200 movies - m1 and m2 - add some content.
    2. Create a button in m1 set Exectue Javascript ->>
    loadMovie('m2.htm');
    3. Publish html and swfs to the same folder.
    4. Open m1.htm and replace all the code with the following
    (up to and including </html>):
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8">
    <title>m1</title>
    <script type="text/javascript">
    var xmlHttp
    function loadMovie(url)
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    alert ("Browser does not support HTTP Request")
    return
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    function stateChanged()
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    document.getElementById("movieContainer").innerHTML=xmlHttp.responseText
    function GetXmlHttpObject()
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    objXMLHttp=new XMLHttpRequest()
    else if (window.ActiveXObject)
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    return objXMLHttp
    </script>
    </head>
    <body>
    <div id="movieContainer">
    <!-- captivate generated code -->
    <object
    classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="
    http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
    width="200" height="200" id="Captivate1" align="middle">
    <param name="allowScriptAccess" value="sameDomain">
    <param name="movie" value="m1.swf">
    <param name="quality" value="high">
    <param name="menu" value="false">
    <param name="loop" value="0">
    <param name="bgcolor" value="#f3f3f3">
    <embed src="m1.swf" name="Captivate1" quality="high"
    bgcolor="#f3f3f3" width="200" height="200" name="menu"
    align="middle" allowScriptAccess="sameDomain" loop="0"
    type="application/x-shockwave-flash" menu="false" pluginspage="
    http://www.macromedia.com/go/getflashplayer">
    </object>
    <!-- end Captivate code -->
    </div>
    </body>
    </html>
    5. Open m2.htm and replace the code with the following:
    <!-- Captivate generated code -->
    <object
    classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="
    http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
    width="200" height="200" id="Captivate1" align="middle">
    <param name="allowScriptAccess" value="sameDomain">
    <param name="movie" value="m2.swf">
    <param name="quality" value="high">
    <param name="menu" value="false">
    <param name="loop" value="0">
    <param name="bgcolor" value="#f3f3f3">
    <embed src="m2.swf" name="Captivate1" quality="high"
    bgcolor="#f3f3f3" width="200" height="200" name="menu"
    align="middle" allowScriptAccess="sameDomain" loop="0"
    type="application/x-shockwave-flash" menu="false" pluginspage="
    http://www.macromedia.com/go/getflashplayer">
    </object>
    <!-- end Captivate generated code -->
    6. Open m1.htm in you browser, click the button to load m2
    How it works:
    Simply put AJAX lets you load parts of an html file in the
    current window. The code to be replaced is within the div
    id="movieContainer". The code in the file you want to load should
    be only the code you need, not an entire HTML file.
    Call it from Captivate with loadMovie('URL') where URL is the
    name of the html file.

  • Calling a function from another class - help!

    I realize that this is probably a basic thing for people who have been working with JavaFX for a while, but it is eluding me, and I have been working on it for over a week.
    I need to call a function that is in another class.  Here's the deal.  In EntryDisplayController.java, there are 2 possible passwords that can be accepted - one will give full access to the car, the second will limit functions on the car.  So when a password is entered and verified as to which one it is, I need to call a function in MainDisplayController.java to set a variable that will let the system know which password is being used - full or restricted.
    So in MainDisplayController.java I have this snippet to see
    public class MainDisplayController implements Initializable, ControlledScreen {
        ScreensController myController;
        public static char restrict;
         * Initializes the controller class.
        @Override
        public void initialize(URL url, ResourceBundle rb) {
            // TODO
        public void setRestriction(){
            restrict = 0;
            restrictLabel.setText("RESTRICTED");
        public void clearRestriction(){
            restrict = 1;
            restrictLabel.setText("");
    And in EntryScreenDisplay.java I have this snippet:
    public class EntryDisplayController implements Initializable, ControlledScreen {
         @FXML
        private Label passwordLabel ;
        static String password = new String();
        static String pwd = new String("");
         ScreensController myController;
         private MainDisplayController controller2;
         * Initializes the controller class.
        @Override
        public void initialize(URL url, ResourceBundle rb) {
            setPW(pwd);    // TODO
         @FXML
        private void goToMainDisplay(ActionEvent event){
            if(password.equals ("123456")){
              controller2.clearRestriction();
               myController.setScreen(ScreensFramework.MainDisplayID);
               pwd = "";
               password = "";
               setPW(pwd);
            else if(password.equals ("123457")){
               controller2.setRestriction();
                myController.setScreen(ScreensFramework.MainDisplayID);
               pwd = "";
               password = "";
               setPW(pwd);
            else{
                password = "";
                pwd = "";
                setPW(pwd);
    When I enter the restricted (or full) password, I get a long list of errors, ending with
    Caused by: java.lang.NullPointerException
      at velocesdisplay.EntryDisplayController.goToMainDisplay(EntryDisplayController.java:60)
    Line 60 is where "controller2.setRestriction(); is.
    As always, thanks for any help.
    Kind regards,
    David

    You never set the controller2 variable to anything, which is why you get a null pointer exception when you try to reference it.
    public static variables (and even singletons) are rarely a good idea as they introduce global state (sometimes they can be, but usually not).
    If a static recorder like this can only have a binary value, use a boolean, if it can have multiple values, use an enum.
    Some of the data sharing solutions in dependency injection - Passing Parameters JavaFX FXML - Stack Overflow might be more appropriate.
    I also created a small framework for roll based solutions in JavaFX which perhaps might be useful:
    http://stackoverflow.com/questions/19666982/is-there-a-way-to-implement-a-property-like-rendered-on-javafx
    https://gist.github.com/jewelsea/7229260
    It was just something I hacked together, so it's not a fully polished solution and you probably don't need something quite so complex.
    What you need is a model class shared between the components of your application.  Dependency injection frameworks such as afterburner.fx can help achieve this in a fairly simple to use way.
    If you don't want to go with a dependency injection framework, then you could use either a static singleton model class for your settings or pass the model class using the mechanism in defined in the passing parameters link I provided.  For a model class example, see the ClickCounter class from this example.   That example doesn't use FXML, but to put it together with the passing parameters solution, for your restriction model, you would have something like the following:
       private class Restricted {
         private final ReadOnlyBooleanWrapper restricted;
         public Restricted(boolen isRestricted) {
           restricted = new ReadOnlyBooleanWrapper(isRestricted);  
         public boolean isRestricted() {
           return restricted.get();
         public ReadOnlyBooleanProperty restrictedProperty() {
           return restricted.getReadOnlyProperty();
    Then in your EntryDisplayController you have:
    @FXML
    public void goToMainDisplay(ActionEvent event) {
         // determine the restriction model as per your original code...
         RestictionModel restrictionModel = new RestrictionModel(<appropriate value>);
      FXMLLoader loader = new FXMLLoader(
      getClass().getResource(
       "mainDisplay.fxml"
      Stage stage = new Stage(StageStyle.DECORATED);
      stage.setScene(
       new Scene(
         (Pane) loader.load()
      MainDisplayController controller =
        loader.<MainDisplayController>getController();
      controller.initRestrictionModel(restrictionModel);
      stage.show();
    class MainDisplayController() {
      @FXML private RestrictionModel restrictionModel;
      @FXML private RestrictLabel restrictLabel;
      public void initialize() {}
      // naming convention (if the restriction model should only be set once per controller, call the method init, otherwise call it set).
      public void initRestrictionModel(RestrictionModel restrictionModel) {
        this.restrictionModel = restrictionModel;
         // take some action based on the new restriction model, for example
        restrictLabel.textProperty.bind(
          restrictionModel.restrictedProperty().asString()
    If you have a centralized controller for your navigation and instantiation of your FXML (like in this small FXML navigation framework), then you can handle the setting of restrictions on new screens centrally within the framework at the point where it loads up FXML or navigates to a screen (it seems like you might already have something like this with your ScreensController class).
    If you do this kind of stuff a lot, then you would probably benefit from a move to a framework like afterburner.  If it is just a few times within your application, then perhaps something like the above outline will give you enough guidance to implement a custom solution.

  • Calling a function in a swf with TLFTextField from an external program fails

    I have a program A that loads another swf B, and after B is loaded, A will call a function of B.  It used to work when B creates a TextField and uses TextFormat, but when I changed to creating a TLFTextField, I got this error:
    Reference Error: Error #1069:  Property loadCurrentPictureFromMenu not found on ECard__Preloader__ and there is no default value.
    at ECard/swfLoadCompleteEventHandler()....
    And also
    Warning: Ignoring 'secure' attribute in policy file from http://fpdownload.adobe.com/pub/swz/crossdomain.xml.  The secure attribute is only permitted in HTTPS and socket policy files......
    So I wrote these 2 programs to test this:
    ----------------------- Test B -------------------------
    import fl.text.TLFTextField;
    import flashx.textLayout.formats.TextLayoutFormat;
    import flashx.textLayout.elements.TextFlow;
    var myFormat:TextLayoutFormat = new TextLayoutFormat();
    myFormat.fontFamily = "Kids";
    myFormat.fontSize = 24;
    var tlfTextField:TLFTextField = new TLFTextField();
    tlfTextField.x = 50;
    tlfTextField.y = 50;
    addChild(tlfTextField);
    var myTextFlow:TextFlow = tlfTextField.textFlow;
    myTextFlow.hostFormat = myFormat;
    myTextFlow.flowComposer.updateAllControllers();
    tlfTextField.text = "Testing this";
    function changeText(string:String):void
         tlfTextField.text = string;
    ---------------------- Test A -----------------------------------
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.display.MovieClip;
    var urlRequest:URLRequest = new URLRequest("testTLFTextField.swf");
    var loader:Loader = new Loader();
    loader.load(urlRequest);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingCompleteEventHandler);
    function loadingCompleteEventHandler(evt:Event):void
         addChild(loader);
         loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadingCompleteEventHandler);
         var mc:MovieClip = evt.currentTarget.content;
         mc.changeText("We are here");
    I got Error #1069 again, but when I changed TLFTextField back to TextField, it works again.  Test A can now find the function "changeText()" in Test B.
    I am using CS5.5.
    Any help is appreciated!
    Thanks in advance!

    I had this written in the program and commented it out when I was trying to debug an earlier problem.  I uncommented the Embed statement, but it is still not working on Android.  Running on PC is fine.  I will try out a few more things, if it still does not work, I will open a new thread.
    Thanks all for your help!

  • How can i call a function of a swf-file which is embedded as a Resource in 3D-Annotation?

    Hi.
    I use a Flash-menu as an embedded *.swf in a 3D-Annotation. Now i want to trigger one of the ActionScript-Function out of the 3D-Annotation.
    How can i get access to that function?
    Cause of it is embedded, the callAS() Methods still not possible. But how else can i do that?
    Can u give me a simple example? How is the usability of Flashvariable in the Ressource-Tab of 3d-Annotation?
    Kind regards
    Florian

    It depends to some extent on how your SWF has been bound to the 3D scene. If you have bound it using a script, then you have a FlashMovie object that has a .call() method - but if you've attached it to something using the binding option on the Resources panel you will need to collect a reference first. If you know you are going to talk to the SWF it's best to bind it using JavaScript.
    Let us assume you have a SWF in the resources collection but it's not bound to anything. In the 3D scene there is an object called 'cube' on which the SWF must appear as a material, and the SWF has declared a function to the ExternalInterface engine that is called "myFunction", which expects a string as a variable. Here's what you would put in the script attached to the 3D scene:
    var fm = new FlashMovie("demo.swf");
    var matl = scene.meshes.getByName("cube").material;
    matl.useFlashMovie(fm);
    fm.call("myFunction","hello");
    The call() method is strictly typed - for example if your AS function expects a boolean and you sent it a string, it will not execute. There is also a limit on the possible returned variables - e.g. you cannot send back an Object.
    Note that commands sent in the other direction using ActionScript's ExternalInterface.call() method are targeted at  document-level by default, not at the 3D API - so if your AS is trying to call something it must exist as a document-level JavaScript function. It is possible to divert this traffic into the 3D API using the FlashEventHandler object, but it gets complicated as your code must implement XML encoding of the traffic - this is done automatically by the document-level script but not by the 3D API.
    To answer your second question, in the resources dialog you can define the FlashVars string which is passed to the SWF when it loads - this is the same URL-encoded set of variables that you would send to a SWF when embedding it in an HTML page. It's a static string; you cannot read or edit it with JavaScript but this means it will still work if the user disables the JavaScript engine.

  • Why can't I call the function in the swf from the javascript?

    Hello,
    I have an html file that calls the function in swf file. In the swf file, I registered the function to be called using ExternalInterface.addCallback, as the book says.
    And I put this swf file in the html file using <object> tag and attempted to call the function using this object's id attribute.
    But every time to run this file, what I see is the error message such as "test1.show is not a function".
    Why is it?
    Please anyone help me. I am enclosing my work file. It's very simple one.
    Thank you.
    Daniel.

    It is entirely possible your college has decided to block certain websites. It's easy to do.

  • Call a function from another software

    hello,
    Iam working on a program where i have to invoke a function from another software, is there any way i can do that? someone told me that i can use RMI to invoke the function but it seems to me like RMI is mainly for networked and distributed systems. any suggestions? i have an idea in my mind, if the software is programmed using c/c++ i can use the native coding to access the functions, well this is only a blind shot, not sure about it.
    asrar

    Hey asrar,
    It is possible to call external programs from within the JVM. You need to do the following:
    Process p = java.lang.Runtime.getInstance().exec("some.exe");
    You can then do the following:
    p.waitFor();
    This will block until the process returns.
    The Process class gives you access to 3 streams.
    p.getInputStream(); returns a stream that the process sends to stdout.
    p.getErrorStream(); returns a stream that the process sends to stderr.
    p.getOutputStream(); returns a stream that allows you to send data to the process.
    That is basically all you get.
    regards,
    Dr_N35S

  • Calling a function inside another class

    I have the following two classes and can't seem to figure to figure out how to call a function in the top one from the bottom one. The top one get instantiated on the root timeline. The bottom one gets instantiated from the top one. How do I call functions between the classes. Also, what if I had another call instantiated in top one and wanted to call a function in the bottom class from the second class?
    Thanks a lot for any help!!!
    package
         import flash.display.MovieClip;
         public class ThumbGridMain extends MovieClip
              private var grid:CreateGrid;
              public function ThumbGridMain():void
                   grid = new CreateGrid();
              public function testFunc():void
                   trace("testFunc was called");
    package
         import flash.display.MovieClip;
         public class CreateGrid extends MovieClip
              public function CreateGrid():void
                   parent.testFunc();

    kglad,
    Although I agree that utilizing events the way you attempted in your suggestion is better for at least a reason of eliminating dependency on parent, still you code doesn't not accomplish what Brian needs.
    Merely adding event listener to grid instance does nothing - there is no mechanism in the code that invokes callTGMFunction - thus event will not be dispatched. So, either callTGMFunction should be called on the instance (why use events - not direct call - in this case?), or grid instance needs to dispatch this event based on some internal logic ofCreateGrid AFTER it is instantiated - perhaps when it is either added to stage or added to display list via Event.ADDED. Without such a mechanism, how is it a superior correct way OOP?
    Also, in your code in ThumbGridMain class testFunc is missing parameter that it expects - Event.
    Am I missing something?
    I guess the code may be (it still looks more cumbersome and less elegant than direct function call):
    package
         import flash.display.MovieClip;
         import flash.events.Event;
         public class ThumbGridMain extends MovieClip
             private var grid:CreateGrid;
             public function ThumbGridMain():void
                 grid = new CreateGrid();
                 grid.addEventListener("callTGMFunction", testFunc);
                 addChild(grid);
            // to call a CreateGrid function named cgFunction()
             public function callCG(){
                 grid.cgFunction();
             public function testFunc(e:Event):void
                 trace("testFunc was called");
    package
         import flash.display.MovieClip;
         import flash.events.Event;
         import flash.events.Event;
         public class CreateGrid extends MovieClip
             public function CreateGrid():void
                 if (stage) init();
                 else addEventListener(Event.ADDED, callTGMFunction);
             // to call a TGM function
             public function callTGMFunction(e:Event = null):void
               // I forgot this one
                removeEventListener(Event.ADDED, callTGMFunction);
                this.dispatchEvent(new Event("callTGMFunction"));
            public function cgFunction(){
                 trace("cg function called");
    I think this is a case of personal preference.
    With that said, it is definitely better if instance doesn't rely on the object it is instnatiated by - so, in this case, either parent should listen to event or call a function directly.

  • Calling a Function from another Function within CFC

    Hi all,
    I have many functions in my CFC that do various things, but
    one query is a query that selects absolutely every record from a
    table.
    The thing is, I need to do a query like this in another
    function to obtain only a recordcount of the same table used in
    both separate functions. Instead of writing the query out again,
    how can I utilise the function already written?
    My question is, how can I invoke and use the results of a
    query in one cffunction for another cffunction in the same CFC
    component?
    An example may look like the code attached...
    Many thanks for your patience and help!
    Mikey.

    quote:
    Originally posted by:
    Dan Bracuk
    Generally, to call a function from within a cfc, you do
    exactly what you do outside a cfc.
    For your specific case, if your requirements permit it, you
    might consider caching the big query for a couple of seconds. Then
    you can continously call the function and not have to wait for it
    to run and bring back the data each time.
    Do you mean to say that within a CFC function I can execute
    the same cfinvoke tags I use in normal CFM pages?
    Mikey.

  • Problem:  Unable to call a function in parent swf from the child swf.

    I am working on a site right now that has a parent loader
    (all it contains are the menu bar [which is as3 tweened] and the
    functions for calling all of the other pages.) The problem that I
    am having right now, are some of the internal or child pages, need
    to call functions that are in the parent loader. For what ever
    reason, I am unable to do any of that.
    I have attached the code so you can look at that.
    Let me see if I can explain it any better.
    The code I just posted is for the Main Stage swf called
    loader.swf. It has the menu, and all the functions that control the
    menu's movement and when to load all the other swfs. The easiest
    way for me to ask this, is to show you.
    click
    http://dev.locallinux.com/mystictan/layout2.html
    When you get there, you will see the menu bar, and it is
    loading home.swf onto the stage behind the menu.
    Mouse over "The Perfect Tan" and click on "1: Base"
    You will notice it just loaded a new swf called ptbase.swf.
    Well in that swf is a button for "Products" That button
    basically needs to take you to "Products > 1: Base" on the menu
    (not working yet, I know. But theres no point in me making that,
    until I could get this working"
    What I would like is when you click on "Products" in
    ptbase.swf, it calls the function clickedProductsBase(), which does
    its thing. But that function is back in the loader.swf. Does that
    make sence?
    What am I missing here?

    RyanORo, thank you very much for your response.
    I try that, and I get this sort of error when I click on it:
    TypeError: Error #1006: fwd is not a function.
    at ptbase_fla::MainTimeline/testing()
    I know all that code that I posted was a bith much, but here
    is the movie loading part:
    function loadComplete(event:Event):void
    loaderbar.visible = false;
    mainbody.removeChild(thisMC);
    thisMC = MovieClip(myloader.content);
    myloader.unload();
    mainbody.addChild(thisMC);
    thisMC.gotoAndStop(1);
    TransitionManager.start(thisMC, {type:Fade,
    direction:Transition.IN, duration:5, easing:Strong.easeOut});
    mainbody is an empty mc under the menu, so that the loaded
    swf file appears under the menu.
    You know what, scratch all that . *MOOWHA* I could KISS you
    right now. "(parent as MovieClip).clickedProductsBase()" did not
    work because it was calling it out of the wrong parent. Just did
    "(this.parent.parent as MovieClip).clickedProductsBase()" and that
    did the magic I needed. Thanks...

  • Calling flex functions from flash swf (AS3)

    Hi all, i'm stuck with communication between loaded AS3 SWF
    from Flash and Flex3 project. I use SWFLoader for runtime loading
    SWF, call functions inside SWF, but cannot find the way to call
    functions declared in Flex project. I try to use ExternalInterface
    class, but it does not help me, or maybe i use it incorrect. Is
    there a method to call Flex user declared functions from Flash SWF?
    All i need is a syntax sample, thank you in advance!

    Also, application.application will point to the top-level app
    scope, even from a loaded swf.
    I believe parentApplication will resolve to what you usually
    want as well.
    For looser coupling, consider using a bubbling event.
    Tracy

Maybe you are looking for