google maps in flex withiout mxml component - apache-flex

How do I add google maps as Class into main.mxml
withiout <maps:Map key="" sensor="" />
like in Flash
UPDATE:
and if i have class
package{
import com.google.maps.Map;
public function myMap extends MovieClip {
var map:Map = new Map();
map.setSize(new Point(300, 300));
this.addChild(map);
}
}
if i use this in mxml
myMap:myMap = new myMap();
addChild(myMap);
return error
addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
if i use this
var container:UIComponent = new UIComponent();
container.width = 300;
container.height = 300;
addChild(container);
myMap:myMap = new myMap();
container.addChild(myMap);
Nothing is not added
thanx

MXML is declarative markup that is translated into actual instances at compile time.
For example:
<s:Label text="Something" />
is the same as running
var label:Label = new Label();
label.text = "Something";
this.addElement(label);
So in your case, just assign a function to execute at some point in the component lifecycle and keep the reference to the map at the class level. (I'm using some VGroup component for example)
<s:VGroup creationComplete="onCrtComplete()" ...>
<fx:Script>
<![CDATA[
private var map:Map;
private function onCrtComplete():void
{
maps = new Map();
//now you can do something with the map.
}
]]>
</fx:Script>
</s:VGroup>
Alternatively, you can add an id attribute to the MXML and then reference it programmatically using that id as the property name:
<maps:Map id="map" key="" sensor="" />
In the case of "addChild()", use "addElement()" instead - it's part of the changes between Flex 3 to 4.

Related

How to display remote swf in flex UI component?

I am trying to display remote swf in my flex application, I am able to load swf, but it is not shown(visble) in my flex application.
here is the code
private function onLoaderComplete(event:Event):void{
can.addChild(l);
}
import flash.system.SecurityDomain;
import flash.system.ApplicationDomain;
var l:Loader = new Loader();
private function initApp():void {
var context:LoaderContext = new LoaderContext();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
if(Security.sandboxType == Security.REMOTE){
var context:LoaderContext = new LoaderContext();
context.securityDomain = SecurityDomain.currentDomain;
l.load(new URLRequest('www.somedomain.com/load.swf?id1'), context);
}else{
l.load(new URLRequest('www.somedomain.com/load.swf?id=1'));
}
private function onLoaderComplete(event:Event):void{
can.addChild(l);
}
<mx:Canvas width="100%" height="50%" backgroundColor="red">
<mx:UIComponent id="can" width="100%" height="100%" >
</mx:UIComponent>
</mx:Canvas>
any idea
Thanks all
Your code snippet does not define what 'L' is
The most likely problem you're having with your current code is that you are adding your 'l' onto a UIComponent which has no built in code for sizing and positioning its children, therefore your 'l' will have no height and width, effectively making it invisible.
I would use a SWFLoader to load another SWF File and display it as part of your application.

Create new window in Air Application

how to create new window(same application duplicate) in Air Project. Any one Help thanks.
Use mx:Window, and take your code out of mx:WindowedApplication and put it into a reusable Canvas. The put an instance of that back in mx:WindowApplication, and then you can create a new mx:Window and add your reusable Canvas component in there as well.
<mx:WindowedApplication ...>
<p:YourComponent ... /> <!-- by putting it in your own file you can reuse it -->
</mx:WindowedApplication>
In a separate file called YourComponent.mxml:
<mx:Canvas ...>
<!-- put the contents that's in WindowedApplication here -->
<!-- add this block to your script block, and hook up a button/menu/whatever to
invoke this function. See how it creates a new instance of Window, adds a
new instance of YourComponent (which is the guts of your app), and shows that.
-->
<mx:Script>
private function createNewWindow() : void {
var window : Window = new Window();
var yourComponent : YourComponent = new YourComponent();
// initialize yourComponent instance's properties
window.addChild( yourComponent );
window.width = 800;
window.height = 600;
window.open(true);
}
</mx:Script>
</mx:Canvas>

Is Flex 4 Panel's controlBarContent dynamic?

I have a custom TitleWindow component (written in ActionScript) that extends spark.componenets.TitleWindow
I want to define some controls to be in the control bar but I don't have all controls at the creation stage. Also, this custom component is the base for other components which need other controls in the control bar.
Is there a way to add controls to the controlBarContent in ActionScript at run time?
Maybe something like the following? (this obviously didn't work)
controlBarContent = [];
.
.
.
controlBarContent.push(new Button());
In general, look out for
addElement()
or
addChild()
methods.
addElement() adds other UI components as sub-elements of other components.
This might be of interest. Finnaly, Adobe provides good help here: 'Working with components'.
UPDATE-1
Sorry, my fault. This works for me:
<s:Panel creationComplete="init();" id='p' controlBarVisible="true" >
<s:controlBarContent>
<!-- will show controls -->
<s:Button label="dd">
</s:Button>
</s:controlBarContent>
<fx:Script>
<![CDATA[
import mx.controls.Button;
import spark.components.Button;
private function init(): void {
var s:spark.components.Label = new spark.components.Label();
s.text = 'My Label';
s.width = 200;
var a:Array = new Array();
a.push( s );
p.controlBarVisible = false;
p.controlBarContent = a;
p.controlBarVisible = true;
p.invalidateDisplayList();
}
]]>
</fx:Script>
</s:Panel>

Adding a custom UI component as a panel titleIcon (should be easy, I'm kind of a newbie)

The concept of this seems easy, but I'm having trouble getting it right and can't find anything to help me on this.
I have a panel I need to perform a drag and drop operation on, but I only want to perform that if the user mouses down on a particular area of the panel. I can add an Icon to the panel by doing this:
[Embed("/img/icon.png")]
[Bindable]
public var dragIcon:Class;
newPanel.titleIcon = dragIcon;
But what I really want to add is a box, which I can then add my listeners to for the drag and mouse down like I do on some canvases created in actionscript like so
var tempBox:Box = new Box;
tempBox.x=0;
tempBox.y=0;
tempBox.width = 20;
tempBox.height = 44;
tempBox.setStyle("horizontalAlign","center");
tempBox.setStyle("verticalAlign","middle");
tempBox.addEventListener(MouseEvent.ROLL_OVER,over);
tempBox.addEventListener(MouseEvent.ROLL_OUT,out);
tempBox.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownAnswer);
var tempImg:Image = new Image();
tempImg.source = grabbableItem;
tempBox.addChild(tempImg);
myCanvas.addChild(tempBox);
So what do I need to do to use that tempBox and turn it into a class to be used as my panels titleIcon?
Edit 12/29/09:
So I came up with something where I'm extending the panel class (shown below) but all this is really doing is covering up the icon with something I can access publicly. I'm sure there's a better way out there right?
package custClass
{
import mx.containers.Box;
import mx.containers.Panel;
import mx.controls.Image;
public class DragPanel extends Panel
{
[Bindable] public var iconBox:Box = new Box();
[Embed("../img/doc_page.png")] [Bindable] public var grabbableItem:Class;
public function DragPanel()
{
super();
}
override protected function createChildren():void{
super.createChildren();
iconBox.x = 10
iconBox.y = 4
iconBox.width = 20;
iconBox.height = 20;
iconBox.setStyle("horizontalAlign","center");
iconBox.setStyle("verticalAlign","middle");
iconBox.setStyle("borderStyle","solid");
iconBox.setStyle("backgroundColor",0x000000);
var tempImg:Image = new Image();
tempImg.source = grabbableItem;
iconBox.addChild(tempImg);
this.rawChildren.addChild(iconBox);
}
}
}
EDIT 1/7/10 (or 16 according to my windows mobile phones text messages):
Using Chaims help from below here is my new answer.
Create a box mxml component like Chaim says but also add the following script block to it.
<mx:Script>
<![CDATA[
import mx.core.Application;
[Embed("/img/doc_page.png")]
[Bindable]
public var grabbableItem:Class;
public function init():void{
this.addEventListener(MouseEvent.MOUSE_DOWN,Application.application.mouseDownSection);
this.addEventListener(MouseEvent.ROLL_OVER,Application.application.over);
this.addEventListener(MouseEvent.ROLL_OUT,Application.application.out);
}
]]>
</mx:Script>
This adds in all the event listeners I want on the Box that will be used as my icon. Now just add the box as an Icon and it's good to go.
panel.titleIcon = DraggableBox;
I guess since it's a separate mxml component it is now a class, though I don't think I understand why.
The Panel expecting titleIcon property value to be a IFactory and create an instance by himself.
Make your box a component (lets name it DraggableBox.mxml):
<?xml version="1.0" encoding="utf-8"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml"
x="0" y="0" width="20" height="44"
horizontalAlign="center" verticalAlign="middle">
<mx:Image source="{grabbableItem}"/>
</mx:Box>
And assign it to titleIcon:
<mx:Panel titleIcon="{DraggableBox}" >
...
</mx:Panel>
If you want do it in ActionScript use ClassFactory:
panel.titleIcon = new ClassFactory(DraggableBox);

How do I create a bidirectional data binding in Flex 3?

I need to bind a property to an edit control and have the control write its value back to the same property. The problem is, I'm setting the source value before the control is created:
<mx:Panel>
<mx:Script>
<![CDATA[
[Bindable] public var editedDocument: XML;
]]>
</mx:Script>
<mx:TextInput id="docLabel" text="{editedDocument.#label}"/>
<mx:Binding source="docLabel.text" destination="editedDocument.#label"/>
</mx:Panel>
I call this like so:
var xmlDoc: XML = <document label="some label" />;
var myPanel: MyPanel = new MyPanel();
myPanel.editedDocument = xmlDoc;
parent.addChild(myPanel);
What happens is this:
the docLabel text field ends up blank (equal to "")
the xmlDoc's #label attribute is set to ""
What I want is this:
the docLabel text field should contain "some label"
the xmlDoc's #label attribute should change only when the docLabel's text property changes.
How do I accomplish this, using Flex 3?
Edit
I have also tried this:
<mx:Panel>
<mx:Script>
<![CDATA[
[Bindable] public var editedDocument: XML;
]]>
</mx:Script>
<mx:TextInput id="docLabel"/>
<mx:Binding source="editedDocument.#label" destination="docLabel.text"/>
<mx:Binding source="docLabel.text" destination="editedDocument.#label"/>
</mx:Panel>
The result is the same.
You can try using BindingUtils to programmatically create the binding after the class has been created:
http://life.neophi.com/danielr/2007/03/programmatic_bindings.html
There are many variations of this that I've used to tackle similar problems. If you can't figure it out from the link post a comment and I'll dig through my source code and see what I can find.
private function init():void
{
var xmlDoc: XML = <document label="some label" />;
var myPanel: MyPanel = new MyPanel();
myPanel.editedDocument = xmlDoc;
parent.addChild(myPanel);
BindingUtils.bindProperty(docLabel, "text", editedDocument, "label");
//or maybe it should be one of these, I have not done binding to an XML attribute before
BindingUtils.bindProperty(docLabel, "text", editedDocument, "#label");
BindingUtils.bindProperty(docLabel, "text", editedDocument, "{#label}");
}
Take a look at Two-way data binding.
Take a look at the part of the text:
In Flex 3, if you want to set
two-way binding using the
mx:Binding
tag you need to set it twice:
mx:Binding source="a.property" destination="b.property"/>
mx:Binding source="b.property" destination="a.property"/>
which becomes:
mx:Binding source="a.property" destination="b.property" twoWay="true"/>
In Flex 3 you would be better of doing something like this. Also not sure you can bind directly to XML?
Instead do something like this:
[Bindable] public var tmpString: String;
public var onChange():void {
tmpString = docLabel.text;
//set the XML string, etc.
}
]]>
</mx:Script>
<mx:TextInput id="docLabel" text="{tmpString}" change="onChange()" />
I think bidirectional data binding is a new feature in Flex 4.
This is straight from Adboe http://opensource.adobe.com/wiki/display/flexsdk/Two-way+Data+Binding, and it's Flex 3 too!
I created custom controls that programmatically create two-way bindings when given a provider object that has a suitable property whose name matches the control's id. Here's an example for a TextInput:
public class BoundTextInput extends TextInput
{
// some code omitted for brevity:
// Create getter / setter pair, call invalidateProperties()
// and set internal flag for efficiency
// create bindings in commitProperties:
override protected function commitProperties():void
{
if (this._fProviderChanged) {
this._fProviderChanged = false;
if (null != this._provider && this._provider.hasOwnProperty(this.id) && this._provider[this.id] is String) {
// this is the core bit
BindingUtils.bindProperty(this, "text", this._provider, this.id);
BindingUtils.bindProperty(this._provider, this.id, this, "text");
}
}
// Normally, you call the overridden method first,
// but we want to see the values initialized by the new
// binding right away, so we first create the bindings
// and then commit all inherited properties
super.commitProperties();
}
}
This is an example of how I use it inside one of my other components (a popup dialog). The data property is set to an instance of the appropriate model class, which is always a dumb, [Bindable] container.
<?xml version="1.0" encoding="utf-8"?>
<PopUp xmlns="com.econemon.suite.gui.components.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Form width="100%" height="100%" >
<mx:FormHeading label="Server-URL" />
<mx:FormItem label="URL" >
<!--
If it is available, and of type String, data.urlServer
is bound to the text property of this TextInput
-->
<BoundTextInput id="urlServer" provider="{this.data}"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="OK" click="this.submit(event)" />
</mx:FormItem>
</mx:Form>
</PopUp>

Resources