How to Import FileReference and FileSystemTree to ActionScript - apache-flex

I tried to insert a FileSystemTree in Flex .
Flash Builder doesn't recognise that and produces the error:
1046: Type was not found or was not a compile-time constant: FileSystemTree
Here's the code . It's a very basic one ....
<mx:HDividedBox width="100%" height="725" paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10" y="41">
<mx:VBox width="200" height="100%">
<mx:FileSystemTree id="fileSystemTree" width="100%" height="100%" change="onChange(event)" />
</mx:VBox>
<mx:Canvas width="100%" height="100%" id="content" ></mx:Canvas>
</mx:HDividedBox>
I'm using Flex 4 , Flash Builder 4. What am i doing wrong ? Is FileSystemTree supported in Flex 4 ?

That component is only available within Adobe AIR applications, not browser-based Flex applications, since browsing the local file system would violate the browser sandbox.
EDIT: Now that I understand your intention, yes, you can upload files from a flex application without having to use AIR. Instead of using the FileSystemTree component (which is AIR only), you use FileReference.browse() to allow the user to select a file from the local filesystem to upload. This page from the documentation will give you all the info you need: Working with file upload and download
Hope that helps.

Related

migrating from Flex 3.6 to 4.6

I'm currently working on an Adobe Flex Air Project, which was created with Flex 3.6! But now it should become an App for IPad, but Flash Builder can only export projects as App since Flex 4.6. So I'm trying to convert the project from Flex 3.6 to 4.6, what should be easy to do, I guess, but there are some problems with libraries and/or namespaces, which confuse me. This is how my Main-mxml starts:
<s:Application xmlns:mx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:MyComp="*"
xmlns:local="*"
xmlns:srv="generated.webservices.*"
width="1366"
applicationComplete="init()"
backgroundGradientColors="[0xffffff,0xffffff]"
borderColor="#ffffff"
color="#eaeaea"
fontSize="14"
horizontalScrollPolicy="off"
layout="absolute"
paddingBottom="0"
paddingLeft="0"
paddingRight="0"
paddingTop="0"
verticalScrollPolicy="off">
But I get the error:
`Attribute "mx" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "s:Application".`
But if I remove the line
`xmlns:mx="library://ns.adobe.com/flex/mx"`
then of course I can't use e.g. mx:VBox any more and would have to refactor the whole project.
I tried some test examples using Flex 4.6, e.g.
<?xml version="1.0"?>
<!-- containers\layouts\BoxSimple.mxml -->
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<mx:Box direction="vertical"
borderStyle="solid"
paddingTop="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10">
<mx:Button id="fname" label="Button 1"/>
<mx:Button id="lname" label="Button 2"/>
<mx:Button id="addr1" label="Button 3"/>
<mx:ComboBox id="state">
<mx:ArrayList>
<fx:String>ComboBox 1</fx:String>
</mx:ArrayList>
</mx:ComboBox>
</mx:Box>
</s:Application>
But here I get the error
`"Could not resolve <mx:Button> to a component implementation." `and more like this.
Now my question(s):
1. It's possible to use all three namespaces
`(xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark")`
Right? I saw this on several examples on the internet so I think it must work.
Do I have to reference/add external libraries to use Flex 4.6 with these 3 namespaces?
Is there an easy general way for migrating from Flex 3.6 to 4.6? Is it at all necessary to make changes or must it work in 4.6, even though developed in 3.6?
Besides, I'm relatively new to Flex, though it's not difficult I think.
Thanks in advance
Regards,
Max B
Max - to answer your question specifically it is absolutely possible to use MX components within Flex 4 apps. Your example seems to work fine with a regular flex 4.6 project. You might need to ensure you have the right library path settings.
Flex isn't difficult, but migrating between major verions can be a pain in the ass and may require a more seasoned developer. The fact is you have to know both frameworks, what are their differences and how you can fix those differences.
So Is there an easy general way for migrating? Well, ... no (or yes if you're willing to compromise, more on that later).
As for the namespaces: you can use all three of them together in one application and there's nothing special you have to do for that. That is, if you're building a traditional web app. If you're building a mobile app, some other framework libraries are used which do not inculde the components from the mx age. The reason is that Spark components or much more efficient and mobile devices just aren't as powerful as desktops yet.
Which means you'll have to convert your entire application to the Spark namespace. If your views haven't completely been separated from the business logic, you might as well rewrite it from scratch.
You can force the compiler to include the mx libraries however, even when compiling for mobile. But this will come at a performance cost.
That said, all I've said until now was on a technical level. From a UX point of view you can not expect an application that was designed for a big screen to be pleasant to use on a small one. In most of the cases these 'simple' conversions are complete failures.

How to Create Advanced Flex custom components library

I want to create a custom component library. the components are customize-able during creation time. means like Accordion or TabNavigator, when we drag and drop the Accordion in flash builder it
<mx:Accordion x="38" y="167" width="200" height="200">
<s:NavigatorContent width="100%" height="100%" label="Accordion Pane 1">
</s:NavigatorContent>
</mx:Accordion>
look there is two tags came at a time mx:Accordion and s:NavigatorContent how it happens. how can i create a component like this.
I want to create a component of container with three buttons. after i drag component into flash builder it should editable mean its tag must look like this
<local:container x="38" y="167" width="200" height="200">
<s:button width="10" height="10" />
<s:button width="10" height="10" />
<s:button width="10" height="10" />
</local:container>
In order to add additional tags when the user drags your custom component into Flash Builder you'll have to write an extension for your component and configure it within a design.xml file.
Here are a few links to get you started:
Flash Builder Design View extension FAQ
Extending Flex Builder
Design View Extensibility Kit for Flex 4.5
First You want to understand one thing, that is creation of custom components is to simplify the tags. Though the flash builder also won't supports such kind of thing. The custom components child can be created internally by overriding some methods in it, which depends upon the base class you inherit.
Creation of Custom component will lead only to
<local:container x="38" y="167" width="200" height="200">
</local:container>
Though you can add child in it by manually or internally.

Multiple initializer values in Flash Builder

Finally decided to try Flash Builder rather than FlashDevelop and got caught up on my very first app. I'm building a AIR app and downloaded the latest SDK and installed it in the Flash Builder path.
When I add a few simple items they all get errors. I added this code:
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingTop="10"/>
<s:Label id="myLabel" text="Some text stuff I typed."/>
<s:Button click="myLabel.text='Some stuff the button typed'"/>
</s:layout>
And I get an error on each spark item (except layout) that says:
In initializer for 'layout', multiple initializer values for target type spark.layouts.supportClasses.LayoutBase.
I've searched google with no real results. Does anyone know what this error is telling me? Is there a problem with the SDK installation? I followed install instructions from a Lynda.com vid.
Thanks for the help!
Not sure which Flex SDK or Flash builder version you are working with but in version 4 try this,
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingTop="10"/>
</s:layout>
<s:Label id="myLabel" text="Some text stuff I typed."/>
<s:Button click="myLabel.text='Some stuff the button typed'"/>
You create the components after the closing layout tag not inside it.

Classes must not be nested - MXML

I'm trying to build a simple FLEX application. Unfortunately, I get '1131: Classes must not be nested.' errors even with the simples MXML .... the error pops out at the mx:Application openning tag:
(I'm using PureMVC if it's important)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:view="icm.view.components.*"
viewSourceURL="srcview/index.html"
name="ICM"
layout="absolute"
> //FLEX BUILDER SAYS THE ERROR IS HERE
<mx:Script>
<![CDATA[
import mx.effects.easing.Exponential;
import icm.ApplicationFacade;
public static const NAME:String = "AppSkeleton";
private var facade:ApplicationFacade = ApplicationFacade.getInstance(NAME);
]]>
</mx:Script>
<mx:Move id="slideInEffect" yFrom="5000" easingFunction="{Exponential.easeOut}" duration="1300"/>
<mx:Fade id="fadeOut" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:Fade id="fadeIn" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>
<mx:Style source="css/yflexskin.css" />
<mx:Canvas id="mainViewStack" left="0" top="0" right="0" bottom="0" >
<mx:ViewStack id="vwStack" left="0" top="0" right="0" bottom="0" resizeToContent="false" creationPolicy="auto">
<mx:VBox />
<view:SplashScreen id="splashScreen" showEffect="{slideInEffect}" hideEffect="{fadeOut}" />
<view:LoginScreen id="loginScreen" showEffect="{fadeIn}" />
<view:MainScreen id="mainScreen" showEffect="{fadeIn}" />
</mx:ViewStack>
</mx:Canvas>
</mx:Application>
Can someone help me understand why? I've being doing a lot of non-sense tests because I'm not understanding it.
Sometimes if I remove the Script section the compilation suceed, others not.
Thanks
Thank you all for the comments.
The greatest tip at this topic is: build with the SDK!!!
Flex Builder (both, the IDE and the Plugin) seems to lack a lot of features on error treatment and even when it reports an error it's not reliable.
A prompt window for compiling used with the IDE saved me a lot of headaches.
Thank you all again!
I had this problem using a compiler option to exclude/include some code
like -define+=CONFIG::myOption,true
when the option is true (resulting including some code), and you have such thing into your code :
CONFIG::myOption {
import <a package>;
}
this will result in a 1131 error... I have no workaround but not using such conditional compilation directives.
There is a flex compiler option "Enable Strict type checking" just de-select it. I think that can give so a simple solution....
http://blog.gigantt.com/2011/02/how-to-build-flex-sdk.html
Building
Let's create a batch file to set some useful envars: envars.bat
set JAVA_HOME=c:\Program Files\Java\jdk1.6.0_23
set PATH=c:\dev\ant\bin;%PATH%
set ANT_OPTS=-Xmx256m
Open cmd.exe and run it...
Edit c:\dev\sdk\frameworks\build.xml
Look for:
And fix the location of the manifest file from:
"${datavis.dir}/manifest.xml" to:
"${datavis.dir}/manifest_datavisualization.xml"
Run Ant:c:\dev\sdk\frameworks> ant
It should end with such a message: BUILD SUCCESSFUL
Now let's tell Flash Builder where to find this new SDK: c:\dev\sdk
Add it to the "Installed SDKs" settings in Flash Builder
Make sure your project is configured to use this SDK (it was probably created with the original one and still refers to it).
Rebuild your project. It should work.

Displaying progressbar for file upload

I need to create an application where I can add files for upload. As I add items for upload, a progressbar should be displayed along with each item added. And when I click for file upload, the progress of file upload for each file should be reflected in the progress bar. The progress should use the function like
.....
addEventListener(ProgressEvent.Progress, uploadProgressHandler);
private function uploadProgressHandler(event:ProgressEvent):void
{
var numPerc:Number = Math.round((Number(event.bytesLoaded) / Number(event.bytesTotal)) * 100);
//this.progBar.validateNow();
.....
}
Can anyone provide help me out?
See these examples:
Multiple File Upload with Flex and PHP
which looks like this:
Multiple File Upload With Progress Bar Using Flash and ASP.NET
which looks like this:
Flex has a ProgressBar class, have you checked that out yet?
Here are two great examples of Flex file uploaders (using HTTP):
Flex File Uploader using PHP, with source.
Merb and Adobe AIR File Uploader, with source.
alt text http://blog.vixiom.com/uploads/merb_air_upload.png
In order to make the above two examples work together to achieve the desired result (multiple file uploader, one ProgressBar per preloader, in Flex), all you need to do is:
Download the Flex File Uploader PHP Project
Download the Merb AIR Uploader and copy/paste the "UploadProgressComponent.mxml" somewhere into the PHP project (copy to src/UploadProgressComponent.mxml for now).
Replace the DataGrid with a List and a Custom ItemRenderer in FileUpload.mxml in the Flex File Uploader PHP Project.
Replace this:
<mx:DataGrid id="listFiles" left="0" top="0" bottom="0" right="0"
allowMultipleSelection="true" verticalScrollPolicy="on"
draggableColumns="false" resizableColumns="false" sortableColumns="false">
<mx:columns>
<mx:DataGridColumn headerText="File" dataField="name" wordWrap="true"/>
<mx:DataGridColumn headerText="Size" dataField="size" width="75" textAlign="right"/>
</mx:columns>
</mx:DataGrid>
with this:
<mx:List id="listFiles" left="0" top="0" bottom="0" right="0"
allowMultipleSelection="true" verticalScrollPolicy="on"
itemRenderer="UploadProgressComponent"/>
The result: Multiple file uploader in Flex, with a custom ItemRenderer that has a ProgressBar for each FileReference. Uploads to a PHP script, which you can swap out for anything.
Should be very easy to customize from there. Let me know if that works,
Lance

Resources