could not resolve <mx:String> - actionscript-3

I'm very new to the Flex Programming.
I was writing a sample program.
<?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>
<mx:String id="message">Hello, World</mx:String>
<mx:Label text="{message}"/>
</s:Application>
But getting an error "could not resolve to a component implementation"
I have the following queries.
What does , tags refers to.
why i'm getting the above error.Please help

This code should work:
<?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:String id="message">Hello, World</fx:String>
</fx:Declarations>
<mx:Label text="{message}"/>
</s:Application>
What I did was:
Changed your string to <fx:String>
Moved it into the <fx:Declarations> tag.
Reason:
It looks a little like you trying to compile with the Flex 4 SDK and are mixing a little of Flex 3 and Flex 4. Anything starting with the namespace "s" is a Flex 4 Spark components. Anything with the namespace "mx" is from Flex 3.
In Flex 3 you could declare variables in the code, right next to any visual component and they were all declared with the "mx" namespace. With Flex 4, they changed it so that declaring things that are not visual components (like variables) need to be placed in the <fx:Declarations> tag, which is why there is the comment "Place non-visual elements (e.g., services, value objects) here". They also changed the namespace of those non-visual elements to "fx".
There is some explaination in Flex 3 equivalent of ''?

Related

Flex4: how to create the view states in as class (code-behind)

According to this document from Adobe Create and apply view states is <s:State/> a state object.
How to create the view states in code-behind ActionScript class?
I have found a simple solution, and I don't have to declare the states using skinning architecture. I don't even to declare the states in my ApplicationClass which extends WindowedApplication.
The solution is: declare the states only in the Main.MXML and by all means with the right namespace, in my case it should be "custom".
Here is the Main.MXML:
<?xml version="1.0" encoding="utf-8"?>
<custom:ApplicationClass 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:custom="components.*">
<custom:states>
<s:State name="loginState"/>
<s:State name="infoState"/>
</custom:states>
<s:Panel id="loginPanel" title="Login" includeIn="loginState" />
</custom:ApplicationClass>
I only want to change between different Panels, so this method works well for me. There are certainly other cases, in which the states need to be declared in skinning.
I have got this solution form this link: Error: Could not resolve to a component implementation.

Enable Button only when 2 TextInput fields are not empty - code and screenshot attached

In a Flex mobile app (or any Flex 4 application) - how can you enable/disable a button depending on the contents of 2 other fields?
I am pasting my very simple test code below and the problem with it is the syntax error in Flash Builder 4.7: The entity name must immediately follow the '&' in the entity reference. - which probably means that ampersand is a special character, but how to solve this (probably frequent) problem?
TestApp.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
firstView="views.Home"
applicationDPI="160">
</s:ViewNavigatorApplication>
views/Home.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="How to enable Login button?">
<s:layout>
<s:VerticalLayout paddingTop="8"
horizontalAlign="center" gap="8" />
</s:layout>
<s:Label text="Username:" />
<s:TextInput id="_username" />
<s:Label text="Password:" />
<s:TextInput id="_password" />
<s:Button id="_login"
label="Login"
enabled="{_username.text.length > 0 && _password.text.length > 0}" />
</s:View>
You shall replace && with && when you write it outside of CDATA in mxml.
It is also better to use _username.text!='' instead of _username.text.length > 0 because it will cause warnings at runtime as text is not an eventdispatcher and it can't report length changes. However, it will update button's availablity because text will be changed itself and TextInput will report it causing binding update.
when using binding expressions. mxml does not consider && rather write your expression as
& amp ; & amp ;
....also mxml does not read escape characters e.g. \t for tab...rather write your expression in actionscript then use data binding .cheers ;-)

Flex Vertically Aligned Text Mac vs Windows

I am looking into an issue in a Flex application where on OS X text is shifted up a couple pixels compared to windows. Every text field is not vertically aligned to the middle it is more towards the top.
Found a thread here but no real solution http://forums.adobe.com/message/2189821
Anyone know how to solve this problem in a way that applies to both systems.
My approach would be to conditionally adjust component positioning when OS X is detected.
<?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"
preinitialize="onPreinitialize()"
>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function onPreinitialize():void
{
Alert.show((-1 != Capabilities.os.search(new RegExp('mac', 'i'))) ? 'Replace this Alert with code which adjusts text positioning in order for it to appear the same as when it runs on Windows.' : 'No need to adjust text', Capabilities.os);
}
]]>
</fx:Script>
</s:Application>

Creating A dynamic grid of input areas in Flashbuilder 4.6

I'm trying to make an application with flash builder that performs operations on square matrices. I take in the size of he matrix (n) but now, I am having difficulty figuring out how to generate an n by n grid of text inputs where the user can enter the matrix element values
Yeap, do just like Peter Hall said. Use DataGroup with tile layout.
<s:DataGroup itemRenderer="Groups.DataGroupRenderer">
<s:layout>
<s:TileLayout horizontalGap="5" verticalGap="5" requestedRowCount="3" requestedColumnCount="3"/>
</s:layout>
<s:dataProvider>
<s:ArrayCollection>
<fx:String>1</fx:String>
<fx:String>2</fx:String>
<fx:String>3</fx:String>
<fx:String>4</fx:String>
<fx:String>5</fx:String>
<fx:String>6</fx:String>
<fx:String>7</fx:String>
<fx:String>8</fx:String>
<fx:String>9</fx:String>
</s:ArrayCollection>
</s:dataProvider>
</s:DataGroup>
And renderer:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:TextInput text="{data}"/>
</s:ItemRenderer>
Of course if you know Flex at least in basic level, you will know how to do it all dynamically.
Use a DataGroup with a TileLayout.

AmChart component is not rendering (AIR app)

Our AIR app consists from multiple modules. Each module extends MovieClip class. But when I am adding AmChart component to one of these modules, it is not rendering. Here the sample (PieChart.mxml):
<?xml version="1.0" encoding="utf-8"?>
<s:SkinnableContainer 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:amcharts="http://www.amcharts.com/com_internal"
width="100%" height="100%">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var chartData:ArrayCollection = new ArrayCollection([
{country:"Czech Republic",litres:156.90},
{country:"Ireland",litres:131.10},
{country:"Germany",litres:115.80},
{country:"Australia",litres:109.90},
{country:"Austria",litres:108.30},
{country:"UK",litres:99.00},
{country:"Belgium",litres:93.00}]);
]]>
</fx:Script>
<amcharts:AmPieChart width="100%" height="100%" dataProvider="{chartData}" titleField="country" valueField="litres"/>
</s:SkinnableContainer>
And this is a sample usage:
var chart:PieChart = new PieChart();
cContainer.addChild(chart);
cContainer - is instance of MovieClip.
Can you suggest why this is not rendering? Maybe this seems a silly question, but I am a quite newbie to Flex. Please, help.
You may want to try using the dataset syntax used here http://blog.amcharts.com/2010/11/amstock-flex-tutorial-part-1-basics.html, and also try using a number for width and height until you get it working, rather than a percentage. If neither of those works, you may want to try asking the people who wrote this.
HTH;
Amy