I have a component library. It has a manifest file that looks like this:
<?xml version="1.0"?>
<componentPackage>
<component id="AutoComplete" class="be.edge.components.AutoComplete" />
<!-- more components left out for brevity -->
</componentPackage>
I compile the library through FlashBuilder with these compiler settings:
When I use the compiled library in other FlashBuilder projects everything works as expected. I get code completion and when I select a suggestion from the code completion a namespace attribute is automatically added to the component, like this:
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:ns="library://ns.edge.be" >
<ns:AutoComplete />
</s:Skin>
But: FlashBuilder automatically creates the prefix 'ns'. I would like to customize this to 'e' for instance. How can I make FlashBuilder use this custom prefix by default?
I have two reasons for this:
'ns' doesn't say anything: it just says A namespace has been used, not what namespace.
when I use other libraries that also start with a url like 'library://ns.' FlashBuilder will probably start numbering the prefixes to resolve the conflict (ns, ns1, ns2, etc.), which would be even more confusing.
EDIT:
I also pass a config.xml to the compiler that has the following declarations relating to namespaces:
<compiler>
<namespaces>
<namespace>
<uri>library://ns.edge.be</uri>
<manifest>manifest.xml</manifest>
</namespace>
</namespaces>
</compiler>
<include-namespaces>
<uri>library://ns.edge.be</uri>
</include-namespaces>
This used to work:
Create a file called design.xml in your /src folder:
<?xml version="1.0" ?>
<design>
<namespaces>
<namespace prefix="mangos" uri="http://com.mangofactory.sample/mxml/2010" />
</namespaces>
</design>
Create a file called manifest.xml in your /src folder:
<componentPackage>
<component id="MyClass" class="com.mangofactory.framework.MyClassTag"/>
</componentPackage>
Configure your Namespace URL, etc in the build properties:
This is supposed to cause flash builder to prompt as follows:
<?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"
xmlns:mangos="http://com.mangofactory.sample/mxml/2010">
<fx:Declarations>
<mangos:MyClass />
</fx:Declarations>
</s:Application>
(Note that the class appears as MyClass instead of MyClassTag, and the namespace appears as mangos)
However, I just tried doing this, and although the class was renamed correctly, the namespace appeared up as ns. I know this used to work in FB3.x, maybe I've either forgotten a step, or FB4.5 has broken it.
If you just change xmlns:ns to xmlns:e or xmlns:foo then the MXML parser will pick up on the change. It's not all that difficult to change, and I don't think there is a way to change how it generates namespaces by default.
Related
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.
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>
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.
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.
I have an actionscript file that defines a class that I would like to use inside a Flex application.
I have defined some custom controls in a actionscript file and then import them via the application tag:
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:scorecard="com.apterasoftware.scorecard.controls.*"
...
</mx:Application>
but this code is not a flex component, rather it is a library for performing math routines, how do I import this class?
You'd need to import the class inside a script tag.
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import com.apterasoftware.scorecard.controls.*;
// Other imports go here
// Functions and other code go here
</mx:Script>
<!-- Components and other MXML stuff go here -->
<mx:VBox>
<!-- Just a sample -->
</mx:VBox>
</mx:Application>
Then you'll be able to reference that class anywhere else in your script tag. Depending on how the class is written you may not be able to use binding within the MXML, but you could define your own code to handle that.
Namespace declarations are only used to import other MXML components. AS classes are imported using the import statement either within a Script block or another AS file.
#Herms: To clarify a little, namespace declarations can be used to "import" AS classes as well, when you're going to instantiate them using MXML.
For example, consider having a custom visual component you've written entirely in AS, let's say com.apterasoftware.scorecard.controls.MathVisualizer. To use it within MXML:
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:aptera="com.apterasoftware.scorecard.controls.*">
<aptera:MathVisualizer width="400" height="300" />
</mx:Application>