I am using the mxmlc to compile the examples from google to get started in using Google Maps API in Flex 4. But after compiling the swf file the map does not load.
I've registered for an API key
Downloaded and included the Maps SDK in the xml config file used at compile time
C:\sdk\flex4\frameworks\flex-config.xml
<external-library-path>
<path-element>libs/google/maps/lib/map_flex_1_18.swc</path-element>
</external-library-path>
Foo.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<maps:Map xmlns:maps="com.google.maps.*" id="map" mapevent_mapready="onMapReady(event)"
width="100%" height="100%" key="{KEY}"/>
<mx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
private function onMapReady(event:Event):void {
this.map.setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
}
]]>
</mx:Script>
</mx:Application>
Any tips on where to go from here? I can compile a basic flex project without problem and displays the components I put in so i'd imagine it's something to do with the API Key?
Thanks for the help
If your onMapReady function is getting called your api key is probably ok (you would get an error otherwise)
I had the exact same problem. But adding the following to the onMapReady() function seemed to fix it:
private function onMapReady(event:Event):void
{
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.addControl(new ZoomControl());
this.map.setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
}
You should also consider using the latest version of the library it is now on version 20
Unfortunately, google does not yet "officially" support Flex 4 so I imagine there might be other bugs out there as well.
Note if you happen to be using https you also need to add a call to Security.allowInsecureDomain("maps.googleapis.com");
Related
I'm migrating from flex 3.5 to flex 4.6 with flex 3 compatibility mode. I got this warning in my two modules:
Module1 is a module or application that is directly referenced. This will cause Module1 and all of its dependencies to be linked in with index. Using an interface is the recommended practice to avoid this.
I have module1.mxml and module1controller.as with several functions, then this module is loaded in many applications files using mx:ModuleLoader. Like i said this is a compatibly mode so I'm not sure if i can use spark on this.
I think i don't understand what this warning means, everything works in the application. Can someone give me an example of a Interface that can fix this problem.
Here is the example.
You want your module to do some things for your main app. For example, let your module provide some user notifying functionality.
So, we declare interface for that functionality:
package test
{
public interface IAlertable
{
function alert(message:String):void;
}
}
Then we declare that our module can provide functionality, declared in that interface:
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300"
implements="test.IAlertable"
>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
public function alert(message:String):void{
Alert.show(message,message);
}
]]>
</fx:Script>
</mx:Module>
And then in main application we shall never be interested in our module class name or implementation, we just need to know that it has functionality we desire from it:
<fx:Script>
<![CDATA[
import test.IAlertable;
protected function handleCreationComplete():void
{
moduleLoader.loadModule('test/TestModule.swf');
}
protected function testInterface():void{
var alertModule:IAlertable = IAlertable(moduleLoader.child);
alertModule.alert('Hello module world!');
}
]]>
</fx:Script>
<mx:ModuleLoader id="moduleLoader" width="100%" height="100%" ready="testInterface()"/>
Now you can change implementation of your functionality at any time without recompiling main app(in current example, you can do trace instead of alert), you can even create different module class with that interface, and main app will never notice the change.
I'm trying to embed swf file with some frame labels defined in its timeline into my Flex application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1000" height="563" creationComplete="doSomething()">
<mx:Script>
<![CDATA[
private var movieClip:MovieClip;
private function doSomething():void {
movieClip = swfFile.content as MovieClip;
movieClip.gotoAndPlay('playIntro');
movieClip.addEventListener("swfFinished", doSomethingElse);
}
private function doSomethingElse():void {
//
}
]]>
</mx:Script>
<mx:SWFLoader id="swfFile" width="1000" height="563" source="#Embed(source='test.swf')" />
</mx:Application>
However, I cannot control swf timeline in this way... Is it possible to embed swf file and control it in a way I want?
Thanks!
Some searches on this seem to indicate that this is happens when the swf is embedded. If you can get away with not embedding the swf, do that.
Here's a solution I found that allows the embed to work:
http://iamjosh.wordpress.com/2008/04/09/embedding-flash-in-flex/
I think the issue may lie Flash Player's security model, just a hunch. It may not be allowing this type of communication with the embedded swf ... but you might be able to do something like Security.allowDomain("*") (a dangerous shortcut).
But first, check out the docs for allowDomain, as the docs suggest you might be able to do this:
Security.allowDomain(loader.contentLoaderInfo.url); // 'loader' is a SwfLoader
But I'm guessing that url might be null in the embed case :)
Hi I have a project which is build with Flash CS3 IDE and ActionScript 3. Now I need to integrate some feature with file refrence class. that is avail only in flex. So I want to migrate to flex(MXML)..
how is it possible?
I did some code, but doesn't work properly
ProjectFile.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete = "initApp()" >
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
public function initApp():void {
var app:Applications = new Applications(this);
addChild(app);
}
]]>
</mx:Script>
</mx:Application>
Applications.as
The Applications class is called from the FLA earlier, now i need to add my base class to mxml.
package {
import com.AnotherClass;
import flash.display.*;
import flash.events.*;
public class Main extends Sprite {
public var _mystage:Stage;
public function Main() {
var app:AnotherClass= new AnotherClass(this);
addChild(app);
}
}
}
But Iam unable to load the Applicatios class object on the MXML.
Of course you can use FileReference.save without deploying AIR content and/or porting to Flex. The only problem is: FileReference.save is available in Flash Player 10 or greater, but CS3 will deploy only up to Flash Player 9.
It turns out you can still do it, but it's a bit messy, and you have to use a little hack:
Get the FlashPlayer 10 AS3
libraries. They are a part of Flex SDK, which you can download from Adobe for free.
Create a Flash 9 AS3 document.
Add the libraries to your classpath, instead of the default ones.
Use FileReference.save in your
program.
Deploy to FP 9. Ignore compiler warnings, if any.
Open the SWF in a hex editor.
Change the 4th byte from 09 to 0A (his indicates the version number).
Save the SWF.
Open your SWF in Flash Player 10 -
everything should work.
(Most of these hints are from ZEROSEVEN's german page).
Trying to create a banner ad as a one-off project for a client. I am using Flash Builder / AS 3 and with my simple hello world example. Google Adwords rejects the add with: Encountered flash error - ad cannot use mouse tracking.
I Have not been able to figure out what I am doing that signals to Adwords that I am mouse tracking. Follows is my simple mxml file: (the handleClick is to adhear to their clickTAG specification)
Thanks!!!
<?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="336" minHeight="280" width="336" height="280" includeInLayout="true" click="handleClick(event)">
<fx:Script>
<![CDATA[
public function handleClick(mouseEvent:MouseEvent):void {
navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG),"_blank");
}
]]>
</fx:Script>
</s:Application>
It is quite possible that whatever automated analysis that Google does on the ads submitted is being confused by the Flex framework. You could try creating an ActionScript project instead of Flex project in Flash builder and see if that makes any difference.
If you use an ActionScript project you won't be able to use MXML for creating the ad, but you might not really even want to drag in the Flex framework, since it takes a while to load (the first time at least).
I have used Flash to make skins, which I import and apply to Flex components.
But how can I create a component in Flash, with properties and methods. And make it able to be added to the displayList in a Flex app?
I installed the Flex component kit for flash. Created my component in flash (it extends MovieClip). Did Command->Convert to flex Component, did File->Published, which gave me a .swc, dropped the .sec file into my Flex project. Now when I create a new var the class "FlashFlexComponentTest" pops up in the new class hint box, so flex sees it. But afterwards I get the error:
Type was not found or was not a
compile-time constant: FlashFlexComponentTest
I feel like I must be missing a step?
Thanks!
UPDATE
I added the .swc via project build path -> add SWC.
I no longer have a compile-time error but I am getting a runtime error:
Type Coercion failed: cannot convert FlashFlexClassTest#9089129 to mx.core.IUIComponent
The base class for all flex components, UIComponent, allows you to add Sprites that don't implement the IUIComponent interface.
An example :
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="init();">
<mx:Script>
<![CDATA[
private function init():void
{
var component:FlashFlexClassTest = new FlashFlexClassTest();
container.addChild(component);
}
]]>
</mx:Script>
<mx:UIComponent id="container" width="100%" height="100%"/>
</mx:Application>
There's a good video tutorial on this at Linda.com by David something. I did a lot of this a year or so ago, and that was the best resource I found. Doesn't cover absolutely every possible angle, but does a great job of covering what you need to know.
I'm guessing there's just some small linkage detail that you're missing. The tutorial should get you straight, if that's the case. It was worth the $20, or whatever, for a monthly subscription for me.
Sorry, that's the best I can do... haven't built Flex components in Flash since last year.
basically there are step what need to do:
open Flash
drag a component you need to stage
right click on it in Library > Export to SWC
put this SWC in your Flash Builder libs folder
There is explanation by Jesse Warden http://jessewarden.com/2011/06/integrating-flash-components-with-flex-revisited.html
Cheers!