9 Replies Latest reply on Nov 15, 2007 8:24 PM by bitwyse

    Application casting error

    Tom L
      I'm trying to set a class to centralized event handling. I'm using the model from the Flex 2 Beyond the Basis cd, but ran into a problem. I'm getting an error from a line of code I copied from the CD, but don't what to do, since the example on the CD runs without error. The line of code would appear simple, since it's just setting up a private variable in the class and casting Application.application to CentralEvents type. Here's the code from the skeleton of the class. Can anyone tell me what's wrong?

      package controller
      {
      import mx.core.Application;
      import mx.controls.Alert;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;

      public class FrontController
      {
      private var app:CentralEvents = Application.application as CentralEvents;

      public function FrontController()
      {

      }
      }
      }
        • 1. Re: Application casting error
          levancho Level 3
          there is something wrong or missing what is CentralEvents?
          is that maybe a main mxml file?
          • 2. Re: Application casting error
            Tom L Level 1
            To be honest, I'm not exactly sure why the cast of the Application.application value. As I mentioned, I took the code from the Training CD. According to the narrator, he's setting up the app variable to be an instance of the current application. He later uses the app variable to set up addEventListeners inside the constructor method for the class. By having an instance of the application in the class the code was able to value bindable variables found in the main mxml form.
            The goal of the exercise was to set up the class to handle all event operations from a central class. It made sense to me and since I had the code from the examples I decided to try it.
            That said, when I look at the syntax of casting the type of the variable to CentralEvents, it looks OK

            Thanks for responding and if you have an good ideas please let me know.
            Tom
            • 3. Re: Application casting error
              bitwyse Level 1
              Look at the import statements from the sample app. Somewhere there must be an import for CentralEvents
              • 4. Application casting error
                levancho Level 3
                most likely in your examples video/file file name is called CentralEvents.mxml which is main mxml file.

                remember filename turns into a legal datatype during runtime, so it seems your main mxml file is named differently than :"CentralEvents.mxml"
                • 5. Re: Application casting error
                  Tom L Level 1
                  Levancho,
                  Bingo! you got it and I missed it completely. As long as your on a roll I wonder if you could take a look at another post I made that deals with an error I'm getting when I try to use a font I built in flash. Here's the code: and the error message is "Font Poetica Std with normal weight and regular style not found. I followed all the direction about how to build the font and the code is straight from the book. I'm at a loss. Hope you can do your magic once again.
                  Thanks
                  Tom

                  <mx:Style>
                  @font-face
                  {
                  src:url("assets/poetica.swf");
                  fontFamily: 'Poetica Std';
                  font-weight:normal;
                  font-style:normal;
                  }
                  .mamTitle
                  {
                  fontFamily: 'Poetica Std';
                  fontSize: 55pt;
                  color: #FFFFFF;
                  }
                  </mx:Style>
                  • 6. Application casting error
                    levancho Level 3
                    honesty I have not done much fonts in flex, but (speculating) looks like that font does not support bold etc ... (sometimes there is more then one font required to support whole suite (bold, italic etc ...) maybe I am completely off since I have not done any fonding in flex.

                    btw you dont have to build swf to have custom font you can also just paste that fond file probably ttf in assets directory and then do :
                    @font-face
                    {
                    src:url("assets/poetica.ttf");
                    fontFamily: 'Poetica Std';
                    font-weight:normal;
                    font-style:normal;
                    }
                    • 7. Re: Application casting error
                      Tom L Level 1
                      Thanks for the suggestion, I'll give it a try. Just want to thank you and Bitwyse for your help in this matter. Starting from scratch with Flex has been no easy task, but I'll try and hang in there.

                      Tom
                      • 8. Re: Application casting error
                        levancho Level 3
                        Tom L - its well worth it to stay with it :)
                        afeter month you will feel no pain, once you get your mind adjust to the way flex works.
                        • 9. Re: Application casting error
                          bitwyse Level 1
                          I too am fairly new with Flex. I love it. It is very frustrating at times learning a new framework. But it's worth the effort. I truly love working with Flex.

                          Stay with it. Things do get easier after a few months. There are lots of smart folks on this site that can help as well.

                          Good luck. . . .