How do you access parent component from a child in Flex 4?

Suppose I have a Component A (as a Spark Group) that generates an event, eventX.  Inside Component A, I add Component B (also a Spark Group) that wants to add itself as an event listener for eventX.  How do I access Component A from Component B to register for the event?
For reference, this relationship should be similar to the MVC pattern where Component B is the view, and Component A is the model and controller.
If I were implementing this in ActionScript, I'd have no problem coding this.  However, I am using flex, and am still trying to figure out how the FLEX API works.

GordonSmith wrote:
B could "reach up" to A using the parentDocument property. Or you could set a reference-to-A onto B.
Gordon Smith
Adobe Flex SDK Team
B could "reach up" to A using the parentDocument property
Would you mind explaining that?
set a reference-to-A onto B.
That is something I am trying to avoid.  I do not want to create tightly coupled code.
Here is a generic form of the code I am using.  Feel free to tell me what I'm doing wrong in your explanation of how B can "reach up" to A.  Thanks!
Component A
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx" width="837" height="733"
                 creationComplete="componentA_creationCompleteHandler(event)"
                 xmlns:components="components.*">
     <fx:Script>
          <![CDATA[
               import mx.events.FlexEvent;
               public static const STATE_CHANGED:String = "stateChanged";
               private var currentModelState:String;
               protected function componentA_creationCompleteHandler(event:FlexEvent):void
                    changeModelState("second");
               public function changeModelState(newState:String):void
                    if (newState != currentModelState)
                         currentModelState = newState;
                    dispatchEvent(new Event(IP_Dragon.STATE_CHANGED));
               public function getModelState():String
                    return currentModelState;
          ]]>
     </fx:Script>
     <fx:Declarations>
          <!-- Place non-visual elements (e.g., services, value objects) here -->
     </fx:Declarations>
     <components:Component_B id="b" x="0" y="0"/>
</s:Group>
Component B
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:components="components.*"
           width="837" height="733" contentBackgroundAlpha="0.0" currentState="first"
           creationComplete="componentB_creationCompleteHandler(event)">
     <fx:Script>
          <![CDATA[
               import mx.events.FlexEvent;
               protected function componentB_creationCompleteHandler(event:FlexEvent):void
                    currentState = parent.getModelState;
                    parent.addEventListener(Component_A.STATE_CHANGED, modelStateListener);
               private function modelStateListener (e:Event):void
                    currentState = parent.getModelState();
          ]]>
     </fx:Script>
     <s:states>
          <s:State name="first"/>
          <s:State name="second"/>
          <s:State name="third"/>
     </s:states>
     <fx:Declarations>
          <!-- Place non-visual elements (e.g., services, value objects) here -->
     </fx:Declarations>
     <components:Component_C includeIn="first" x="220" y="275"/>
     <components:Component_D includeIn="second" x="2" y="0"/>
     <components:Component_E includeIn="third" x="0" y="8"/>
</s:Group>
For the record, I know this code does not work.  It has to do with the parent calls in Component B.  Comment out those lines, and the code will compile.

