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.
Related
I created a Flex Library Project which contains an .MXML file with one componnent (a button).
It's called Button.mxml in myLibrary.views package.
Then i created a different Flex Mobile project in which i want to include the button from my library project.
This project refers the previously created library.
I can't find an answer on how to achieve this.
Can i add it somehow like an mxml componnent?
<?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"
applicationDPI="240">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import myPackage.views.Button; // this is the package containing Button.mxml
]]>
</fx:Script>
<myPackage.Views.Button id="myButton" /> // is this possbile somehow ???
</s:Application>
Thank you!
First be sure to add the other project to your library path. You can do this by adding the generated SWC to the libs folder or by adding it to the library path. IF both projects are in the same Flash Builder workspace you can use the "Add project" button on the library tab.
Next, to use your new Button file in MXML, you must import the namespace in the top level MXML tag; something like this:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:myPackage="myPackage.views.*"
applicationDPI="240">
The syntax is very similar to what Flex does for their own packages. Except you probably haven't gone through the process of creating a namespace URL, so you use the package name. Not creating a namespace URL is fine in most cases it is more headache than it is worth.
Then you can use your custom button like this:
<myPackage:Button id="myButton" />
This follows the same syntax as other Flex components; which is namespace:ComponentName.
You cannot use the Component in MXML based on an import statement in ActionScript; but you had the right idea.
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 :)
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'm a complete newbie to Flex, so apologies for my dumbness. I've searched for an answer but haven't found anything that seems to be doing the trick.
What I'm trying to do: port this example http://www.adobe.com/devnet/air/flex/articles/flex_air_codebase_print.html
to Flash Builder 4.
All seems to be fine but for one thing. When I use the original code for the Air application
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="onApplicationComplete()">
<fx:Script>
<![CDATA[
private static const neededForCompilation:AirGeneralImplementation = null;
private function onApplicationComplete():void
{
var can:MainCanvas = new MainCanvas();
this.addChild(can);
can.labelMessage = "Loaded in an AIR Application ";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>
I get this run time error
Error: addChild() is not available in
this class. Instead, use addElement()
or modify the skin, if you have one.
at
spark.components.supportClasses::SkinnableComponent/addChild()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableComponent.as:1038]
If I substitute the code with
this.addElement(can);
Everything loads well but the first time I try to press any of the buttons on the main canvas I get the following run time error
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/getChildIndex()
at mx.managers::SystemManager/getChildIndex()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:1665]
at mx.managers.systemClasses::ActiveWindowManager/mouseDownHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\systemClasses\ActiveWindowManager.as:437]
here's the super simple code for the main canvas
<?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"
creationComplete="init();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script source="main.as" />
<mx:Label id="lblMessage" text="The UI from the shared Flex app BothCode" x="433" y="112"/>
<s:Button x="433" y="141" click="saveFile();" label="Save File"/>
<s:Button x="601" y="141" click="GeneralFactory.getGeneralInstance().airOnlyFunctionality();" label="Air Only"/>
</s:Application>
Any help would be immensely appreciated. And any pointers to how to setup a project that can compile in both Air and Flash while sharing the same code, all for Flex 4, would also be immensely appreciated.
thank you!
I ran into the same problem using that tutorial for Flex 4. I did the same thing as you and used the <s:Application> component for the Main Canvas. However the tutorial uses a <mx:VBox>, the solution I found was to change the Main Canvas from an <s:Application> to an <s:Group>. The problem seems to be embedding an Application within an Application.
The code on that link was written using the flex 3.5 sdk or below. You are using the new flex 4 sdk ( which is the default for Flash Builder ).
You can do the following:
1. step into the code do any necessary changes to make it work for flex 4 sdk.
2. setup a new project using the flex 3 sdk ( select "Use a specific SDK" and choose the Flex 3 from the dropdown box in the "New Project" window)
I would suggest going for the second option, make it work and once you've stepped a little deeper into flex 4 you can do the 1st option.
Cheers.
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");