How can I import symbols from Flash CS in MXML? - apache-flex

I'm writing a mobile app in Flex with FlashDevelop and using Flash CS6 to create the visual assets. I created a symbol in Flash CS6 and exported it as AC3 into an SWC, which I imported into my FlashDevelop project. I then created a class for it, like so:
package com
{
import flash.display.Sprite;
public class volmeter_class extends Sprite
{
private var design:volmeter;
public function volmeter_class()
{
trace("I'm a MySymbol instance called", name);
design = new volmeter();
addChild(design);
}
}
}
I'm now seeking to display the symbol I created on a page of my app. To do this, I suspect I am expected to somehow import it in my MXML, but I have no idea how to do so. Can someone give me a few tips on how to get started doing this?

In Flash Pro, assure AS Linkage is specified for the symbol.
Using the published SWC from Flash Pro in the ActionScript Build Path of a project, the symbol may be instantiated by AS Linkage. Or, symbols may be embedded from the published SWF of Flash Pro.
Pure ActionScript example:
package
{
import flash.display.Sprite;
public class AppExample extends Sprite
{
public function AppExample()
{
var exampleSymbol:ExampleSymbol = new ExampleSymbol();
addChild(exampleSymbol);
}
}
}
Flex MXML example:
<?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"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
var exampleSymbol:ExampleSymbol = new ExampleSymbol();
symbol.addChild(exampleSymbol);
}
]]>
</fx:Script>
<s:SpriteVisualElement id="symbol" />
</s:Application>
Another approach would be to embed the symbol by linking a SWF from Flash Pro.
Flex MXML embed example:
<?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">
<fx:Script>
<![CDATA[
[Embed('assets/library.swf', symbol = 'ExampleSymbol')]
[Bindable]
public static var ExampleSymbolClass:Class;
]]>
</fx:Script>
<s:Image source="{ExampleSymbolClass}" />
</s:Application>

Related

Error: Skin for xxx cannot be found when adding an IVisualElement obtained from a Flex Module via a custom property

