Flex navigateToURL from iframe POST - apache-flex

Let me explain my current issue right now:
I have a webapp located at domain A. Let's call it A-App. I open an iframe from A-App that points to a Flex app on domain B. We'll call it B-FlexApp. B-FlexApp wants to post some data to another app located on the same domain, we'll call it B-App. The problem is that in IE the communication breaks somewhere between B-FlexApp and B-App while B-FlexApp is opened in the iframe. This only happens in IE.
However when opening B-FlexApp in a new window, posting the data to B-App works just fine. How to overcome this? Dropping the iframe is not possible.

ThereĀ“s a issue with AS3 navigateToURL and IE. You can try calling javascript to navigate: I have a little utility class to handle this:
//class URLUtil
package com
{
import flash.external.*;
import flash.net.*;
public class URLUtil extends Object
{
protected static const WINDOW_OPEN_FUNCTION:String="window.open";
public function URLUtil()
{
super();
return;
}
public static function openWindow(arg1:String = "", arg2:String="_blank", arg3:String=""):void
{
var browserName:String = getBrowserName();
switch (browserName)
{
case "Firefox":
{
flash.external.ExternalInterface.call(WINDOW_OPEN_FUNCTION, arg1, arg2, arg3);
break;
}
case "IE":
{
flash.external.ExternalInterface.call("function setWMWindow() {window.open(\'" + arg1 + "\');}");
break;
}
case "Safari":
case "Opera":
{
flash.net.navigateToURL(new URLRequest(arg1), arg2);
break;
}
default:
{
flash.net.navigateToURL(new URLRequest(arg1), arg2);
break;
}
}
return;
}
private static function getBrowserName():String
{
var str:String="";
var browserName:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent;}");
if (!(browserName == null) && browserName.indexOf("Firefox") >= 0)
{
str = "Firefox";
}
else
{
if (!(browserName == null) && browserName.indexOf("Safari") >= 0)
{
str = "Safari";
}
else
{
if (!(browserName == null) && browserName.indexOf("MSIE") >= 0)
{
str = "IE";
}
else
{
if (!(browserName == null) && browserName.indexOf("Opera") >= 0)
{
str = "Opera";
}
else
{
str = "Undefined";
}
}
}
}
trace("Browser: \t" + str);
return str;
}
}
}
and you call it like:
btn.addEventListener(MouseEvent.CLICK, onBTNClick);
function onBTNClick(evt:MouseEvent):void
{
URLUtil.openWindow(YOUR_URL_STRING);
}
Hope it helps!

It is better to let the browser actually does the "navigate to URL" function instead of Flex.
For example, in the page that contains the Flex app, the page would contain a Javascript function call handleNavigationRequest(pageName, target). In the Flex application, you may utilize ExternalInterface, and call the handleNavigationRequest.
By using this paradigm, the Flex application would not have to figure the details as to how the external implementations such as frame setup, etc, and you end up having a cleaner and less-coupled design.

I've found out that i can use swfObject to embed the flash object thus the iframe implementation is completely useless. Embedding the flash component in the overlay, instead of opening it in an iframe, makes IE behave properly.

I had the same problem and I solved it simply passing the second argument (browser window) to the function:
navigateToUrl(url,"_blank"); , in my case I use "_blank".
It works with IE8 and IE9.
Davide

Related

How to access global telerik functions in typescript

I try to access the function GetRadWindowManager() from my app.ts file.
I added the definitions files and I cannot find a way to call "window.GetRadWindowManager()" or "window.top.GetRadWindowManager()"
That is my code until now :
export class App {
private _windowManager: Telerik.Web.UI.RadWindowManager;
constructor() {
this._windowManager = null;
}
getRadWindowManager(): Telerik.Web.UI.RadWindowManager {
if (this._windowManager == null) {
try {
this._windowManager = window.top.GetRadWindowManager();
} catch (err) {
this._windowManager = GetRadWindowManager();
}
}
return this._windowManager;
}
}
PS : Don't mind the try/catch block, I'll remove that later :)
Thanks for your help !
Well, I don't know if this answer is the best, but extending the Window object allowed me to manually add this function. Then I can simply call it from my script.ts
interface Window {
GetRadWindowManager(): Telerik.Web.UI.RadWindowManager;
}

Adobe Flex: memory leak when pushView an popView