Similar Messages

  • 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.

  • How do you access one list from more than one page?

    So I have 3 pages to my sharepoint site and I would like to access a particular list on all 3 of the pages by adding an app part of the list to each page. However I've noticed that this isn't possible, and that you can only add a list as a web part if the
    list was created on that page. How could I do this? I am completely new to sharepoint so a simple step by step guide would be appreciated!
    Thanks!

    After Creating a custom list > Create page > Click Page in the Ribbon > Edit >  Insert > Apppart > Click on the list you created > Add.
    I was able to add to another page and replicate changes on both ends.

  • How do you access ipod photos from a PC?

    Please I need this for a project and my places do not come up in my finder help!

    You can use 3rd party apps like Photo Transfer App.
    https://itunes.apple.com/sg/app/photo-transfer-app/id365152940?mt=8

  • How do you access html attributes from an Event?

    Hi,
    Is there a way to access the VALUE of this html tag in the event code?
    Html:
    <input type="IMAGE" id="testId" src="images/sort_ascending.gif" name="event_Sort" value="ASC" />
    Event Code:
    public void onSort(DataActionContext ctx)
    // Code before executing the default action
    //if (ctx.getEventActionBinding() != null) ctx.getEventActionBinding().doIt();
    // Code after executing the default action
    }

    Duncan or anyone,
    Any Ideas why I can not get this to work?
    I do not get the value "ASC" in a prameter "event_Sort".
    I do get Two Parameters event_Sort.x & event_Sort.y.
    I believe they represent the coordinates on the image that I clicked?
    Here is all my code simple to the core:
    JSP Page:
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ page contentType="text/html;charset=windows-1252"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
    </head>
    <body>
    <form action="action1.jsp">
    <input type="image" src="images/sort_ascending.gif" name="event_Sort" value="ASC"/>
    </form>
    </body>
    </html>
    Java Event Code:
    package mypackage3;
    import javax.servlet.http.HttpServletRequest;
    import oracle.adf.controller.struts.actions.DataForwardAction;
    import oracle.adf.controller.struts.actions.DataActionContext;
    public class Action1Action extends DataForwardAction
    // To handle an event named "yourname" add a method:
    // public void onYourname(DataActionContext ctx)
    // To override a method of the lifecycle, go to
    // the main menu "Tools/Override Methods...".
    public void onSort(DataActionContext ctx)
    // Code before executing the default action
    //if (ctx.getEventActionBinding() != null) ctx.getEventActionBinding().doIt();
    // Code after executing the default action
    HttpServletRequest request = ctx.getHttpServletRequest();
    String sortValue = request.getParameter("event_Sort");
    System.out.println(sortValue);
    }

  • How do you access published playlists from the iTunes Store (am using iTunes 10.7 on a windows 7 machine)? There is no link on the music page

    Tried following directions in iTunes help, but there is no option on the music drop down box for playlists.

    Regards the size of apps the actual size of the apps is listed on iTunes
    Secondly you seem to be getting storage capacity/app size mixed up with RAM. They are two different things. The 64GB you have on your iPad is for actual storage of content whether it be apps, books, music, podcasts, video etc. RAM is the volatile memory that is used during the running of the iPad including the apps.
    The system requirements including the amount of RAM needed to run are not simply because unlike computers all iPads are the same regards the internal system specs. The only differences being the actual storage capacity and whether they have 3G capability or not.
    If you get an error message regards lack of system memory or RAM then doing a reset may help clear this problem. Unfortunately some developers do not optimise their apps properly for the iPad and it's not the first time an app has not run or crashed due to a lack of RAM. The best thing to do is to report it to the developer using the link on their iTunes app page.
    Regards memory leaks these do occur with both software on computers as well as apps on the iPad and iPhone. These are also due to badly designed apps or software and would need to be fixed by the developers.
    Edited by: Mr.C UK

  • How do you access updates to apps from the App store after changing to a new ID because the password on the old ID was changed and you don't know what it is now?

    How do you access updates to apps from the App store after changing to a new ID because the password on the old ID was changed by the former husband and you don't know what it is now?  And you set up your own new ID and account but can NOT access the updates, from the App store for the many apps that you already have, because they require that you sign in with that former now inaccessible ID and account and password?  Call it a problem of modern times and changing relationships, if you want to be charitable.

    So I guess it will only be new apps that I download that are allowed to give me their updates while 13 updates wait for me on an ID I can no longer access.
    Yes...  sorry.
    In the future, if need be, you can re download your purchases for free  >  Downloading past purchases from the App Store, iBookstore, and iTunes Store
    Good rule of thumb is to back up your purchases regardless  >  Mac App Store: Backing up your app purchases

  • How do you connect your photoshop elements on your computer to your account online? and how do you create a customized url? how does the gallery work and how do you access it? i have trouble signing in on my program from my computer to connect to the onli

    how do you connect your photoshop elements on your computer to your account online? and how do you create a customized url? how does the gallery work and how do you access it? i have trouble signing in on my program from my computer to connect to the online photoshop, and I really want to create my own customized url and post photos to my gallery and share them with the world, family, and friends, but i need help because i can't figure how to do any of this, would really appreciate feedback and assistance, thanks, - claire conlon

    To add to sig's reply, "calibrating" does not calibrate Lithiu-Ion batteries, it calibrates the charge reporting circuitry.  If you look at the effect of deep discharging Lithium-Ion batteries in the data from the independent test group, Battery University, you will see that doing so shortens the life of the battery significantly. It looks like an optimum balance between use and life is at a discharge level of 50%.

  • How do you access files from an external harddrive connected to TC through USB from iPad or windows computer?

    How do you access external hard drive data that is connected to TimeCapsule through USB from iPad or knows based computer?

    Filebrowser for the iPad does this very well.
    FileBrowser - Access files on remote computers for iPhone, iPod ...
    Cannot help on Windows, but another PC guy might be able to answer. Some possible clues here:
    http://support.apple.com/kb/HT1331

  • HT4847 How do you access your pictures that you stored on icloud from your ipod touch? I lost my ipod touch and want to get my photos from icloud but i cant seem to find any ******* help. where the **** is icloud and how do you get your stored pictures ba

    How do you access your pictures that you stored on icloud from your ipod?

    sunshinecowgill wrote:
    We have three operational computers, one does not have iTunes on it.  Since Apple is saying I have more than 5 authorized computers, and I can't imagine what they are, I am afraid to deauthorize all my computers.  See what I mean?  I just wanted to ask the question about how I can find out WHICH computers Apple thinks I have authorized, so I can decide if it's safe to deauthorize them all or not. 
    You could have more 5 computers authorized if you ever, for example, reformatted a hard drive or replaced a hard drive without deauthorizing the computer first. Apple's system would see that as a different computer, even though you don't. There's nothing to be afraid of in deauthorizing everything and the reauthorizing what you actually have. You won't lose any data. Mistimp is correct, they can't tell you which computers are authorized.

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • How do you access your itunes library from any computer

    how do you access your itunes account from another computer?

    You have asked two different questions?
    Your account is just a user name and password.  You can access that to buy content from any computer with itunes, just sign it.
    Your library wil only be where your put it. Yo can copy it from one computer to another, or from your backup copy of your computer ot another computer. In some countries you can download some past itunes purchases.
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • How do you access files on your time capsule from your mac?

    how do you access files on your time capsule from your mac?

    i had an old macbook pro that i had all the pictures on and i backed it up to my time capsule through time machine. i got a new macbook pro retina display recently and im wanting to see if i can get some of the pictures off of my time capsule now but i dont want all of them.

  • How do you access your itunes library from the icloud on your ipad

    How do you access your itunes library from the icloud on your ipad?

    You have asked two different questions?
    Your account is just a user name and password.  You can access that to buy content from any computer with itunes, just sign it.
    Your library wil only be where your put it. Yo can copy it from one computer to another, or from your backup copy of your computer ot another computer. In some countries you can download some past itunes purchases.
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • 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

