2 Replies Latest reply on Jan 23, 2009 8:19 PM by ntsiii

    Custom Flex Packages

    CaptainRedmuff
      Hi!

      This is my first post in these forums, but i have been dabbling with Flex for a few months now. Usually, i have had no problems finding answers to trivial problems via google, but this latest issue seems to be a lot harder to find any information for.

      I am trying to create a new package using Adobe Flex Builder 3. Let me just back up to the beginning of my process to outline the steps taken which have lead me to this problem.

      1) Opened Flex Builder, clicked File -> New -> Flex Project.
      2) Filled out the relevant project details in the wizard (selected Windowed Application) and called the project test_project.
      3) Clicked File -> New -> Actionscript Class, named the file test_class.
      4) Pressed F11 and ran the project. No Problems so far.

      At this stage, i added a script tag to include the actionscript class and once again pressed F11. This time i received the following error:

      1037: Packages cannot be nested.

      No amount of googling or searching adobe/air/flex resources has any information on how to fix this. I have only added one single line of code which imo is intirely valid. All the rest of the code has been generated by Flex Builder so i see no reason why i should be encountering this problem.

      Upon my travels through the vast amounts of results google threw up, i also saw mention that Classes cannot be declared in external AS files. Seeing that FB has the option to create a new Actionscript Classes as a .as file, i guess this is a null point?

      Are there any tutorials on creating packages? Are packages the same between flash and flex? A lot of the examples i've seen are all made using flash, i know they both implement AS3 but sadly i am unable to find any tutorials soley geared towards Flex. This makes me a sad panda :(

      Any help anyone can offer would be greatly appreciated. Thanks for reading.
        • 1. Custom Flex Packages
          rtalton Level 4
          Shot my mouth off too quick, sorry.
          I've got nothing.
          • 2. Re: Custom Flex Packages
            ntsiii Level 3
            You are trying to put a package and class into a *script* tag. When Flex compiles an mxml file, it first generates it into an AS class with its own package declaration. Thus, a package statement in the script becomes a nested package, wihch is illegal.

            If FLVplayer is a class, then you cannot use it in the source of a script tag. You must instanitate it like any class, either in mxml or in AS:

            <FLVPlayer id="flv" myProperty="myValue" .../>
            or
            var flv:FLVPlayer = new FLVPlayer();
            or make the methods static.

            Note: FLVPlayer is now a component with its own scope. It will not have automatic access to the sibling components under its parent. You will need to pass data in as args, or use the dom traversal properties, or events, to communicate with the parent.