I am having problems of memory leaks with an app I had build in Adobe Flex, using Flex Builder. After using it for 30-40 minutes it starts to go slower and slower.
The app shows images as a catalog, but when I push and pop the views my memory rise considerably.
My thoughts are that if I set all my objects to null and dispose all the bitmapdata that I use I could free enough memory to keep using the app with no problems, but it seems like the problem is not there.
I have 3 views in my app menuView.mxml,categoriesView.mxml and productsView.mxml.
My App starts up in my pc (not in tablet) with TotalMemory: 47Mb and Private Memory : 88 MB
After pushing and poping the views for 5 times I get TotalMemory: 61Mb and Private Memory : 101 MB
Imagine if I do this several times. The app begins to go very slow in my Ipad or my Samsung Galaxy Tab.
Why is this happening? I have no idea how to solve this.
Please help! Thanks a lot!!
I put some code below.
When I am in menuView I use the following code to push the view from menuView to categoriesView
protected function button3_clickHandler(event:MouseEvent):void
{
if((FlexGlobals.topLevelApplication.getIdClienteServidorCompraActual( )!=null)&& (FlexGlobals.topLevelApplication.getIdClienteServidorCompraA ctual()>0))
{
navigator.pushView(categoriesView);
}
}
When I am in categoriesView I use the following code to push the view from categoriesView to productsView. In this view I have 3 buttons for each category.
protected function buttonC1_clickHandler(event:MouseEvent):void
{
//Categoria general con todos
var ab:ArrayCollection = getIdAmbienteServidor();
cleanMemory();
navigator.pushView(productsView, null);
}
private function cleanMemory():void
{
result.splice(0);
result = null;
System.gc();
}
When I am in productsView I use the following code to pop(I USE PUSH INSTEAD OF POP DUE TO DIFFERENT OPTIONS I HAVE) the view from productsView to categoriesView .
protected function button1_clickHandler(event:MouseEvent):void
{
cleanMemory();
navigator.pushView(menuView);
}
private function cleanMemory():void
{
if(image1 != null)
{
image1.source = "";
if(image1.bitmapData != null)
{
image1.bitmapData.dispose();
}
}
if(image2 != null)
{
image2.source = "";
if(image2.bitmapData != null)
{
image2.bitmapData.dispose();
}
}
if(result != null)
{
result.splice(0);
result = null;
}
if(result1 != null)
{
result1.splice(0);
result1 = null;
}
if(result2 != null)
{
result2.splice(0);
result2 = null;
}
dbConnection = null;
object1 = null;
object2 = null;
dataToSave = null;
cGreyImageSmallAsset = null;
cRedImageSmallAsset.bitmapData.dispose();
cRedImageSmallAsset = null;
cOrangeImageAsset.bitmapData.dispose();
cOrangeImageAsset = null;
cGreenImageAsset.bitmapData.dispose();
cGreenImageAsset = null;
cPinkImageAsset.bitmapData.dispose();
cPinkImageAsset = null;
cBlueImageAsset.bitmapData.dispose();
cBlueImageAsset = null;
cGreyImageAsset.bitmapData.dispose();
cGreyImageAsset = null;
cRedImageAsset.bitmapData.dispose();
cRedImageAsset = null;
cGreenImageSmall = null;
cOrangeImageSmall = null;
cPinkImageSmall = null;
cBlueImageSmall = null;
cGreyImageSmall = null;
cRedImageSmall= null;
cGreenImage = null;
cPinkImage = null;
cBlueImage= null;
cGreyImage = null;
cRedImage= null;
cOrangeImage= null;
System.gc();
}
I load the images with.
private function setImages():void
{
if(object1!=null)
{
panelLeft.visible = true;
buttonLeftMore.visible = true;
image1.source = "file://" + File.applicationStorageDirectory.nativePath + "/b"+object1.idArchivo+"_500.jpg";
setObject1MainTexts();
}
else
{
image1.source = "";
panelLeft.visible = false;
buttonLeftMore.visible = false;
}
if(object2!=null)
{
panelRight.visible = true;
buttonRightMore.visible = true;
image2.source = "file://" + File.applicationStorageDirectory.nativePath + "/b"+object2.idArchivo+"_500.jpg";
setObject2MainTexts();
}
else
{
image2.source = "";
panelRight.visible = false;
buttonRightMore.visible = false;
}
}
When I am in categoriesView i use the following code to pop(I USE PUSH INSTEAD OF POP DUE TO DIFFERENT OPTIONS I HAVE) the view from categoriesView to menuView.
protected function button1_clickHandler(event:MouseEvent):void
{
cleanMemory();
navigator.pushView(menuPrincipalBelda);
}
private function cleanMemory():void
{
result.splice(0);
result = null;
System.gc();
}
Thanks in advance!
I discover the problem: I was not removing the EventListener, now is working fine.
I leave you guys with some examples. If you do not remove them, then memory increases a lot! Be careful with this.
stage.addEventListener("keyUp", handleButtons, false, 1);
stage.removeEventListener("keyUp",handleButtons,false);
xeasy.addEventListener(ResultEvent.RESULT, AppWS_resultHandler);
xeasy.removeEventListener(ResultEvent.RESULT,AppWS_resultHandler, false);
Thanks to everybody!!
Remember that Flex Builder uses the Flash virtual machine and this frees the memory when considered necessary, even if you try to force him to clean the garbage collector will not do if you have free memory and does not consider it necessary.
Test the movie embedded in the images you need in the application, and not constantly loading. Since this may be letting some low-level relationship.
regards
When I worked with GC I found that it became of advantage to try several different ways! I used 3 in total over time, but just can only find one at the moment as this was the one noticeable better working in this App. so here it is and if needed I can send the other two as well must just look for them!
private var gcCount:int;
private function startGCCycle():void {
gcCount = 0;
addEventListener(Event.ENTER_FRAME, doGC);
}
private function doGC(evt:Event):void {
flash.system.System.gc();
if(++gcCount > 1) {
removeEventListener(Event.ENTER_FRAME, doGC);
setTimeout(lastGC, 40);
}
}
private function lastGC():void{
flash.system.System.gc();
}
]]>
I just was looking at something else which you should try as well it worked for me very well!
FlexGlobals.topLevelApplication.deleteReferenceOnParentDocument(this) I used these in a creationComplete in MXML where I had to open 45 Main Canvases one after another but each time with three PopUps = 180 which was easy to handle in the way I worked the GC in! regards aktell

