Classes must not be nested - MXML - apache-flex

I'm trying to build a simple FLEX application. Unfortunately, I get '1131: Classes must not be nested.' errors even with the simples MXML .... the error pops out at the mx:Application openning tag:
(I'm using PureMVC if it's important)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:view="icm.view.components.*"
viewSourceURL="srcview/index.html"
name="ICM"
layout="absolute"
> //FLEX BUILDER SAYS THE ERROR IS HERE
<mx:Script>
<![CDATA[
import mx.effects.easing.Exponential;
import icm.ApplicationFacade;
public static const NAME:String = "AppSkeleton";
private var facade:ApplicationFacade = ApplicationFacade.getInstance(NAME);
]]>
</mx:Script>
<mx:Move id="slideInEffect" yFrom="5000" easingFunction="{Exponential.easeOut}" duration="1300"/>
<mx:Fade id="fadeOut" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:Fade id="fadeIn" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>
<mx:Style source="css/yflexskin.css" />
<mx:Canvas id="mainViewStack" left="0" top="0" right="0" bottom="0" >
<mx:ViewStack id="vwStack" left="0" top="0" right="0" bottom="0" resizeToContent="false" creationPolicy="auto">
<mx:VBox />
<view:SplashScreen id="splashScreen" showEffect="{slideInEffect}" hideEffect="{fadeOut}" />
<view:LoginScreen id="loginScreen" showEffect="{fadeIn}" />
<view:MainScreen id="mainScreen" showEffect="{fadeIn}" />
</mx:ViewStack>
</mx:Canvas>
</mx:Application>
Can someone help me understand why? I've being doing a lot of non-sense tests because I'm not understanding it.
Sometimes if I remove the Script section the compilation suceed, others not.
Thanks

Thank you all for the comments.
The greatest tip at this topic is: build with the SDK!!!
Flex Builder (both, the IDE and the Plugin) seems to lack a lot of features on error treatment and even when it reports an error it's not reliable.
A prompt window for compiling used with the IDE saved me a lot of headaches.
Thank you all again!

I had this problem using a compiler option to exclude/include some code
like -define+=CONFIG::myOption,true
when the option is true (resulting including some code), and you have such thing into your code :
CONFIG::myOption {
import <a package>;
}
this will result in a 1131 error... I have no workaround but not using such conditional compilation directives.

There is a flex compiler option "Enable Strict type checking" just de-select it. I think that can give so a simple solution....

http://blog.gigantt.com/2011/02/how-to-build-flex-sdk.html
Building
Let's create a batch file to set some useful envars: envars.bat
set JAVA_HOME=c:\Program Files\Java\jdk1.6.0_23
set PATH=c:\dev\ant\bin;%PATH%
set ANT_OPTS=-Xmx256m
Open cmd.exe and run it...
Edit c:\dev\sdk\frameworks\build.xml
Look for:
And fix the location of the manifest file from:
"${datavis.dir}/manifest.xml" to:
"${datavis.dir}/manifest_datavisualization.xml"
Run Ant:c:\dev\sdk\frameworks> ant
It should end with such a message: BUILD SUCCESSFUL
Now let's tell Flash Builder where to find this new SDK: c:\dev\sdk
Add it to the "Installed SDKs" settings in Flash Builder
Make sure your project is configured to use this SDK (it was probably created with the original one and still refers to it).
Rebuild your project. It should work.

Related

Flex: empty window on HelloWorld app

I'm totally new to flex and tried to create helloWorld app unsuccessfully.
Steps:
1) Create flex project within flash builder;
2) Added <s:Label text="Hello World" x="100" y="100" /> to HelloWorld.mxml file in default package;
3) runned project with Flash Builder;
4) saw an empty flash page in browser window;
Did I miss something?
HelloWorld.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label text="Hello World" x="100" y="100" />
</s:Application>
P.S.
- Flash Builder 4.6;
- SDK 4.5.1;
- Other flash page do work correctly in browser (Chrome);
Ok, reposted from comment.
Did you try to open this swf in different browser?
Make sure to clear browser cache when your swf is not opened anywhere, and you
can try to delete files manually.
Sometimes it's easy to forget to save edited file, this isn't your case, is it?
Reliable approach to
see if your swf is updated or not is to Alert.show('version') or to
draw big red line across your app with graphics.

Multiple initializer values in Flash Builder

Finally decided to try Flash Builder rather than FlashDevelop and got caught up on my very first app. I'm building a AIR app and downloaded the latest SDK and installed it in the Flash Builder path.
When I add a few simple items they all get errors. I added this code:
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingTop="10"/>
<s:Label id="myLabel" text="Some text stuff I typed."/>
<s:Button click="myLabel.text='Some stuff the button typed'"/>
</s:layout>
And I get an error on each spark item (except layout) that says:
In initializer for 'layout', multiple initializer values for target type spark.layouts.supportClasses.LayoutBase.
I've searched google with no real results. Does anyone know what this error is telling me? Is there a problem with the SDK installation? I followed install instructions from a Lynda.com vid.
Thanks for the help!
Not sure which Flex SDK or Flash builder version you are working with but in version 4 try this,
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingTop="10"/>
</s:layout>
<s:Label id="myLabel" text="Some text stuff I typed."/>
<s:Button click="myLabel.text='Some stuff the button typed'"/>
You create the components after the closing layout tag not inside it.

