Solved

Javascript call to swf function (using the as3 externalInterface API) not working 100% of the time

Posted on 2008-10-20
5
797 Views
Last Modified: 2013-11-11
Hello,
I created an AS3 swf module which, from a javascript call, load and image into a movieclip for further transformation.
I ran it under ff3 and ie6/7 hundreds of time with no issue, but when I tried to test it under opera, I encountered some problems :

Sometimes the page loads but the javascript flashcall doesn't fire (javascript function fires but not the flashcall in it), so my image doesn't load in the swf file ! If I hit refresh on the page : one time it is on, one time it is off.

The bug also appear on ff and opera when I "go back" to this page (I'm browsing the website, going one page further and then do "previous page").
_____

The javascript function I call on page load is : "thisMovie("productviewer").loadImage(image)" and when firefox/opera decide not to show my image : the error console tells me that "thisMovie("productviewer").loadImage is not a function".

How do I make it work ?
// Javascript functions
 
function thisMovie(movieName) {
     var isIE = navigator.appName.indexOf("Microsoft") != -1;
     return document[movieName];
}
 
function stickerInitiate(image){
     thisMovie("productviewer").loadImage(image);
}
 
// Html call (based on mootools)
 
window.addEvent('load', function() {
     stickerInitiate(myimage);
});

Open in new window

0
Comment
Question by:dagobert_renouf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Expert Comment

by:stretchyboy
ID: 22771726
Hi, this may not be the full answer as what is appearing in your debug log seems odd but the symptoms you are getting are likely to be because the onload event only runs in FF and Opera when a page is loaded from the network not when it is retrieved from cache. for that you need to use the onpageshow event. As discussed here  http://developer.mozilla.org/en/Using_Firefox_1.5_caching

The snippet below should give you a hint.



<script type="text/javascript">
function onLoad() {
	loadOnlyFirst();
	onPageShow();
}
 
function onPageShow() {
//calculate current time
	var currentTime= new Date();
	var year=currentTime.getFullYear();
	var month=currentTime.getMonth()+1;
	var day=currentTime.getDate();
	var hour=currentTime.getHours();
	var min=currentTime.getMinutes();
	var sec=currentTime.getSeconds();
	var mil=currentTime.getMilliseconds();
	var displayTime = (month + "/" + day + "/" + year + " " + 
		hour + ":" + min + ":" + sec + ":" + mil);
	document.getElementById("timefield").value=displayTime;	
}
 
function loadOnlyFirst() {
	document.zipForm.name.focus();
}
</script>
</head>
<body onload="onLoad();" onpageshow="if (event.persisted) onPageShow();"> 

Open in new window

0
 

Author Comment

by:dagobert_renouf
ID: 22776667
This solution allow firefox to work everytime, which is good.

However my main issue is with opera (25% of my users), and it's still not working with that solution.
0
 

Expert Comment

by:stretchyboy
ID: 22780067
Ok, I am only skimming things quickly so I apologise for not testing that out (I was more than half scared the issue was to do with the swf so wasn't sure I could test it for you).

If you instead have a look at this example

http://arieslink.sitebar.org/onload-1.html

this seems to be running a pretty bomb proof piece of code the discussion about this topic has been running here for years and this is their latest effort. Hope that helps.  If this is over the top then just consider

            window.addEventListener('DOMContentLoaded', init, false);

which should work for both FF and Opera.
0
 

Accepted Solution

by:
dagobert_renouf earned 0 total points
ID: 22780622
thanks for your answer stretchyboy, but I just came with another solution that satisfies me.
I'm now using swfloader and it all works fine, with no "cache tweaking and all" so it seems cleaner to me.

who wants the 500pts :-D ?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 43
Add somewhat of a wildcard to your javascript 12 30
close pop up windows when logout or main window closes 17 55
Boolean 13 24
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question