Skip to main content

Flex Cache Problem

There is very big problem in flex that's cache problem. When I was developing a Rich Internet application. I faced flex cache problem in Internet Explore & Firefox browser i was stuck badly.

Then I wrote this code for avoiding flex cache problem & i think it works a bit. Well still working on it.

I have added this code into index.template.html which is located into flex project html-template/index.template.html.

<Script Language="javascript">
var url = location.href;
var ots = parseInt(url.substring(url.indexOf("=")+1,url.length))+6000;
var dt = new Date();
var n = dt.getTime();
if(url.indexOf("?timeStamp=")!=-1)
{
if(isNumber(ots) && ots!=""){
if(nts>ots){
location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+nts;
}
}else{
location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+newTimeStamp;
}
}else{

location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+nts;
}

function isNumeric(val)
{
var vc = "0123456789.";
var isnum=true;
var c;
for (i = 0; i < val.length && isnum == true; i++)
{
c = val.charAt(i);
if (vc.indexOf(c) == -1)
{
isnum = false;
}
}
return isnum;
}
</Script>


Changes which i made in swf javascript code.


<script language="JavaScript" type="text/javascript">
<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if ( hasProductInstall && !hasRequestedVersion ) {
// DO NOT MODIFY THE FOLLOWING FOUR LINES
// Location visited after installation is complete if installation is required
var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
var MMredirectURL = window.location;
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
var MMdoctitle = document.title;

AC_FL_RunContent(
"src", "playerProductInstall",
"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
"width", "${width}",
"height", "${height}",
"align", "middle",
"id", "${application}",
"quality", "high",
"bgcolor", "${bgcolor}",
"name", "${application}",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else if (hasRequestedVersion) {
// if we've detected an acceptable version
// embed the Flash Content SWF when all tests are passed
AC_FL_RunContent(
"src", "${swf}"+"?run="+newTimeStamp,
"width", "${width}",
"height", "${height}",
"align", "middle",
"id", "${application}",
"quality", "high",
"bgcolor", "${bgcolor}",
"name", "${application}",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else { // flash is too old or we can't detect the plugin
var alternateContent = 'Alternate HTML content should be placed here. '
+ 'This content requires the Adobe Flash Player. '
+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
document.write(alternateContent); // insert non-flash content
}
// -->
</script>


Httpservice not refreshing there's another point of flex cache. Some time Httpservice does not show refresh result in second time so we just use a parameter which we can send into with Httpservice Request.

Flex Function
public static function uniqueNum():String{
var d:String = new Date().getDate().toString();
var m:String = new Date().getMonth().toString();
var y:String = new Date().getFullYear().toString();
var h:String = new Date().getHours().toString();
var mm:String = new Date().getMinutes().toString();
var s:String = new Date().getSeconds().toString();
var unique:String = d + m + y + h + mm + s ;
return unique;
}



above code genrate unique number every request genrate new unique number and browser takes this url as a new url in every request. we can implement it.

httpservice.url = "index.php";
httservice.send(num:uniqueNum);


so it will return you always refresh result.

Comments

  1. It is working fine with firefox But there is problem with IE.

    ReplyDelete
  2. We can also avoid flex cache problem using meta tags..

    ReplyDelete

Post a Comment

Popular posts from this blog

How to send variables from on SWF flex file to another SWF file Using Flex.

How to Communicate From one SWF Flex file to another SWF Flex File ? See the below example, This is loading external swf flex file into parent SWF File and sharing the data or variable from parent to child and child to parent. Parent.mxml CODE: 1: <?xml version="1.0" encoding="utf-8"?> 2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%"> 3: <mx:Script> 4: <![CDATA[ 5: import mx.events.CloseEvent; 6: import mx.controls.SWFLoader; 7: import mx.managers.PopUpManager; 8: import mx.containers.TitleWindow; 9: import mx.controls.Alert; 10: 11: public var tw:SWFPlaceHolder; 12: 13: public function launchExternalSWF(title:String,swfFilePath:String):void{ 14: 15: /

How to Format My Source Code For Blogger ?

How to format my source code for blogger, blog, Blogging, weblog & website ? Now you can format you source code for blogger, blog, Blogging, weblog & website using online source code formatter. This application build in javascript. This source code beautifier or formatter provide for your blogger, Blog and websites a good code indentation. You can can format your source code with alternative background using <pre> tag. It does not add unnecessary tags in formatted source code excpet <pre> and <code> so just try onto your source code for blog or blogging & website posts . This is absolutly free online line source code formatter tool for your blogger & website. http://codeformatter.blogspot.com/ See example.. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT=""> <META NAME="A

How To Change Form Action at Runtime

How to change Form action at runtime using javascript. This the example which will change html form action at runtime. CODE: 1 :   <html> 2 :   <head> 3 :   <Script Language="javascript"> 4 :   function change_action(){ 5 :   var frm_obj=document.getElementById("frm"); 6 :   frm_obj.action="http://www.google.com"; 7 :   } 8 :   </Script> 9 :   </head> 10 :   <body> 11 :   <form id="frm" action="abc.php" method="post" onsubmit="return change_action()"> 12 :   UID &nbsp;&nbsp;<input type="text"><br> 13 :   PWD <input type="Password"><br><br> 14 :   <input type="submit" value="submit"> 15 :   </form> 16 :   </body> 17 :   </html>