How to load and run a Flex3 SWF inside Flex4 or vice versa?

I am interested in understanding how to run a Flex-3 SWF inside a Flex-4 SWF.
My Flex-4 host app looks like this:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<mx:SWFLoader source="SimpleFlex3App.swf" loadForCompatibility="true"/>
</s:Application>
And this is the Flex-3 app:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="400">
<mx:Script>
<![CDATA[
private function onClick():void
{
labelField.visible = true;
}
]]>
</mx:Script>
<mx:Button label="Click Me" click="onClick();" horizontalCenter="0" verticalCenter="-20"/>
<mx:Label text="Clicked" visible="false" id="labelField" horizontalCenter="0" verticalCenter="20"/>
</mx:Application>
I get a null object reference where the SWFLoader tries to set up the bridge. I assume it does not get an instance for the IMarshalSystemManager implementation.
IMarshalSystemManager(sm.getImplementation("mx.managers::IMarshalSystemManager")).addChildBridge(_swfBridge, this);
By using the SWFLoader and setting loadForCompatibility to true I was following the adobe documentation:
I must be missing out on something very simple as both, my host and hosted apps, basically don't do anything special.
Further, is it possible to do the opposite and run a Flex-4 based SWF inside a Flex-3 one? In my opinion the adobe doc does not clearly say yes or no.
Thanks.
Flex harUI provided the correct answer here at the adobe forum.
Thanks!
It is possible to do as I built an application that can load AS2 swfs into a Flex 3 SWF.
You may need to set the trustContent property to false. This will mean you swfs are in separate security domains, and communication between the two will need to happen over a shared event bridge, local connection or custom sockets.
Have a look here for more info on this http://www.pixelbox.net/2009/02/11/sub-application-communication-in-air/

I can't get MXMLC to work on Ubuntu

Okay, I downloaded the Flex 4 SDK from Adobe and extracted the contents to ~/Documents/flex4_sdk.
Now I have the following simple MXML file:
<?xml version="1.0"?>
<!-- usingas/StatementSyntax.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Label id="label1"/>
</mx:Application>
When I compile it with mxmlc /path/to/file.mxml, I get:
Loading configuration file ~/Documents/flex4_sdk/frameworks/flex-config.xml
/path/to/file.mxml (38642 bytes)
However, the resultant SWF file is blank. (Basically just a white canvas.)
I get the same results if I Try to compile similar code using Flash Builder on Windows.
Try to give the label a value so there is actual a visual piece on your application
<mx:Label id="label1" text="Label1"/>
If at all possible I strongly recommend using the Flex 4 spark Application instead of the old mx approach. Your app might look like this:
<s:Application 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:Label text="label1" />
</s:Application>

Importing a SWC for a Flex Project in Flash Develop

I just started using flashdevelop for flex apps (I had been using it for pure as3 projects previously). I can't figure out how to import files and such. I have included them to the library as usually. In this case I have included flexlib.swc and flexmdi.swc. Both are in my lib folder and both have been right clicked and Added to the Library.
Auto complete does not work so I think I am missing a step.
This is my code:
`
<flexmdi:MDICanvas id="mdic" width="500" height="500">
<flexmdi:MDIWindow id="win1" title="Window One" x="10" y="10">
<samples:SampleContent />
</flexmdi:MDIWindow>
<flexmdi:MDIWindow id="win2" title="Window Two" x="250" y="250">
<samples:SampleContent />
</flexmdi:MDIWindow>
<flexmdi:MDIWindow id="win3" title="Window Three" x="100" y="100">
<samples:SampleContent />
</flexmdi:MDIWindow>
</flexmdi:MDICanvas>
`
I also tried to add
<mx:Script>
<![CDATA[
import flexmdi.containers.MDICanvas;
import flexmdi.containers.MDIWindow;
]]>
</mx:Script>
I also get a strange error saying flexmdi:MDICanvas is not bound.
I might be way off here because we're talking about FlashDevelop, but I'm pretty sure you need to add the namespace for the MDICanvas in your MXML root tag, like this:
<?xml version="1.0" encoding="utf-8"?>
<MDICanvas xmlns="flexlib.mdi.containers.*" xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
...
</MDICanvas>
The import statements only apply to .as files or <mx:Script> sections of your MXML code.
Death by repetition, but Flex has two ways to import classes and packages. The MXML way and the AS3 way.
Unfortunately, the latest stable releases of FlashDevelop does not support code completion in MXML, although the feature is fully implemented in AS (you can browse packages in libraries with code completion in actionscript).
If you need help with MXML, I suggest keeping the library's API open side-by-side with FlashDevelop (it's what I prefer to do anyway). Still, you need to make sure that you include all of the XML namespaces. For example, for the Degrafa graphics library, you need to include
xmlns:gfx="http://www.degrafa.com/2007"
in the tag (there is also a similar namespace definition for the namespace "mx" already there).
However, MXML code completion is hopefully going to be implemented in a stable release very soon, and there have already been some ways to get it working.

Resources