I am getting a value in a MXML... now i need to pass it to another MXML to invoke an event... how can i do it.
It can be done like this
Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public var a:String;
]]>
</mx:Script>
</mx:Application>
Test2.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public var a1:String;
public var te1:Test=new Test();
public function init():void{
a1=te1.a;
}
]]>
</mx:Script>
</mx:Application>
this is not right i think but it may serve your purpose
Assuming one MXML component is the child of the other, you should be using binding to pass data around.
You could dispatch an event containing the string value from the source component to be received by the destination component.
You need to explain more about how your two mxml components relate to each other... parent/child? two siblings within a parent? That will determine the best approach. Of course, your components should not really be "wired into each other" if possible, which is where frameworks such as Mate come in, but that is probably way beyond where you're at just now.
Related
So, i've got three HTTPService calls for three different XML files:
<mx:HTTPService id="projectsHttp" url="projects.xml" resultFormat="e4x" makeObjectsBindable="true" result="countProjects(event)" />
<mx:HTTPService id="studentsHttp" url="students.xml" resultFormat="e4x" makeObjectsBindable="true" result="createStudentsCollection(event)" />
<mx:HTTPService id="dprepHttp" url="directorsPrep.xml" resultFormat="e4x" makeObjectsBindable="true" result="createPhase(event)" />
The first two work great... but that last one just won't work. For testing purpose, the createPhase function looks like this:
public function createPhase(e:ResultEvent):void
{
Alert.show("Testing");
}
Also, the directorsPrep.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<directorspreps>
<directorsprep>
<prepid>1</prepid>
<title>dir. prep. 1</title>
<workingtitle>dp1 WT</workingtitle>
<startdate>7/7/2011</startdate>
<numdays>2</numdays>
<positions>
<role>1D</role>
<role>2D</role>
<role>1C</role>
</positions>
</directorsprep>
<directorsprep>
<prepid>2</prepid>
<title>dir. prep. 2</title>
<workingtitle>dp2 WT</workingtitle>
<startdate>7/10/2011</startdate>
<numdays>3</numdays>
<positions>
<role>1D</role>
<role>2D</role>
<role>1C</role>
<role>GE</role>
</positions>
</directorsprep>
</directorspreps>
Anybody see anything that would prevent the directorsPrep.xml file from not loading?
EDIT:
I'm a moron... Didn't do the .send(); :( Sorry for the time waster
It is tough to say for sure. I created a little project in Flex3 that includes your XML file and it worked fine for me. You should add a fault handler to know why it is failing. Put a breakpoint in that handler if you need to examine things. Also, make sure that you are calling send() in order for that XML file to get loaded. Here is an example of what was working for me (including the fault handler).
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public function createPhase(e:ResultEvent):void
{
Alert.show(e.result.toString());
}
protected function createPhaseFailed(e:FaultEvent):void
{
Alert.show(e.message.toString());
}
]]>
</mx:Script>
<mx:HTTPService id="dprepHttp" url="directorsPrep.xml" resultFormat="e4x" makeObjectsBindable="true"
result="createPhase(event)" fault="createPhaseFailed(event)" />
<mx:initialize>
<![CDATA[
dprepHttp.send();
]]>
</mx:initialize>
</mx:Application>
Good luck!
I am working on an air-application but written in as3.
How can I still display an fileSystemList-Component(flex) written in actionscript?
Thanks
fileSystemList i also Available for AIR Since AIR1.1 see API
also see About file system controls
EDITED Please find AIR APP sample using action script to Create FileSystemDataGrid
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="{onCreationComplet()}">
<mx:Script>
<![CDATA[
import mx.controls.FileSystemDataGrid;
private var fileSystemDataGrid:FileSystemDataGrid;
private function onCreationComplet():void
{
fileSystemDataGrid = new FileSystemDataGrid();
fileSystemDataGrid.directory = File.desktopDirectory.resolvePath('');
fileSystemDataGrid.percentHeight = 100;
fileSystemDataGrid.percentWidth = 100;
this.addChild(fileSystemDataGrid);
}
]]>
</mx:Script>
</mx:WindowedApplication>
Hopes that helps
Please enlighten this flex noob. I have a remoteobject within my main.mxml. I can call a function on the service from an init() function on my main.mxml, and my java debugger triggers a breakpoint. When I move the remoteobject declaration and function call into a custom component (that is declared within main.mxml), the remote function on java-side no longer gets called, no breakpoints triggered, no errors, silence.
How could this be? No spelling errors, or anything like that. What can I do to figure it out?
mxml code:
< mx:RemoteObject id="myService"
destination="remoteService"
endpoint="${Application.application.home}/messagebroker/amf" >
< /mx:RemoteObject >
function call is just 'myService.getlist();'
when I move it to a custom component, I import mx.core.Application; so the compiler doesn't yell
my child component: child.mxml
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" >
<mx:Script>
<![CDATA[
import mx.core.Application;
public function init():void {
helloWorld.sayHello();
}
]]>
</mx:Script>
<mx:RemoteObject id="helloWorld" destination="helloService" endpoint="$(Application.application.home}/messagebroker/amf" />
<mx:Label text="{helloWorld.sayHello.lastResult}" />
</mx:Panel>
my main.mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" xmlns:test="main.flex.*" >
<mx:Script>
<![CDATA[
[Bindable]
public var home:String;
[Bindable]
public var uName:String;
public function init():void {
//passed in by wrapper html
home = Application.application.parameters.appHome;
uName = Application.application.parameters.uName;
}
]]>
</mx:Script>
<test:child />
</mx:Application>
The child components are calling creationComplete before the parent (so home is null). A solution is to throw an event (like InitDataCompleted) from the parent after you read the data, and in the child components listen for this event (so don't rely on creationcomplete in the child).
However more important than that is how can you diagnose in future this kind of problems. A simple tool like a proxy (eg Charles) should help.
For your endpoint value you've got
endpoint="$(Application.application.home}/messagebroker/amf"
Why are you using $( before Application.application... This should be a { as in:
endpoint="{Application.application.home}/messagebroker/amf"
re: spark.components.ButtonBar
In the spark ButtonBar's mouseOver event, how do you determine which of the several buttons the mouse is hovering over? There is, of course, no selected index at this juncture. If it makes a difference, my ButtonBar is not defined in MXML but is instantiated in ActionScript and an ArrayList is assigned to the dataProvider property of my ButtonBar instance.
Thanks for the help.
There's no real easy/built-in way to do this if Flex 4, and I think that's a good thing. Instead, they give you access to the renderers via ElementExistenceEvent.RENDERER_ADD and ElementExistenceEvent.RENDERER_REMOVE, so you can look for all kinds of events on the children. Try this out:
<?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">
<fx:Script>
<![CDATA[
import mx.core.IVisualElement;
import spark.events.RendererExistenceEvent;
protected function rendererAddHandler(event:RendererExistenceEvent):void
{
var element:IVisualElement = event.renderer;
element.addEventListener(MouseEvent.MOUSE_MOVE, renderer_mouseMoveHandler);
}
protected function rendererRemoveHandler(event:RendererExistenceEvent):void
{
var element:IVisualElement = event.renderer;
element.removeEventListener(MouseEvent.MOUSE_MOVE, renderer_mouseMoveHandler);
}
protected function renderer_mouseMoveHandler(event:MouseEvent):void
{
trace(event.currentTarget.label);
}
]]>
</fx:Script>
<s:ButtonBar id="buttonBar"
rendererAdd="rendererAddHandler(event)"
rendererRemove="rendererRemoveHandler(event)">
<s:dataProvider>
<mx:ArrayList source="[one, two, three, four]"/>
</s:dataProvider>
</s:ButtonBar>
</s:Application>
Hope that helps,
Lance
You can simply use the itemRollOver event of the spark buttonbar.
I have two mxml files in a flex project:
But when I trace a.cBtn, it is null.
Why should it be?
test.mxml :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="runIt()">
<mx:Script>
<![CDATA[
public function runIt():void
{
var a:abc = new abc();
trace(a.cBtn);//a.cBtn is null here
}
]]>
</mx:Script>
</mx:Application>
And, abc.mxml :
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Button x="108" y="73" label="Button" id="cBtn"/>
</mx:Canvas>
The underlying issue here is that in Flex, the children components of a given flex container component are not created until that container is initialized. The initialization process starts after you add the container to the display list. As noted above, the CREATION_COMPLETE event is fired after initialization is done and the children are instantiated, so you can safely access children at that point.
It's pretty ugly, but if you absolutely need to access the children of a component before you want to add that component to the display list, you can call "initialize()" on your container.
public function runIt():void
{
var a:abc = new abc();
trace(a.cBtn);//a.cBtn is null here
a.initialize();
trace(a.cBtn);//a.cBtn is not null here
}
You need to wait for the creationcomplete event.
public function runIt():void
{
var a:abc = new abc();
a.addEventListener(FlexEvent.CREATION_COMPLETE, traceIt)
trace(a.cBtn);//a.cBtn is null here
}
private function traceIt(e:Event):void
{
trace(a(e.target).cBtn)
}