How to get around Flash error 2176 - apache-flex

In my Flex application, users need to be able to upload and download content. However, this content is access restricted, and I need to do a permissions check before allowing the upload/download. The user clicks a link, and then selects a file using the FileReference class. The FileReference class doesn't attach cookie information, so I can't use a session.
I want to implement a 2 step process where the client first pings the server to get a one-time-use token, and then does the upload or download with the one-time-use token as a parameter. However, this plan is being foiled by error #2176, which is apparently a security fix to FP10, that only allows uploads/download to be triggered during a MouseEvent propogation. Anyways around this?

I got workarround for this here.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
minWidth="955" minHeight="600"
creationComplete="creationCompleteHandler(event)">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
Alert.show("Now you can save the file!", "Test", Alert.OK|Alert.CANCEL, null, closeHandler);
}
protected function closeHandler( event:CloseEvent ):void
{
var fileReference :FileReference;
if ( event.detail == Alert.OK )
{
fileReference = new FileReference();
fileReference.save("http://www.bogdanmanate.com", "test.txt");
}
}
]]>
</mx:Script>
</mx:Application>

Related

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 refresh an application in Flex?

I have designed a quiz application in Flex 4. At the end I want to reload my application (that is refresh the page in the browser). At the end I will show score in an alert. After that I want to reload the current application. How can I do this?
To cause the refresh to not happen until after your alert is clicked:
<?xml version="1.0" encoding="utf-8"?>
<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" xmlns:local="*"
>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.CloseEvent;
protected function refreshClicked(event:Event):void
{
Alert.show("Congratulations you won",
"Hooray!",
Alert.NO|Alert.YES, null, refreshFinish);
}
protected function refreshFinish(event:CloseEvent=null):void{
if(event == null){
event = new CloseEvent("refreshFinish");
event.detail = Alert.YES;
}
if(event.detail == Alert.YES){
navigateToURL(new URLRequest(FlexGlobals.topLevelApplication.url), "_self");
}
}
]]>
</fx:Script>
<s:Button label="Alert and Refresh" click="refreshClicked(event)" />
</s:Application>
You can remove the option of "NO" by removing it from the or as the 3rd parameter of Alert.show.
just navigate back to your website :)
navigateToURL(new URLRequest("linktoyourwebsite"));
to get the current page's url, you can use the following code:
import flash.external.ExternalInterface;
var pageURL:String = ExternalInterface.call('window.location.href.toString');
so your code then becomes:
var pageURL:String = ExternalInterface.call('window.location.href.toString');
navigateToURL(new URLRequest(pageURL));
another answer.
we have to call function in AS3
ExternalInterface.call("reload");
in html file within javascript we have to define function reload
function reload()
{
window.location.reload(true);
}

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

Deployed flex applet not processing web service results

When I test my deployed app in a browser the popup window continues to be displayed even after it should be closed. Everything works as expected when debugged in Flash Builder 4.
Following is currently what's happening: the request is sent to my restful web service, which processes the request, (seemingly) the ResultEvent is called which in turn dispatches the profileEvt dynamic event that changes the view state. However, the popup window does not get closed and the applet gets 'stuck.'
Anyone know what could be the problem? Below are the flex applet web service event listeners/handlers:
webService.addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void
{
var rawData:String = String(event.result);
var profileEvt:DynamicEvent = new DynamicEvent("profileSaved", true);
profileEvt.data = JSON.decode(rawData).profile;
dispatchEvent(profileEvt); // Dispatch profile saved event
_progressPopUp.closePopUp();
dispatchEvent(event); // Dispatch submit profile button clicked
});
webService.addEventListener(FaultEvent.FAULT, function(event:FaultEvent):void
{
Alert.show("Could not create profile; please try again later.\n" + event.message, "Status");
_progressPopUp.closePopUp();
});
var params:Object = {"profile" : profile};
try
{
_progressPopUp = PopUpManager.createPopUp(this, com.profs.ui.components.ProgressPopUp, true);
_progressPopUp.eventSource = webService; // Set source of progress events
webService.send(JSON.encode(params));
}
NOTE:
com.profs.ui.components.ProgressPopUp is a custom component; the code for it is below:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow 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="300" height="200" showCloseButton="false" title="Status" creationComplete="init()">
<fx:Declarations></fx:Declarations>
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;
[Bindable] public var eventSource:Object;
private function init():void
{
PopUpManager.centerPopUp(this);
}
public function closePopUp():void
{
PopUpManager.removePopUp(this);
}
public function completionHandler(event:Event):void
{
closePopUp();
}
]]>
</fx:Script>
<mx:ProgressBar id="progressBar" indeterminate="true" mode="event" source="{eventSource}" complete="completionHandler(event)" verticalCenter="0" horizontalCenter="0"/>
</mx:TitleWindow>
I am not familiar with the com.profs.ui.components.progressPopUp component, but it is possible that the closePopUp() method has a bug in it. You could try to remove the ProgressPopUp directly using the PopUpManager method. For example instead of:
_progressPopUp.closePopUp();
try
PopUpManager.removePopUp(_progressPopUp);
I also don't know off the top of my head what the rules for closures are (i.e. at which point is the _progressPopUp variable copied into the ResultEvent.RESULT event handler. You could try moving that particular event handler below the line where you actually created the _progressPopUp instance.

Resources