Mxml Component Help

I am createing an app that has a mxml component with a
menubar in it. For itemClick in the menubar i want to call a
function that is in my main mxml file but cant get it to work. Is
this possible and if so what is the solution.

The proper way is to use events. You will need to read up on
them as they are a little too complex to detail for you.
However there are two quick wasy to call a function outside
your current component. Basically you can "dot" your way up the
application till y ou get to the main.xm by using the
parentDocument.
So, in your component use parentDocument.FunctionName();
You can also directly access your application.mxml by using
mx.core.Application.application.FunctionName();

Similar Messages

  • Loading MXML Component Dynamically

    Hi all,
    I am new to Flex and was trying out small things . I created
    a MXML Application and also MXML components.
    I tried loading MXML component to application using xmlns and
    it worked fine.(
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" backgroundColor="#ffffff" xmlns:mi="com.*">
    <mi:base1 id="base1" />
    <mi:base2 id="base2" />
    This method is ok if we are loading 3-4 components .
    but , if i have to load a mxml component dynamically how do I
    do it?
    for example ,if base1 and base2 are two components and i want
    to load them based on some event performed.
    I have tried the method which uses ViewStack and code
    myViewStack.selectedChild=Container(myViewStack.getChildByName(selectedNode))
    ,where each child will have one component declared or initialized.
    Following this method is not a feasible when we have hundred
    of components to be loaded.
    Can anyone help me on this??

    "srirama.83" <[email protected]> wrote in
    message
    news:gpkoui$g3u$[email protected]..
    > Hi all,
    > I am new to Flex and was trying out small things . I
    created a MXML
    > Application and also MXML components.
    > I tried loading MXML component to application using
    xmlns and it worked
    > fine.(
    > <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    > layout="absolute"
    > backgroundColor="#ffffff" xmlns:mi="com.*">
    > <mi:base1 id="base1" />
    > <mi:base2 id="base2" />
    > )
    > This method is ok if we are loading 3-4 components .
    > but , if i have to load a mxml component dynamically how
    do I do it?
    > for example ,if base1 and base2 are two components and i
    want to load them
    > based on some event performed.
    >
    > I have tried the method which uses ViewStack and code
    >
    myViewStack.selectedChild=Container(myViewStack.getChildByName(selectedNode))
    > ,where each child will have one component declared or
    initialized.
    >
    > Following this method is not a feasible when we have
    hundred of components
    > to
    > be loaded.
    > Can anyone help me on this??
    >
    >
    http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
    Q4

  • Mxml component application

    Hi all,
    I am converting a asp.net website to Flex, I have five web pages which I designed as Five mxml components have buttons, grid, combos, text boxes etc.
    my question is how do I move between these pages they are distinct in there looks and functionality. I read a lot about view states and I am confused whether view states will solve my issue.
    Please tell me how do we handle this usually in flex applications.

    Hi,
    Flex 4 or Flex 3 the answer remains the same, I have a state for each form then I place a container, be it a group a canvas or a panel, in each state to show how states work, the following is in flex 3
    The Application
    ============
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" currentState="form1" xmlns:ns1="*">
    <mx:states>
    <mx:State name="form1">
    <mx:AddChild position="lastChild">
    <ns1:form1 horizontalCenter="0" verticalCenter="0">
    </ns1:form1>
    </mx:AddChild>
    </mx:State>
    <mx:State name="form2">
    <mx:AddChild position="lastChild">
    <ns1:form2 horizontalCenter="0" verticalCenter="0">
    </ns1:form2>
    </mx:AddChild>
    </mx:State>
    <mx:State name="form3">
    <mx:AddChild position="lastChild">
    <ns1:form3 horizontalCenter="0" verticalCenter="0">
    </ns1:form3>
    </mx:AddChild>
    </mx:State>
    </mx:states>
    <mx:Button label="Form 1" click="currentState='form1'" top="10" horizontalCenter="-150"/>
    <mx:Button label="Form 2" click="currentState='form2'" top="10" horizontalCenter="0"/>
    <mx:Button label="Form 3" click="currentState='form3'" top="10" horizontalCenter="150"/>
    </mx:Application>
    The Mxml Component Container (which is exactly what you said you had)
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" title="First Form">
    </mx:Panel>
    You can navigate through your 'pages' however you want to, the first example I offered is pure flex the above code is pure flex only using the antiquated sdk which I would advise against for 'new' projects, flex 3 sdk maybe used in flashbuilder but I would only go to this for legacy purposes using the flex 4 sdk is by far the better option.
    I try to help where I can, there is no reward for doing this, but I did answer your initial question about states, I hope you get to understand flex a little better with time.
    David.

  • Flex link to internal mxml component

    I have text.mxml component. that is showing me the following:
    <mx:DataGrid id="dgShowHistory" width="100%">
       <mx:columns>
        <mx:DataGridColumn headerText="ID"/>
        <mx:DataGridColumn headerText="Case Number"/>
        <mx:DataGridColumn headerText="Group Number"/>
        <mx:DataGridColumn headerText="Case Name"/>
        <mx:DataGridColumn headerText="Status"/>
       </mx:columns>
      </mx:DataGrid>
    Now the in the Case Number column I want to add a link to SearchCaseNumber.mxml...
    So lets say the Case Number has the following:
    Case Number
    1234
    1235
    1236
    I want these to be highlighted as link and when I click on these It takes me to the SearchCaseNumber.mxml put the 1234 automatically in search and if possible populate all the fields based on this.
    In SearchCaseNumber.mxml
    <mx:TextInput id="CaseSearch" width="81"/>

    I was trying to implement what you mentioned but I’m not an expert in the coding yet. Can you help me with the code and how it looks like?
    Here is my code… text.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
                            layout="vertical"
                            width="1000"
                            height="800"
                            titleStyleName="popWindowTitle"
                            horizontalScrollPolicy="off">
    <mx:Script>
       <![CDATA[
          import mx.formatters.DateFormatter;
          import mx.managers.PopUpManager;
          import mx.containers.TitleWindow;
          import mx.controls.Text;
          import mx.controls.ComboBox;
          import mx.core.Application;
          import mx.utils.ArrayUtil;
         import mx.controls.Alert;
          import mx.collections.ArrayCollection;
          import mx.rpc.events.ResultEvent;
          import mx.rpc.events.FaultEvent;
          import mx.controls.dataGridClasses.DataGridColumn;
          import com.component.coverage;
          [Bindable]
          private var CaseNumber:ArrayCollection = new ArrayCollection();
          private function handle_recordCaseNumber(event:ResultEvent):void
                CaseNumber = event.result as ArrayCollection;
        ]]>
    </mx:Script>
                <mx:RemoteObject id="CaseNumberCreate"
                             destination="ColdFusion"
                             source="Text.cfc.CaseNumber"
                             showBusyCursor="true">
                <mx:method name="getCaseNumber"
                              result="handle_recordCaseNumber(event)"
                               fault="Alert.show(event.fault.message)"/>                     
                </mx:RemoteObject>
    <mx:DataGrid x="800" y="650" id="CaseNumberGrid" dataProvider="{CaseNumber}"  creationComplete="{CaseNumberCreate.getCaseNumber()}"
    height="639"
    width="823">     
       <mx:columns>
          <mx:DataGridColumn headerText="ID" dataField="ID"/>
          <mx:DataGridColumn headerText="Case Number" dataField="Case_Number"/>
          <mx:DataGridColumn headerText="Group Number" dataField="Group_Number"/>  
          <mx:DataGridColumn headerText="Case Name" dataField="Case_Name"/>
          <mx:DataGridColumn headerText="Status" dataField="Status"/>
       </mx:columns>
    </mx:DataGrid>   
    </mx:TitleWindow>
    My SearchCaseNumber.mxml looks like the following:
    <mx:Label text="Enter Case Number Here:" fontWeight="normal" textAlign="center"/>
    <mx:TextInput id="CaseSearch" width="81" fontFamily="Arial"/>
    <mx:Button label="Search" click="findCase()"/>
    private function findCase():void
                      if (CaseSearch.text == "")
                      Alert.show("Enter the Case Number", "Error");
                      else
                      roCreate.returnCaseInfo(CaseSearchSearch.text);
                      roCreate.returnGroupInfo(CaseSearch.text);
    Please let me know if you can help me… Thanks…

  • Passing a variable from an mxml component to the main mxml file

    Hey guys,
    I have a popup titlewindowt which is defined as a component in a separate mxml component file.
    In the popup window i have an inputbox and a button
    When i press the button in that popup window i want the text in the input box to be transfered across to a variable in my main mxml file
    How can i do this?
    Thanks
    Chris

    Since you are already tied in to the top level application then I would add a listener at the application level and in the component do a:
      FlexGlobals.topLevelApplication.dispatchEvent(....)
    However, I can't help but encourage you to decouple this functionality and pass events around rather than what you are currently doing.
    There are a few ways you can do this.  One is to use an MVC framework to model your application after.
    A simpler approach even would be to have the component simploy dispatch events to itself and have whatever is creating the component listen for the events and do higher level functionality.
    Good Luck!

  • Error when using instantiated mxml component in popupmanager

    Hi,
    Im getting the following error when trying to create a popup:
    Error #1007: Instantiation attempted on a non-constructor
    The code looks as follows
    var browserPop:CustomBrowser = new CustomBrowser();
    browserPop.targetType = "file";
    browserPop.fileType = "jpg";
    var pop:TitleWindow =
    PopUpManager.createPopUp(this,browserPop as Class, true) as
    TitleWindow;
    Where CustomBrowser is an MXML component extending
    TitleWindow.
    If i use:
    var pop:TitleWindow =
    PopUpManager.createPopUp(this,CustomBrowser, true) as TitleWindow;
    it works fine but i need to be able to set some public
    properties and therefore instantiate it first. Any help would be
    appreaciated.
    Thanks in advance
    Eric

    Create you component using the popupmanager, then cast it to
    the
    specific type to access it's public methods and/or variables.
    Like so for mxml component ExceptionPopup:
    var popup:IFlexDisplayObject;
    popup =
    PopUpManager.createPopUp(_parentPanel,ExceptionPopUp,true,null);
    (popup as ExceptionPopUp).addRecords(ev.errorMessage);
    (popup as ExceptionPopUp).title = "title";
    (popup as ExceptionPopUp).userText.text = "some user text"
    PopUpManager.centerPopUp(popup);

  • Convert mxml component to an AS class?

    I just made a custom MXML component ("ProjectImage.mxml") and
    expected to be able to instantiate instances of it from AS scripts
    like so:
    var newImage:ProjectImage = new ProjectImage();
    (this is within an <mx:Script> block in Flex, and I've
    explicitly imported the component.)
    but apparently this doesn't work (got "Access of possibly
    undefined property source through a reference with static type
    customComp.views:ProjectImage.") Is there any easy way to convert
    my mxml component to an AS class without writing it from scratch?
    Flex does this anyway at runtime, yes? So it seems like it should
    be able to do it on command....
    Any help would be appreciated. Thanks!

    Ok, I realized I was making another mistake and that the mxml
    component works just fine being instantiated from AS. It'd still be
    nice to know how to get a look at AS classes generated from custom
    components though...

  • Optimizing mxml component having so many group

    Hi,
    I am stuck in critical issue which I have to fix within today. I have a view component or mxml component having 50 group.
    After slashscreen Its taking too much time and memory to load first view and GUI stuck for few minutes.
    There is any solution of this issue.I want to queued all group creation according to requirement I want to load it.
    If there is any alternate way then it will be helpful to me,
    Any help will be appreciated,

    I was going to look at the code for your Groups to see if I could suggest a quick way of refactoring the app to not all get instantiated at once.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.<http://www.adobe.com/>
    Blog: http://blogs.adobe.com/aharui

  • Loading an "MXML Component" at run-time creates a null object.

    Hello!
    I have a simple Flex 3 project with an MXML application file (the parent) and an MXML component file (the child).
    At run-time I create childs of this component, and I add it to the stage using a simple "this.addChild()" call.
    Now, besides that, in the creation loop, after every
      newChild = new mcComp();
    I want to setup a few more custom parameters which belongs to this class. For example, now I want to set a label's text, this label is at the child.
    The issue is that the label isn't created until I exit the creation function, and actually, until my code returns control to the Flash Player.
    See my problem here?
    With custom classes which resides at .AS files, when I instantiate them with the "new" operator, they run their constructure's code and eveything is fine.
    But, when I do the same with those MXML components (which by the way are based over the Canvas class), their constructure do not execute and actually no other child of them is created.
    Can anyone please advise? I must be missing some keyword here.. hopefully.

    Hi Natasha thanks,
    The issue is that the creationComplete event doesn't dispatch even when I addChild() the object.
    var child:mcChild = null;
    for(var i:int; i < 3; i++)
         child = new mcChild();
         // setting some properties, labels' text etc'
         this.addChild(child);
    Try this and you'll see - the event doesn't dispatch until you got out of the code flow.
    Anyway after looking at Flex's documentation I solved it differently;
    After the addChild() call the child receives an "initialize" event. After that I could modify my label.
    Thank you though!

  • Interface not found in implements-attribute for MXML component

    Hi,
    I am trying to use the "implements" attribute for an
    MXML-component in order to implement an interface from a library
    like below (Flex 3). I get the error "Interface IClonable not
    found". The compiler does not complain about " import
    com.yworks.support.IClonable;", so the library is installed
    correctly. I use the library in many places in my project, it just
    does not find it in the "implements" tag. How can I fix this
    without reimplementing the component in ActionScript?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    implements="com.yworks.support.IClonable">
    <mx:Script>
    <![CDATA[
    import com.yworks.support.IClonable;
    ]]>
    </mx:Script>
    </mx:VBox>

    "mavdzee" <[email protected]> wrote in
    message
    news:gldjg8$js8$[email protected]..
    > Hi,
    >
    > I am trying to use the "implements" attribute for an
    MXML-component in
    > order
    > to implement an interface from a library like below
    (Flex 3). I get the
    > error
    > "Interface IClonable not found". The compiler does not
    complain about "
    > import
    > com.yworks.support.IClonable;", so the library is
    installed correctly. I
    > use
    > the library in many places in my project, it just does
    not find it in the
    > "implements" tag. How can I fix this without
    reimplementing the component
    > in
    > ActionScript?
    >
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    > implements="com.yworks.support.IClonable">
    >
    > <mx:Script>
    > <![CDATA[
    >
    > import com.yworks.support.IClonable;
    >
    > ]]>
    > </mx:Script>
    >
    > </mx:VBox>
    I don't see anything where you're actually _implementing_ the
    interface, but
    I'd expect to see a different error if that's the problem.
    Still, I'd go
    ahead and implement the properties and methods in the
    interface, just to
    make sure.
    HTH;
    Amy

  • Event Fired when a mxml component is shown on screen

    hello,
    I have following application structure nested up to 2/3 level.
    Application
         linkbar connected to viewstack
         viewstack
              NavigatorContent
                   mxml Component
              NavigatorContent
                   mxml Component
    mxml componet in turn has similar structure
    componet
         linkbar connected to viewstack
         viewstack
              NavigatorContent
                   mxml Component
              NavigatorContent
                   mxml Component
    and end component is form which is shown and actions performed
    I want to execute specific code when the form is first time shown
    which will collect data from server and will show for further actions.
    User will edit/delete/update data with various button clicks.
    I tried activate event on end component but it seems that it wont get
    fired at all. End components are enclosed in BorderContainer or Group.
    To test activate event I have used Alert.show only but popup is not shown
    when I select link button on penutimate linkbar.
    If I am doing something wrong please let me know as well please
    guide me which event shall I use so that whenever linkbutton is
    pressed on linkbar it will fire that event. In that event I can check
    whether it has been called earlier by checking some variable which
    will be null in creation complete and set in event fired when linkbutton is pressed.
    Thanks and regards
    Raja

    I think 'creationComplete' is the closest event to what you are looking for.

  • How to create custom MXML component accepting other MXML componenents as children

    How can I create an MXML component that when I use it in the "main" MXML, accepts other MXML components...
    For example:
    <s:WindowedApplication>
         <myComponent>
              <otherMXMLcomponent></otherMXMLcomponent>
              <otherMXMLcomponent></otherMXMLcomponent>
              <otherMXMLcomponent></otherMXMLcomponent>
              <otherMXMLcomponent></otherMXMLcomponent>
         </myComponent>
    <s:WindowedApplication>
    How do you declare such a component?
    Thanks in advance

    Bhè non so se ho capito .. ti spiego la prova che ho fatto io.. Dunque, io ho provato a creare un mio componente Custom e a metterci dentro degli oggetti miei di esempio.. Il componente di esempio si chiama mioComponenteCustom e all'interno è strutturato in questo modo:
    <?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">
    </s:Group>
    Al posto dei puntini ci metto quello che voglio.. nel tuo caso i tuoi 2 famosi pulsanti..
    All'esterno chiamerò :
    <mioComponenteCustom>
         <s:DataGrid>
         </s:DataGrid
    </mioComponenteCustom>
    Dove DataGrid è un componente a caso qualsiasi.. Ora, con questa struttura non ricevo errori e sembra andare bene..
    Dimmi se ho capito bene o volevi fare altro..
    Max

  • How to import MXML Component in ActionScript

    Hello,
    I'm having a structure similar to this:
    root
       - components
           - subcomponents (MyCustomMXMLComponent)
       - views
    In views package I have a piece of AS where I want to instantiate an MXML Component from subcomponents.
    In Views:
    var data:DisplayObjectContainer=new components.subcomponents['MyCustomMXMLComponent'];
    But that throws an error.
    I need a syntax similar to the one above because I'm running a for loop and changing data variable to be a new MXML component on each iteration.
    Any idea how I can solve this?
    Thank you.

    OK, so:
    var length:int=arrSubcomponents.length;
    for(var i:uint=0;i<length;i++)
              //Decide parent
              var parent:IVisualElementContainer;
              if(arrSubcomponents[i].group && arrsUbcomponents[i].group==1){parent=firstGroup;}
        else{parent=secondGroup;}
              //Add to parent
              var childClassName:String='components.subcomponents.'+arrsUbcomponents[i].className;
              trace(childClassName);//So far so good the path is correct, I checked.
              var childClass:Class=Class(getDefinitionByName(childClassName));
              trace(childClass);//It breaks here with the error below
              var child:IVisualElement=new childClass() as IVisualElement;
              trace(child);
              parent.addElement(child);
    The error:
    ReferenceError: Error #1065: Variable FirstCustomMXMLComponent is not defined.
              at global/flash.utils::getDefinitionByName()

  • How to add interface to customlize MXML Component when use Flex Builder 3?

    How to add interface to customlize MXML Component when use
    Flex Builder 3?

    David,
    I don't believe you can add the interface via the creation
    dialog in FlexBuilder 3. You can always manually add the
    "implements" property to your MXML Component root tag. Something
    like this: <mx:VBox implements="com.mycorp.IMyInterface">
    If you want autogeneration of the interface, then create an
    ActionScript class with that interface and then copy the generated
    functions and setter/getters into the script block of your MXML
    component.

  • Dynamic addition of  MXML Component

    Is it possible to add an MXML component through an ActionScript.
    I have a situation where I display multiple checkboxes and on click of each I show a subform. I am planning to make that subform as MXML component and add/remove it based on the user's checking/unchecking the checkbox..Is this possible?
    Thanks
    Dharmesh

    Hi Ben ..
         Appreciate your quick response. This is my first Flex app. In a nut sheel here is a sample similar to what I am trying to achieve.
    Consider my Mxml component as follows
    <?xml version="1.0" encoding="utf-8"?>
    <!-- myComponents/TempComponent.mxml -->
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
        <mx:Button label="Hey there from component"/>
    </mx:Canvas>
    Now here he my app mxml file
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
        xmlns:temp="mycomponents.*">
        <mx:Script>
            <![CDATA[
                import mx.controls.Alert;
                public function addRemove():void{
                    //How do i add that component to the Panel?
            ]]>
        </mx:Script>
         <mx:Checkbox id="cb" change="addRemove()" label="Check or Uncheck"/>
         <mx:Panel  id="testPanel" x="0" y="0" width="100%" height="200" layout="absolute" borderThickness="0" borderThicknessBottom="0"/>
    Can you guide me what should go in the listener to add the component to the panel?

Maybe you are looking for

  • Setting LC (Letter of Credit)

    How to set LC functionality in SAP ?

  • Optical Drive suddenly not working

    Last week my MacBook 1,1 refused to play DVDs. This week, it refuses to accept blank CD-R's for burning music on iTunes. In the past, i could usually just try another CD as some appear faulty to begin with, but now the problem is systematic. I tried

  • ORA-06502 PL/SQL Error

    Hi All Currently I am working on .net based application and Oracle 8.0.6.00 (Multi language Support - (Japanese/English ))as backbend . The above mention error is occurring from last few days on our production server when user is trying to save data

  • Reason rewire question

    I have an instrument from Reason rewired into Logic and it works fine. But when I select a new track in Logic (eg piano), my instrument from Reason plays in addition to the piano. I've had this happen in the past but can't remember what to do! Is it

  • Time machine  how to delete all files?

    time machine:   how to empty and delete all files?