Add change event to a custom MXML component

I am building an MXML project in Flash Builder 4.5
I have a custom MXML component that contains a TextInput field. I want the custom component to have a change event that triggers a function in the main application.
I created a test project to try and solve this.  At the moment, it appears to trigger an event once and then stops.  Please take a look and let me know where I am going wrong. Many thanks.
customComponent.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
           width="40" height="20">
    <mx:Script>
    <![CDATA[
        [Bindable]
        public var value:Number;
        protected function inputBox_clickHandler(event:KeyboardEvent):void
            if (event.keyCode == 38 ) {
                keyUp();
            if (event.keyCode == 40 ) {
                keyDown();
        protected function keyUp():void
            value = value++;
            dispatchEvent(new Event('change'))
        protected function keyDown():void
            value = value--;
            dispatchEvent(new Event('change'))
    ]]>
</mx:Script>
<mx:Metadata>
    [Event(name="change", type="flash.events.Event")]
</mx:Metadata>
<mx:TextInput id="inputBox" x="0" y="0" width="40" height="20"
              text="{value}"
              keyDown="inputBox_clickHandler(event)"
              change="dispatchEvent(new Event('change'))"
              />
</mx:Canvas>
main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            xmlns:CustomComponents="CustomComponents.*"
            minWidth="955" minHeight="600" layout="absolute">
<mx:Script>
    <![CDATA[
        private function changeTestLabel():void
            testLabel.text = String(myComponent.value);
    ]]>
</mx:Script>
<CustomComponents:customComponent x="180" y="183"
    id="myComponent" value="0"
    change="changeTestLabel()">
</CustomComponents:customComponent>
<mx:Label id="testLabel" x="165" y="206" text="Test label"/>
</mx:Application>

I have found the solution to this...
The clue was that it worked the first time a change was made, changing the value to the default '0'.
The problem was that the var value is type Number and the inputBox.text is type String.
I therefore added the following function:
  protected function textChange():void
   value = Number(inputBox.text);
   dispatchEvent(new Event('change'))
I also changed the  change="dispatchEvent(new Event('change'))"  property to
   valueCommit="textChange()"
... and that fixed it..
Thanks to all those who took the trouble to look at this

Similar Messages

  • Custom mxml component extending another mxml component

    I want to create a custom mxml component that extends another mxml component. Bacially I want structure like Group -> BaseMXMLComponent -> MyMXMLComponent. I understand that it used to be the case that trying to add child component to MyMXMLComponent would throw "Error: Multiple sets of visual children have been specified for this component (base component definition and derived component definition)." error. But i've been reading few articles that says this has been fixed in Flex 4.
    My question is.. is it an actually fixed, documented, and supported behavior of Flex 4? or just an undefined behavior that appears to be "fixed" but can change on future update?

    I dont know what is happening inside datagrid.But If
    you want to maintain a single instance you could use singleton design pattern
    read about it
    http://en.wikipedia.org/wiki/Singleton_pattern
        public class Singleton
            private static var instance:Singleton= new Singleton();
            public var userdata:*; // keep user object
            public function Singleton()
                if (instance != null) { throw new Error('Cannot create a new instance.  Must use Singleton.getInstance().') }
            public static function getInstance():Singleton
                return instance;

  • Initializing Custom MXML component

    Hello,
    I am new to flex and the one thing I can't seem to get a handle on is using custom mxml components. The whole not being able to use a constructor to pass data through was a tough thing to adjust to so for the most part I've been writing my own AS classes for display purposes that extend layout containers like VBox and such. This is getting cumbersome and I would really like to use MXML to save some time when writing display classes. For the most part I'm trying to use custom mxml components this way: I put the labels and other controls and then want data to display as text from the calling class. However, when I try to set the text it says that the control I am trying to set hasn't been initialized yet. My workaround is something like this.
    var data1:String = "Something";
    var customComp:CustomMXMLComponent = new CustomMXMLComponent();
    customComp.initialize();
    customComp.someControl = data1;
    Now why wouldn't someControl on the custom component be initialized when the actual component is initialized? Is there something I can change in the mxml component so that I don't always have to call .initialize() after creating an instance of the custom component?
    Thanks!

    .  The "initialize" stuff you had was more concerned with the lifecycle of the component.  We don't want to do that , but it is something you should learn about. I think the answer to your problem is to create Bindable variables in your mxml class,  then set those parameters.
    Observe
    <Panel>
      <Button label="{buttonLabel1}" >
      <Button label="{buttonLabel2}">
      <Label label = {labelLabel}>
      <Script>
         [Bindable]  public var buttonLabel1:String;
         [Bindable]  public var buttonLabel2:String;
         [Bindable]  public var labelLabel:String;
       </Script>
    </Panel>
    Meanwhile , in another class ...
    var customComp:CustomMXMLComponent = new CustomMXMLComponent();
    customComp.buttonLabel1 = "Ubuntu";
    customComp.buttonLabel2 = "Rocks";
    customComp.labelLabel = "My Socks";

  • 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 hide/unhide the all Treenodes on Treeview based on Checkbox changed event in Sharepoint custom webpart Sitecollections

    How to  hide/unhide the all Treenodes on Treeview based on Checkbox changed event?
    Checkbox(Control)
    1.Checkbox Checked:(Action below like)
     if user click on  Checkbox, all the treenodes on treeview is hide.
    2.Checkbox Unchecked(Action below like)
    If user uncheck the Checkbox  all the treenodes on treeview is unhode.
    Could you please help me how to do above one.
    Badri

    Hi,
    According to your post, my understanding is that you want to hide/show the TreeView when the Checkbox checked/unchecked.
    We can use jQuery to achieve it, the following script for your reference:
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    $("input[type=checkbox]").click(function () {
    if (this.checked) {
    $("#TreeViewID").hide();
    } else {
    $("#TreeViewID").show();
    </script>
    More information:
    http://dineshsharepoint.blogspot.com/
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Capture event from mxml component

    I have an accordian control in my main mxml application. Each
    item in the control is a custom mxml component that I created that
    consists of a label and some text. When the label is clicked, I
    need to fire off a message to the containing application with a
    string value. I'm not sure how to do this. Here's what I have right
    now. I'm not sure if I'm going down the right track but if I am,
    how do I pass the string argument with the event and then capture
    this event and the argument in the main application?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="200">
    <mx:Script>
    <![CDATA[
    private var _title:String = "";
    private var _desc:String = "";
    [Inspectable(defaultValue=true)]
    public function set Title(title:String):void{
    _title = title;
    public function set Description(desc:String):void{
    _desc = desc;
    private function SetMovie(url:String):void{
    dispatchEvent(new Event("MovieTitle"));
    [Bindable(event="MovieTitle")]
    ]]>
    </mx:Script>
    <mx:VBox>
    <mx:Label id="lblTitle" text="{_title}" width="190"
    click="SetMovie('testmovie.flv');/>
    <mx:Text id="txtDescription" text="{_desc}"
    width="190"/>
    </mx:VBox>
    </mx:Canvas>

    You have several issues, and several options here. First, a
    custom event can pass any data you want, and is not very hard to
    create.
    However, there is a still easier way. All of the Event
    objects have a "target" and "currentTarget" property which give you
    a reference to the object that dispatched the event.
    So, in your component, implement a public property, say like
    this:
    public function get Title():String{
    return _title;
    then in a handler function you can do:
    private function onMovieTitle(event:Event):void {
    var sMovieTitle:String = event.currentTarget.Title; //watch
    out for reserved words, though
    There are two ways to listen for an event. One easy way is to
    use a bubbling event. Some folks advise against bubbling event
    because of potential event name collisions, but this may not be a
    concern for you. It has not yet concerned me enough to make me
    avoid using bubbling.
    The other way is to declare handler on the component itself.
    Also, if you use a metadata tag, you can assign the handler on the
    mxml tag, instead of using addEventListener():
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="200">
    <mx:Metadata>
    [Event(name="MovieTitle", type="flash.events.Event")]
    </mx:Metadata>
    <mx:Script>
    Then, in you main app:
    <myComp id="mc1" ... MovieTitle="onMovieTitle" ...
    Without the metadata, you would do
    mc1.addEventListener("MovieTitle",onMovieTitle)
    Using a bubbling event:
    change the dispatchEvent to this:
    dispatchEvent(new Event("MovieTitle",true)); //the 'true'
    makes it bubble
    Then, in the main app, listen ON the main app(this):
    this.addEventListener("MovieTitle",onMovieTitle);
    Tracy

  • Dynamically add custom MXML components in Actionscript

    As there's no constructor for custom MXML components, how to
    dynamically add it as a child using ActionScript?
    I'm looking for some alternative to avoid the need to rewrite
    the entire existent component in ActionScript just to add it this
    feature (a constructor). PopManager is not an alternative...
    Is there any way?
    The case/situation:
    I have a custom MXML component that needs to be dinamically
    added to a NativeWindow created using ActionScript.
    Thanks a lot!
    Vicente Junior
    Independent Web Developer
    http://teclandoalto.blogspot.com

    mxml classes get generated into AS classes with a default
    constructor.
    In fact, there is essentially no difference between an AS
    component and an mxml component, they can be used exactly the same
    way.
    Tracy

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

  • Event in ActionScript Class not accessible by MXML Component

    I am implementing an ActionScript Class in my MXML Component,
    but it can't see the Event I'm specifying. I'm getting the
    following Error when I compile my application:
    Cannot resolve attribute 'myEvent' for component type
    myClass.
    How do I make the Event available to the MXML component?
    Thanks.

    Guess the compiler has a problem with semi-colons after the
    Event declarations. I removed the semi-colons, and was able to
    compile.

  • Changing custom AWT component to Swing component

    I created my own AWT component. I'd like to change it to Swing component.
    Does anyone know how to change or create a custom Swing component?
    Please also provide some framework to develop a custom Swing component.

    First try to know the difference between SWING & AWT. You can either adopt to SWING or AWT but be specific of what you want to do !
    If you like to migrate from AWT to SWING ,then make the necessary changes in your coding.(ie, re frame things like , Frame to JFrame , Button to JButton ,JTextField to JTextField etc..)
    For creating custom components ,say a component called MyLabel and you should design a class which extends JLabel and do whatever you like...
    eg import javax.swing.*;
    public class MyLabel extends JLabel
      MyLabel(String title)
         this.setTitle(title);
         this.setBackground(Color.white);
         this.setForeground(Color.blue);
    }For more details go to java tutorials.

  • Very simple library with one MXML component ERROR

    <?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"
                         mouseDown="FlexGlobals.topLevelApplication.nativeWindow.startMove()"
                         width="350" height="42" top="0" left="0" right="0">
              <s:states>
                        <mx:State name="maxed"/>
                        <mx:State name="restored"/>
              </s:states>
              <fx:Script>
                        <![CDATA[
                                  import flash.events.MouseEvent;
                                  import mx.core.FlexGlobals;
                                  private var maxed:Boolean = false;
                                  private function restore(e:MouseEvent):void{
                                            if (maxed){
                                                      FlexGlobals.topLevelApplication.restore();
                                                      this.currentState = "restored";
                                                      maxed = false;
                                            }else{
                                                      FlexGlobals.topLevelApplication.maximize();
                                                      this.currentState = "maxed";
                                                      maxed = true;
                                  public function Maximize() : void
                                            if (this.maxed)
                                                      FlexGlobals.topLevelApplication.restore();
                                                      this.currentState = "restored";
                                                      this.maxed = false;
                                            else
                                                      FlexGlobals.topLevelApplication.maximize();
                                                      this.currentState = "maxed";
                                                      this.maxed = true;
                                            return;
                                  }// end function
                                  public function get Maximized():Boolean{
                                            return this.maxed;
                        ]]>
              </fx:Script>
              <s:Rect left="0" top="0" bottom="0" right="0">
                        <s:fill>
                                  <s:SolidColor color="#FFFFFF"/>
                        </s:fill>
              </s:Rect>
              <s:Image x="5" y="-4" source="assets/colibright_title.png" left="5"/>
              <s:Button y="10" width="32" height="32" click="FlexGlobals.topLevelApplication.minimize();" icon="assets/icons/minimize.png" y.restored="5" y.maxed="5" right.restored="74" right.maxed="74"/>
              <s:Button width="32" height="32" click="restore(event)" y="5" icon="assets/icons/restore.png" includeIn="maxed" right="39"/>
              <s:Button y="5"  click="restore(event)"  includeIn="restored" width="32" height="32" icon="assets/icons/maximize.png" right="39"/>
              <s:Button y="10" width="32" height="32" click="FlexGlobals.topLevelApplication.close();" icon="assets/icons/close.png" y.restored="5" y.maxed="5" right.restored="5" right.maxed="5"/>
    </s:Group>
    In my main application when i try to load the SWF and use the Custom MXML Component i get this error
    [SWF] C:\Users\dude\Adobe Flash Builder 4.7\Colibr8\bin-debug\extensions\00 - WindowControlUIPlugin.swf - 8,287 bytes after decompression
    VerifyError: Error #1014: Class spark.components::Group could not be found.
    private function launchPluginsInspection():void{
                                  plLoader = new Loader();
                                  plLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPluginLoaded);
                                  var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
                                  context.allowLoadBytesCodeExecution = true;
                                  context.allowCodeImport = true;
                                  var appFolder:File = File.applicationDirectory;
                                  var extensionsFolder:File = new File(appFolder.nativePath + "/extensions/");
                                  if (extensionsFolder.isDirectory){
                                            var files:Array = extensionsFolder.getDirectoryListing();
                                            for each(var file:File in files){
                                                      if (file.extension == "swf")
                                                                plLoader.load(new URLRequest(file.nativePath), context);
    Why is this happening?

    Can you try giving permissions for the player to access your swf file by adding this
    Security.allowDomain( '<Location of the swf file>' );
    or  
    System.security.allowDomain( '<location of the swf file>' );
    Thanks,
    Sudhir

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

  • Custom AS3 Component / Event Definition for MXML Tag

    Custom AS3 Component / Event Definition for MXML Tag
    Exposing custom event in custom MXML tag.
    I have made an AS3 custom component named,
    'CustomListComponent'.
    Is a list type component extending UIComponent.
    When an item is clicked (selected) I generate a custom event
    named, 'selChange'
    I want the user to be able to use this tag, define a handler
    on the MXML tag.
    I tried using metadata like [Event("selChange")] in the
    component AS3 file with no luck.
    Any help / examples to expose a custom event from an AS3
    custom component to the MXML tag for the end user/developer would
    help significantly.
    Anyone? Thank you.

    Well, That did not take long.
    My mistake, Typo type.
    [Event(nane="selChange", type="flash.events.Event")]
    That is: naNe not naMe :(
    Thank you all for your time and responses.
    I WILL check my code more closely next time I post a
    question.
    P.S.: @VarioPegged : My code is big and not needed now. If
    you would like it anyway just message me. TY

  • Custom Pipeline Component stopped changing input filename

    Hi
    In my project, I have a custom pipeline component to change the input file name. I use it in the receive pipeline decode stage. It was working initially when I had only a receive pipeline and custom pipeline component in my solution. later I introduced
    two schemas, an orchestration, map and a send pipeline. The rename is not working anymore. Please help.
    receive adapter: FILE
    send adapter: FTP
    Custom pipeline component: (File Name Setter)
    Receive pipeline:
      decode: custom pipeline component to rename the filename
      disassemble: flatfile disassembler conecting to a document schema
    Map:
      Schema 1 to Schema 2 (transforms from Windows to Unix format)
    Orchestration:
      receive message
      transform using map above
      send message
      Exception Handler
    Send pipeline:
      FlatFile assembler
    manibest

    May be its not working now, because in the orchestration which you have added,
     you’re constructing a new message from the received message and the context properties from the Received message is not copied across to the newly constructed message. So when you use “%SourceFileName%” macro in the send port,
    the ReceivedFileName context property is missing in the newly constructed message which is sent out.
    So in your Orchestration, while constructing (in MessageAssignment shape) the outbound message from the Received message, copy the context property of the Received message to the newly constructed message. Something like this
    //This line copies all the context properties from received message to the outputted message
    msgOutputted (*)= msgReceived(*)
    //or
    //This line just copies the receive file name context property from received message to the outputted message
    msgOutputted (FILE.ReceivedFileName)= msgReceived (FILE.ReceivedFileName).
    If you’re not using the Orchestration or constructing the new message (even in map), then just add the schemas/orchestration or any pipeline would not affect the ReceiveFileName code. May be in this case, debug the pipeline and also check whether the outputted
    message has ReceivedFileName in its context property.
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

Maybe you are looking for

  • Wuf-209 failed in Forms 64bit (11.1.2.1.0)

    We are using webutil to try to write to the local LPT1 printer from our form. When we execute: WebUtil_File.Copy_File('c:users\temp\brick.txt', 'LPT1'); The file copy happens to the attached printer, but the "WUF-209: Copy file failed" error pops up.

  • Curiosity: How to use a table for input when testing a functionmodule?

    actually I am sick of writing test programs for every function I want to test using ABAP. So why it is (made) impossible to generate input data for a table as input parameter of a functionmodule? Has really nobody ever tested this stuff when the test

  • Suggestion on Good Books for SAP NetWeaver Administrator

    Hi, I am very new to SAP NetWeaver. Can any one please suggest some good books to learn SAP NetWeaver Administration. Is SAP NetWeaver For Dummies is good book to start with? I want to understand the SAP NetWeaver Architecture and also want to learn

  • Schema generate error ORA-04071

    I�m trying to generate a schema into SCM using jr_registration.generate(schema_name=>�NAME�);. Every time it fails with this error: ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword ORA-06512: at "REPOS_MANAGER.JR_GEN", line 4329 ORA-06512: at "

  • Using tcpdump...please help..

    Hi I want to use tcpdump to check a connection termination situation that occurs in my application. I read the documents and they say that the simplest way to use tcp dump is by typing tcpdump -i "interface name" But I am not able to find out what is