I am attempting to prototype a modular application architecture utilizing the Apache Flex SDK 4.12.1 using Flex Modules. I have the following project structure.
CommonLib flex library. This project contains a single file, IPlugin.as as shown below.
{
import mx.core.IVisualElement;
public interface IPlugIn
{
function get MyPlugin():IVisualElement;
}
}
ModuleProject flex application. This project contains two files. PluginModule.mxml which is the module I want to load and DemoForm.mxml which is the component I want to add to the main application.
// PluginModule.mxml
<?xml version="1.0" encoding="utf-8"?>
<s: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"
xmlns:local="*"
implements="Interfaces.IPlugIn">
<fx:Script>
<![CDATA[
import mx.core.IVisualElement;
private var _myPlugin:DemoForm = new DemoForm();
protected function button1_clickHandler(event:MouseEvent):void
{
container.addElement(new DemoForm());
}
public function get MyPlugin():IVisualElement
{
if (_myPlugin == null)
_myPlugin = new DemoForm();
return _myPlugin;
}
]]>
</fx:Script>
<s:HGroup>
<s:Button id="btn" label="Add DemoForm" click="button1_clickHandler(event)"/>
<s:VGroup id="container"/>
</s:HGroup>
</s:Module>
// Demoform.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400">
<s:layout>
<s:TileLayout/>
</s:layout>
<s:Button label="Button 1"/>
<s:TextInput/>
</s:Group>
FlexProject flex application project. This contains a single file with the intention of loading the PluginModule and DemoForm.mxml into it's BorderContainer.
<?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:Script>
<![CDATA[
import mx.core.IVisualElement;
import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;
import mx.modules.ModuleManager;
import Interfaces.IPlugIn;
private var moduleInfo:IModuleInfo;
protected function button1_clickHandler(event:MouseEvent):void
{
moduleInfo = ModuleManager.getModule("PluginModule.swf");
moduleInfo.addEventListener(ModuleEvent.READY, renderModule);
moduleInfo.load(null, null, null, this.moduleFactory);
}
private function renderModule(event:ModuleEvent):void
{
var module:Object = moduleInfo.factory.create();
var plugin:IPlugIn = module as IPlugIn;
container.addElement(plugin as IVisualElement); // <-- Works!
container.addElement(plugin.MyPlugin); // <-- Error: Skin cannot be found
}
]]>
</fx:Script>
<mx:VBox>
<s:Button click="button1_clickHandler(event)" label="Add Plugin"/>
<s:BorderContainer id="container">
<s:layout>
<s:VerticalLayout gap="10"/>
</s:layout>
</s:BorderContainer>
</mx:VBox>
</s:Application>
I can add the module directly to the application's container and everything seems to work. The application container will then display the 1 button implemented by PluginModule.mxml. However, when I try to add the Demoform to the application's container via the plugin.MyPlugin method I receive the following error.
Error: Skin for
FlexProject.ApplicationSkin2.containerGrp.contentGroup.VBox5.container.BorderContainerSkin10.Group11.DemoForm13.RadioButton16
cannot be found.
I have tried this with numerous different controls including TextArea, TextInput, and RadioButtons. These all fail with similar errors. It appears that the main application cannot find the skins for these components!
Interestingly, if I instead allow PluginModule.mxml to add the DemoForm.mxml to it's own container it works fine. Though, this is not the behavior that I desire.
Any suggestions as to what might be occurring and how I can address it?
I think your module is omitting required classes and these are not available in the main application either.
If you want the unused classes to be included, using an import on those classes should be sufficient. Make sure you include the import in a class that is being used.
Add the compiler flag "link-report filename" generates a report to see what classes are included.
A colleague found the answer. In the project which will be loading the modules you need to add -keep-all-type-selectors to the compiler options. According to the adobe docs...
-keep-all-type-selectors
Instructs the compiler to keep a style sheet’s type selector in a SWF
file, even if that type (the class) is not used in the application.
This is useful when you have a modular application that loads other
applications. For example, the loading SWF file might define a type
selector for a type used in the loaded (or, target) SWF file. If you
set this option to true when compiling the loading SWF file, then the
target SWF file will have access to that type selector when it is
loaded. If you set this option to false, the compiler will not include
that type selector in the loading SWF file at compile time. As a
result, the styles will not be available to the target SWF file.
This is an advanced option.

Flex PopUpAnchor created manually not showing up

I need to create a component using ActionScript. Can't use mxml in this case.
In my component I need to create PopUpAnchor using new operator and addElement to the stage. Unfortunatelly when I'm doing it, the PopUpAnchor's displayPopUp property does not respond to any values.
Here is my the example:
<?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"
initialize="init(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import spark.components.Label;
import spark.components.PopUpAnchor;
protected function init(event:FlexEvent):void
{
var anchor:PopUpAnchor = new PopUpAnchor();
var label:Label = new Label();
label.text = 'ABC';
anchor.addChild(label);
addElement(anchor);
anchor.displayPopUp = true;
}
]]>
</fx:Script>
</s:WindowedApplication>
I'm using Flex SDK 4.5 with AIR SDK 2.6.
What am I doing wrong?
I figured it out. The problem is that i connot use addChild on anchor. I should use popUp property instead.
So, this line is WRONG:
anchor.addChild(label);
and should be corrected to this form:
anchor.popUp = label;

Flex 4.6 - Enable onClick (click) on an s:List or s:ArrayCollection

I have been searching thru the posts but I have not been able to find (I could have missed it) how to allow items in an s:List or s:Arraycollection to be clicked to advance to another view in an mobile app. Any help would be much appreciated!
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"
creationComplete="onCreationComplete()"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private var _listDataProvider:ArrayCollection = new ArrayCollection(['one', 'two', 'three']);
private function onCreationComplete():void
{
list.dataProvider = _listDataProvider;
list.addEventListener(MouseEvent.CLICK, onListItemClick);
}
private function onListItemClick(event:Event):void
{
Alert.show('Replace this Alert with code to go to view ' + event.currentTarget.selectedItem.toString() + '.', 'Item #' + (event.currentTarget.selectedIndex + 1).toString());
}
]]>
</fx:Script>
<s:List id="list"
horizontalCenter="0"
verticalCenter="0"
/>
</s:Application>
I'm getting the same issue. For some reasons, flash builder is importing the Alert class correctly (import mx.controls.Alert) with its full package name but the project does not compile because it says "Import alert could not be found". I am developing a mobile application using SDK 4.6 which i know doesn't have support for mx controls. This only explains why mx namespace control classes aren't importing properly. I hope this answers your question correctly as i'd advice you to find other means of alerting information to the user. Maybe write a custom alert component or use the platform's alert control via Native extensions.

