Reputation: 1
I am new in flex development so I need a help to understand logic and solution for my requirement, My Concern is when I login to particular page i want to stored a navigation menu name in any variable or any collection so I can check my last visited page name by that variable or collection data. Is there any possibility where I check what was my last page visited. I have a requirement like this to handle refresh event in flex pages. when I refresh my page I want to go back to same page your valuable comments and your knowledge is needed.
Upvotes: 0
Views: 183
Reputation: 1
public function initSharedObject(userAgent:String):String
{
Alert.show("userAgent : "+userAgent+" substring : "+userAgent.substr(0,15));
sharedObj = SharedObject.getLocal("SO_"+userAgent.substr(0,15));
if (sharedObj.size > 0)
var currentState:String =sharedObj.data.tasks;
//Alert.show("curentState in init "+currentState);
return currentState;
}
public function saveTasks(curentState:String):void {
//Alert.show("curentState "+curentState);
sharedObj.data.tasks = curentState;
sharedObj.flush();
}
public function deleteSavedTasks(userAgent:String):void {
//Alert.show("Im in Delete ...");
//Alert.show("userAgent : "+userAgent+" substring : "+userAgent.substr(0,11));
sharedObj = SharedObject.getLocal("SO_"+userAgent.substr(0,15));
sharedObj.clear();
}
Hi Adrain , above code I am using in the share Objects handling in my application,But Sub String of userAgent String give me Output :
IE 11 : userAgent : Mozilla/5.0 (Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; MS-RTC LM 8; rv:11.0) like Gecko substring : Mozilla/5.0
Mozilla : userAgent : Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0 substring : Mozilla/5.0
Please check the above code and its substring output. and please let me know.
Upvotes: 0
Reputation: 4340
Why not to create a NavigationManager class where you can store in static variables the informations you need.
For example
class MyNavigationManager
{
private static var _visitedPages:Array = [];
public static function pushPage(pageName:String):void
{
_visitedPages.push(pageName);
}
public static function get currentPageName():String
{
if(_visitedPages.length > 0 )
return _visitedPages[_visitedPages.length -1 ];
return null;
}
// ...something else you may need, maybe popPage():Sting...
}
And to use it you can call from any place in your app
MyNavigationManager.pushPage("Home");
MyNavigationManager.pushPage("User Account");
trace(MyNavigationManager.currentPageName);
Update 1
Since you need independent SharedObjects based on browser type (as requested in the comments...)
Get browser name
var userAgent : String = String(ExternalInterface.call("function(){return navigator.userAgent}"));
trace (userAgent);
Use userAgent to create different shared objects, and initialize like this.
public var sharedObj:SharedObject;
private function initSharedObject():void
{
sharedObj = SharedObject.getLocal("SO_"+userAgent.subStr(0,6));
}
Hope that it is better now.
Upvotes: 1