How to cancel 'seeking' state of Flex3 VideoDisplay class

I have a VideoDisplay instance playing some video. When I click on the video slider (also my component) the property videoDisplay.playheadTime is set and the videoDisplay.state goes from 'playing' into a 'seeking' state for a brief moment (the videoDisplay seeks for a new position and then plays the video again). Intended bevaiour.
But if I'm (or any random user) fast enough, I can set the playheadTime again while the player is still in 'seeking' state. When repeated several times every click is enqueued and the videoDisplay jump on every place of the video I have clicked(this is happening in an interval about 10-15 second after my last click). When I use live dragging the videoDisplay, overwhelmed by seekings, goes into 'error' state.
My question is - is there any way to cancel seeking state of the VideoDisplay class? For example player is in 'seeking' state, I set playheadTime, and the player forgets about last seeking and try to find the new place of the video.
I will downvote pointless answers like 'Use the Flex4 VideoPlayer class'!
One possible way is wrap the video display in a component and manage the seek a little better yourself. So if someone calls seek, make sure that the video is not currently seeking, if so, then wait till the current operation is complete before proceeding to the new one. If the user tries to seek again, discard all currently pending operations and make the latest one the next operation. Working on this exact problem right now.... Here's the code:
public function Seek(nSeconds:Number, bPlayAfter:Boolean):void
{
trace("Player Seek: "+ nSeconds);
var objSeekComand:VideoPlayerSeekCommand = new VideoPlayerSeekCommand(ucPlayer, nSeconds, bPlayAfter);
ProcessCommand(objSeekComand);
}
protected function ProcessCommand(objCommand:ICommand):void
{
if(_objCurrentCommand != null)
{
_objCurrentCommand.Abort();
}
_objCurrentCommand = objCommand
objCommand.SignalCommandComplete.add(OnCommandComplete);
objCommand.Execute();
}
Here's the Command
public class VideoPlayerSeekCommand extends CommandBase
{
private var _ucVideoDisplay:VideoDisplay;
private var _nSeekPoint:Number;
private var _bPlayAfterSeek:Boolean;
private var _bIsExecuting:Boolean;
public function VideoPlayerSeekCommand(ucVideoDisplay:VideoDisplay, nSeekPointInSeconds:Number, bPlayAfterSeek:Boolean, fAutoAttachSignalHandler:Function = null)
{
_ucVideoDisplay = ucVideoDisplay;
_nSeekPoint = nSeekPointInSeconds;
_bPlayAfterSeek = bPlayAfterSeek;
super(fAutoAttachSignalHandler);
}
override public function Execute():void
{
//First check if we are playing, and puase if needed
_bIsExecuting = true;
if(_ucVideoDisplay.playing == true)
{
_ucVideoDisplay.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, OnPlayerStateChangedFromPlay, false, 0, true);
_ucVideoDisplay.pause();
}
else
{
DoSeek();
}
}
protected function OnPlayerStateChangedFromPlay(event:MediaPlayerStateChangeEvent):void
{
_ucVideoDisplay.removeEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, OnPlayerStateChangedFromPlay);
if(_bIsExecuting == true)
{
if(_ucVideoDisplay.playing == false)
{
DoSeek();
}
else
{
throw new Error("VideoPlayerSeekAndPlayCommand - OnPlayerStateChangedFromPlay error");
}
}
}
private function DoSeek():void
{
if(_bIsExecuting == true)
{
_ucVideoDisplay.seek(_nSeekPoint);
CheckSeekComplete();
}
}
private function CheckSeekComplete():void
{
if(_bIsExecuting == true)
{
if (Math.abs( _ucVideoDisplay.currentTime - _nSeekPoint) < 2)
{
if(_bPlayAfterSeek == true)
{
_ucVideoDisplay.play();
}
DispatchAndDestroy();
}
else
{
CoreUtils.CallLater(CheckSeekComplete, .07);
}
}
}
override public function Abort():void
{
_bIsExecuting = false;
SignalCommandComplete.removeAll();
}
}
Im Using AS3 Signals here instead of events, and the CoreUtils.Call later you can use setInterval, or a Timer. But the idea is to not call seek until the video is paused, and to keep track of when the seek is complete.

