7 Replies Latest reply on Sep 1, 2010 2:04 AM by kiran7881

    Anybody please paste this code in your Flex Builder 3 and try this

    kiran7881 Level 1

      Hi ,

       

      It has been almost a 10 days since i am trying with this example .
      Could anybody please test this code in their Flex Builder 3 and let me know the problem where exactly it is happeing .

       

      Because eyeballing for debugging is not helping this to solve .

       

      So please paste this paste of code in your Flex builder and once try this .

       

      Passing Data with Custom Events and Componnets .

       

      This program is all about , When a User is logged in , another Custom  component called welcome.mxml dsiplays Hello User Name .

       

      Event class :

       


      package events
      {
          import flash.events.Event;
         
          import vo.User;
          public class LoginEvent extends Event
          {
              public var user:User;
              public static const LOGIN_EVENT:String = "LoginEvent";

             
             
              public function LoginEvent(type:String,userData : Object,bubbles:Boolean = true, cancelable:Boolean = false)
              {
                  super(type,bubbles,cancelable)
                  this.user = user;
              }

             
      override public function clone():Event
              {
                  return new LoginEvent(type,user, bubbles, cancelable);
              }



          }
      }

       

      VO Object :

       

      package vo
      {
          public class User
          {
             
              public var userName:String;
              public var password:String;
             
              public function User()
              {
              }

       

          }
      }

       

       

      Where the User Actually Logs in :

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

       


      <mx:Script>
          <![CDATA[
              import comps.Welcome;
              import mx.controls.Alert;
              import mx.modules.ModuleLoader;
              import vo.User;
              import events.LoginEvent;
              public var user:User = new User();
              public function CallMe():void
              {
              
                  user.userName = UITI.text;
                  user.password = PWDTI.text;
                 
                  var wel:Welcome = new Welcome();
                  
                  wel.addEventListener("ready", onReady);
              }
              public function onReady(event:LoginEvent):void
              {
      systemManager.dispatchEvent(new LoginEvent(LoginEvent.LOGIN_EVENT,user));        
           }

       

             
          ]]>
      </mx:Script>
         
          <mx:Form x="183" y="179">
              <mx:FormItem label="Label">
                  <mx:TextInput  id="UITI" />
              </mx:FormItem>
              <mx:FormItem label="Label">
                  <mx:TextInput id="PWDTI"/>
                  <mx:Button label="Button" click="CallMe()"/>
              </mx:FormItem>
             
             
          </mx:Form>
         
      </mx:Application>

       


       

      Greeting Page (Welcome.mxml)

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"  preinitialize="listen()">
         

       

             
          <mx:Script>
          <![CDATA[
              import mx.controls.Alert;
              import vo.User;
              import events.LoginEvent;
                  public function listen():void
                  {
                      Alert("Hai");
                      systemManager.addEventListener(LoginEvent.LOGIN_EVENT , datahandling);
                  }
                 
                  public function datahandling(event:LoginEvent):void
                  {
          var user : User= event.user as  User
          Alert.show(user.password);
         
                  }

       


             
          ]]>
      </mx:Script>

       

       

       


         
         
          </mx:Canvas>

       

       

      Thanks, please try this .

        • 1. Re: Anybody please paste this code in your Flex Builder 3 and try this
          flex4 Level 2

          Hi Kiran

           

                            I am sorry to say this .... U need to improve ur coding standards and flex component usage and custom components usage and event lifecycle.. Please have a very good knowledge in these areas and then start u r coding .. No one will reply for this post because this code is entirely wrong coding standard...

           

           

                     1)       The main wrong here is with out firing any event how can u listen this event

           

           

                                                     wel.addEventListener("ready", onReady);    //Here what is ready how can it consider this string ... what event  that flex want to listen..

           

           

               2)  The second wrong thing is

           

                 public function LoginEvent(type:String,userData :  Object,bubbles:Boolean = true, cancelable:Boolean = false)
                  {
                       super(type,bubbles,cancelable) 
                      this.user = user;   // what is this user .... u have mentioned userData in that constructor .but here u assigned user.. what is this user....
                   }

           

                         3)The Third thing is

           

           

           

                                                                 The custom component this is not a right way of using custom compoenent .. here where u are displaying this custom component on the screen , weather it is pop up or u are displaying this in the same application state of u are displaying in the anther sate .. what is this mean

           

                  public function CallMe():void
                  {
                  
                       user.userName = UITI.text;        // Where u are sending this two values u need to assing these values to custom event
                      user.password = PWDTI.text;   // where is ur custom event ...  dispatched  
                      
                      var wel:Welcome = new Welcome();
                      
                       wel.addEventListener("ready", onReady);//  what is this mean "ready"
                  }

           

           

          4)The forth one is

           

                              wel.addEventListener("ready", onReady); 

           

                              and

           

           

                                  public function onReady(event:LoginEvent):void
                                      {
                                   systemManager.dispatchEvent(new  LoginEvent(LoginEvent.LOGIN_EVENT,user));        
                                        }

           

                                   when u want to listener listen an event the event must be same type .. in add event listener u are using "ready " event and in the event listener function u are using LoginEvnetType how can it listen  to u r event

           

           

           

                   so my suggesstion is to lear flex full fledge and lear coding standards first then start programming .. mainly using events and components in flex application,,,

           

           

                                             sorry to say this... if u are posting like this no one give u reply Because this is a entirely wrong coding style....

           

           

           

          Thanks

          Ram

          • 2. Re: Anybody please paste this code in your Flex Builder 3 and try this
            kiran7881 Level 1

            here i may make a mistake , because of making changes a number of times , considering all the suggestions from the Forums .

             

            But when i took the code yesterday what you suggested , it still didn't worked .

             

            Can you please make me this code work for me . Because after this only i can start with Flex Modular Program .

             

            Can you please post this working code for me .

            • 3. Re: Anybody please paste this code in your Flex Builder 3 and try this
              flex4 Level 2

              Hi Kiran

               

                        First give me one clarification where that welcome custom component displaying... weather it is popup or any thing that is displayed in another state..

              • 4. Re: Anybody please paste this code in your Flex Builder 3 and try this
                ShardulSingh Level 3

                Hi,


                I have given the explanation for your problem. Your approach is totally wrong. You are using the application as a Login window. In this case where you will go after loging. Please make Login window simply a popup and on successfull login move to any part or overall application and finish that popup. check you log I have already given the solution with total code to you around one week earlier.

                 

                 

                 


                with Regards,
                Shardul Singh Bartwal

                • 5. Re: Anybody please paste this code in your Flex Builder 3 and try this
                  kiran7881 Level 1

                  I am sorry for the late reply ,


                  I am doing this Application for my Practice Purpose only , so not bothered about best Pratices currently , and i dont want to use states also .

                   

                  What i want is login from a Maion MXML file , and recive that data in another component taht is Welcome.mxml .

                   

                  THis welcomem.mxml is a seperate Component developed based on (FlexBuilder --New MXML Component) 
                  This is the way i want to do as i i am currently practicing how to pass data using Events
                  • 6. Re: Anybody please paste this code in your Flex Builder 3 and try this
                    ShardulSingh Level 3

                    Hi,

                    This is the thread pls check this, it was just for you.

                     

                    http://forums.adobe.com/message/3065975#3065975

                     

                     

                     

                     

                     

                     

                     

                     

                    with Regards,

                     

                    Shardul Singh Bartwal

                    • 7. Re: Anybody please paste this code in your Flex Builder 3 and try this
                      kiran7881 Level 1

                      I am completely new to Flex , pratcing it to be as you .

                       

                      So currently , I am learning , how to use Passing Componnets , using Events .
                      Not bothered about States and PopUpManagers .

                       

                      PLease modify my programs nad post the working code .