Maybe you are looking for

  • Regarding SY-CALLD system field

    Dear Experts, I want to know how SY-CALLD works in both 46C and Enterprise. It seems in some cases SY-CALLD works differently in new versions. COuld you please give us an example and explain. Thanks in advance. ambichan

  • How to validate data in SM30

    Hi All, I have one ztable with 2 fields. One for company code and other for G/L acc. I want to validate the G/L acc corresponding comp code. If G/L not maintain for corresponding comp code sys should give error in sm30. How I can achive this. Thanks,

  • HttpURLConnection and cookies!!

    hello evrybody, i want to write a program which connect to a URL and load some data from there. but the problem is that site writes cookies you will only receive an hint to allow cookies. How can i write a program or simulate a client that accepts co

  • Can I output to my TV with big frame sizes

    Hi guys.. I always though I could store a video on the ipod as frame size 720 by 576 and when outputed to the tv, it play at this frame size. When played on my ipod, it downsizes it to fit. Is this right? Basically I just want my home video dvds, whe

  • MP3 player loses 75% memory upon formatting for Mac?! Can it be recovered?

    I recently pruchased a third party MP3 player. (yeah... I know) In order to access it on the Mac, someone told me I need to format it when it comes up asking to be initialized. I then via "Disk Utility" volume format, selected MS-DOS file system and