UIImagePickerController Crashing Monotouch

I am trying to write an application, but it is constantly crashing when using the uiimagepickercontroller. I thought that it might be because I was not disposing of the picker after each use, but it will often freeze up on first run as well. Usually I'll take a picture and it just freezes, never asking to "use" the picture.
Do you have any suggestions? Here is my code. Has anyone gotten this to work?
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
myPicker = new UIImagePickerController();
myPicker.Delegate = new myPickerDelegate(this);
myAlbumButton.Clicked += delegate {
if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)){
myPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
myPicker.AllowsEditing = true;
this.PresentModalViewController (myPicker, true);
}else{
Console.WriteLine("cannot get album");
}
};
myCameraButton.Clicked += delegate {
if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
myPicker.SourceType = UIImagePickerControllerSourceType.Camera;
//myPicker.AllowsEditing = true;
this.PresentModalViewController (myPicker, true);
}else{
Console.WriteLine("cannot get camera");
}
};
}
private class myPickerDelegate : UIImagePickerControllerDelegate
{
private TestView _vc;
public myPickerDelegate ( TestView controller):base()
{
_vc = controller;
}
public override void FinishedPickingImage (UIImagePickerController myPicker, UIImage image, NSDictionary editingInfo)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
_vc.myImageView.Image = image;
myPicker.DismissModalViewControllerAnimated(true);
}
}
Try to call your event handlers code from the main thread by using BeginInvokeOnMainThread().
So my issue was very similar.
Instead of having a delegate class, I had the delegates inline for the picker.
For some reason the app froze every time after talking the image, not stopping in any breakpoint after that.
The solution that worked for me was to use this book:
http://www.scribd.com/doc/33770921/Professional-iPhone-Programming-with-MonoTouch-and-NET-C

How to get folder size in Adobe Air?

How to get folder size in Adobe Air?
Should be fairly simple using File.size. Just in case is confusing, folders in AIR are represented using the File class, which extends FileReference, thus the link to the FileReference documentation.
Recursive folder listings and contents processing
http://cookbooks.adobe.com/post_Recursive_folder_listings_and_contents_processing-9410.html
...has sufficient sample code in it to get you started.
my implementation is:
public static function getFileSize(file:File):Number{
var result:Number = 0;
if(file == null || file.exists == false) {
return 0;
}
if(file.isDirectory){
var files:Array = file.getDirectoryListing();
for each (var f:File in files) {
if(f.isDirectory){
result += getFileSize(f);
}else{
result += f.size;
}
}
}else{
return file.size;
}
return result;
}

Resources