Flex and Parsley Logging

i'm looking for a possibility to log messages in my flex 4.5 Project. This should cover errormessages in remoteClasses, errorHandler or messages typing by hand.
After reading a lot of webpages, the solution from parslay looks good. i want to switch to this framework anyway.
the benefit is the possibility to configure the logging behavior at runtime. but i don't understand the documentation. perhaps because I'm brandnew in parsley. Also google has no fitting result.
Do you have already did this and it is possible for you to give me a few code snippets.
Thanks a lot
Frank
EDIT:
Because of J_A_X justified criticism, i add my code, because i have partially succeeded.
First we need a config file, because i want to configure the logging behavior in runtime. This is a simple xml-file in the project root.
<?xml version="1.0" encoding="UTF-8"?>
<objects
xmlns="http://www.spicefactory.org/parsley"
xmlns:log="http://www.spicefactory.org/parsley/flex/logging"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.spicefactory.org/parsley
http://www.spicefactory.org/parsley/schema/2.3/parsley-core.xsd
http://www.spicefactory.org/parsley/flex/logging
http://www.spicefactory.org/parsley/schema/2.3/parsley-logging-flex.xsd"
>
<log:target level="info" type="components.SocketTarget">
</log:target>
</objects>
This is my Application:
<?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"
initialize="onAppInitiallize(event)"
xmlns:parsley="http://www.spicefactory.org/parsley"
>
<fx:Script>
<![CDATA[
import mx.controls.Label;
import mx.events.FlexEvent;
import mx.logging.Log;
import org.spicefactory.lib.logging.LogContext;
import org.spicefactory.parsley.flex.logging.FlexLoggingXmlSupport;
protected function onAppInitiallize(event:FlexEvent):void
{
FlexLoggingXmlSupport.initialize();
LogContext.getLogger(this);
//Log.getLogger("myCat").info("MyInfo");
}
protected function button1_clickHandler():void
{
Log.getLogger(this.toString()).info("myMessage");
Log.getLogger(this.toString()).fatal("myMessage");
}
]]>
</fx:Script>
<fx:Declarations>
<parsley:ContextBuilder>
<parsley:XmlConfig file="config.xml"/>
</parsley:ContextBuilder>
</fx:Declarations>
<s:Button click="button1_clickHandler()" label="SendLogToParsley" />
</s:Application>
At this point, the logging will work in the console of the flex builder, because parsley uses by default the TraceTarget. Now, i want to send my Logfiles to a socket. I wrote a litte rough SocketTarget.
package de.axurit.components
{
import flash.net.Socket;
import mx.logging.AbstractTarget;
import mx.logging.LogEvent;
import mx.logging.targets.LineFormattedTarget;
public class SocketTarget extends AbstractTarget
{
private var _host:String;
private var _port:int;
private var _socket:Socket;
public function SocketTarget(host:String = "localhost",port:int=8085)
{
_host = host;
_port = port;
_socket = new Socket (host,port);
super();
}
override public function logEvent (event:LogEvent):void
{
trace ("logevent" + event.message);
_socket.writeUTF(event.message + String.fromCharCode(13));
_socket.flush();
}
}
}
In the parsley documentation i can see the comment
The default target type created by this tag is a TraceTarget. You can
explicitly declare other target types:
If i add the type-attribute, i receive a Errormessage "One or more errors in BootstrapProcessor". The same as i received after a typo.
Can you give me some hints, how i can send my logs to a socket destination?
You're creating the socket, but never actually connect it. Plus, if you're going to make a log target, make your class extend trace target and override the log function.

How to display a fileSystemList list in as3

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

Resources