6 Replies Latest reply on Jan 3, 2011 9:19 AM by rtalton

    Flex 3 Passing Event Info via Metadata


      As an opener, I am a complete new Flex user and a total novice.  This is my first crack at it and first post.  Now my problem, I am modifying and updating some existing Flex 3 code using the SDK.  I have completed all updates save one, The Alert messages HAVE NEVER WORKED, so I am trying to get those working.


      The application uses a parent mxml file, FileUploadApp.mxml which sets the stage and a canvas.
      That file uses a subordinate mxml file, FileUpload.mxml does all the work and places items on the canvas.

      FileUpload.swf is created, then included in FileUploadApp.swf.  Everything works except the Alert messages.  Communication from FileUploadApp.swf is as two fold:


      1) variables and constants are defined in FileUploadApp and used by FileUpload.
      2) evemts are defined in FileUpload and passed back to FileUploadApp via metadata.  All events are being passed back except button/mouse events.


      FileUploadApp code:

      <mx:Canvas width="400" height="300" horizontalCenter="0" verticalCenter="0">
        width="100%" height="100%"
        uploadComplete="Alert.show('File(s) have been uploaded.', 'Upload successful')"
        uploadIOError="Alert.show('IO Error in uploading file.', 'Error')"
        uploadHTTPError="Alert.show('Upload Server Connection Lost.', 'Upload Failure')"
        uploadSecurityError="Alert.show('Security Error in uploading file.', 'Error')"
        btnCancel="Alert.show('You have canceled this upload.', 'Upload Cancled')"/>


      FileUpload code:

      [Event(name="uploadComplete", type="flash.events.Event")]
      [Event(name="uploadProgress", type="flash.events.ProgressEvent")]
      [Event(name="uploadCancel", type="flash.events.Event")]
      [Event(name="uploadIOError", type="flash.events.IOErrorEvent")]
      [Event(name="uploadHTTPError", type="flash.events.HTTPStatusEvent")]
      [Event(name="uploadSecurityError", type="flash.events.SecurityErrorEvent")]
      [Event(name="btnCancel", type="flash.events.MouseEvent")]
      btnCancel.addEventListener(MouseEvent.CLICK, onbtnCancelClick);
      var mevt:MouseEvent = new MouseEvent("btnCancel");
      <mx:Button id="btnCancel" toolTip="Cancel upload" icon="@Embed('assets/cancel2.png')" width="26" click="onbtnCancelClick()"/>


      When the "btnCancel" button is clicked, the user should get the Alert message "Upload Cancled'.  All the other Alerts from events except the button events are being displayed.


      Any help will be appreciated.

        • 1. Re: Flex 3 Passing Event Info via Metadata
          rtalton Level 4

          Just a suggestion, try changing the event type to flash.events.Event.

          It doesn't have to be a MouseEvent.

          • 2. Re: Flex 3 Passing Event Info via Metadata
            FishermanWilly Level 1



            Tried changing to :


            [Event(name="btnCancel", type="flash.events.Event")]


            Still did not work.


            Thanks anyhow, I would not have thought of trying that.

            • 3. Re: Flex 3 Passing Event Info via Metadata
              rtalton Level 4

              Your code looks like you are using a custom MXML component within your main app. Is this right? Your comments indicate you may be loading a swf file (module) into the main app...not sure which way you are doing this.


              Anyway, I tested this and had no problem passing the event from the child component into the parent.

              1 person found this helpful
              • 4. Re: Flex 3 Passing Event Info via Metadata
                FishermanWilly Level 1



                There are two mxml files:


                FileUploadApp.mxml => Sets the stage, some constants, some variables, all the Alerts from events and the canvas.


                There is a subordinate file, FileUpload.mxml =>  does all the work, has the images that are placed on the canvas and processes all events, but passes the events back to FileUploadApp.mxml to process the Alerts.


                FileUpload.mxml is compiled to FileUpload.swf and included into FileUploadApp.swf, all in the same compile.  Only FileUploadApp.swf is used in the Flash Player.


                Do no know why this path was chosen, as in my original message, this is code I am modifying and updating.  I have everything else running correctly except the Alerts.  I tried moving all Alert processing to FileUpload.mxml to avoid passing the event through metadata, but no joy.  The Alerts have to be processed where the original blank canvas is defined, that is FileUploadApp.mxml.

                • 5. Re: Flex 3 Passing Event Info via Metadata
                  FishermanWilly Level 1



                  After a lot of testing and research, I determined the alert messages in the subordinate mxml file were being built before he stage was finished, therefore they did not exist as far as the compiled .swf file was concerned.  Your question about the two mxml files was a very profound observation and pointed me to the basic cause of my problem.


                  Therefore, have rewritten the whole thing in one mxml file.  Works like a charm.  Many thanks for the clue.


                  One last question, what are the points (10 points for Correct answer, 5 points for Helpful answer) used for and what do they mean?


                  Thanks a lot,



                  • 6. Re: Flex 3 Passing Event Info via Metadata
                    rtalton Level 4

                    Glad you got it working. Note that a child component should be able to pass data to its parent, and this allows you to segregrate you code into reusable chunks.


                    The points system? I think it helps people see who provides good answers.

                    Also, it may be a secret back-door into Adobe employment. (Just a theory; I've never been contacted by Adobe regarding any of their cushy jobs. All they do is take my money and provide me with great software in return. I guess that's fair.)


                    Happy New Flex Year, everybody!