Hi All,
I've sussed the issue and the swfobject code and my js above does
indeed work - very fast!
However what i've noticed is that it only works with swf files that
have something in them.
My flex and/or as classes looked like this:
AS ONLY
###############################################################################
->
package
{
import flash.display.Sprite;
import flash.external.ExternalInterface;
[SWF(widthPercent="100", heightPercent="100", frameRate="40",
backgroundColor="#242424")]
public class a extends Sprite
{
public function a()
{
if(ExternalInterface.available)
{
ExternalInterface.marshallExceptions = true;
try
{
ExternalInterface.call("initializedOk", "test");
}
catch(e:Error){}
}
}
}
}
FLEX
###############################################################################
->
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
applicationComplete="_initJS()"
creationComplete="_initApp()">
<mx:Script>
<![CDATA[
import flash.utils.getQualifiedClassName;
import flash.external.ExternalInterface;
private var __swfName:String;
private function _initJS():void
{
__swfName = getQualifiedClassName(this);
if (ExternalInterface.available)
{
ExternalInterface.marshallExceptions =
true;
try
{
ExternalInterface.call("initializedOk",
__swfName);
}
catch(e:Error){}
}
}
private function _initApp():void{}
]]>
</mx:Script>
</mx:Application>
Just empty except for the ExternalInterface logic. When i try to embed
either of these... page renders sloooooooooow
But if i grab a swf from anywhere else (and of any size), the embed is
lightning fast as expected....
So what does that actually mean?????..... i will try to find out.
Cheers
Doug
On Feb 17, 9:28 am, VocalPlayboy <[email protected]> wrote:
> Hey Vince,
>
> Ok good call with the manager idea but i still don't think it will
> make a difference, the delay comes from the actual js embed, as if
> it's waiting for each swf to load maybe (i don't know).
> If i try the same code locally it still takes just as long and if i
> swap out my flex component swfs for normal swfs (so no flex framework)
> or need for an rsl it still takes the same amount of time.
>
> It would be good to see some other examples of multi swf embedding
> techniques.
>
> Cheers
> Doug
>
> On Feb 16, 6:50 pm, Vincent Polite <[email protected]>
> wrote:
>
> > Hey Vocal, I took a brief look at your page. I haven't looked at the actual
> > SWFObject code, because generally speaking, if it's implemented correctly
> > it's usually not the problem.
>
> > Using the Net Panel tool in Firebug, I was able to note that the number of
> > connections being farmed out to your server, DNS lookups contribute to the
> > lions share of delay for your page loading. Using this link (maybe
> > outdated) as reference, it notes that there is a default max # of
> > connections allowed from the same page by Firefox. I'm assuming that other
> > browsers may have this limitation as well to make it slightly less trivial
> > for a single browser to bring a web server to it's knees?
>
> >http://groups.google.com/group/firebug/browse_thread/thread/04d1a83b9...
>
> > I looked at your demo page, it didn't seem to hang for me, just took a bit
> > using FF3.5 on a PC. Using IE8 on the same PC, I got similar performance
> > characteristics. At first blush, it would seem like your server is the
> > limiting factor, but maybe I'm wrong about that.
>
> > ----
>
> > 15 minutes later.
>
> > Took a gander at your code. You actually do something very similar to some
> > work I did to deal with a random number of SWFObjects on a page in terms of
> > pushing elements into an array and what not. You might want to consider
> > abstracting these for loops you have into something called a
> > SWFObjectManager class and instead of passing around the objects themselves
> > which if you're not passing by reference might be more CPU work than not,
> > that you just pass the element names around and only perform the operations
> > as needed. You would need to test out which is more efficient though.
>
> > SWFObjectManager.register("nameofDiv", "pathtoSWF", otherparams);
> > SWFObjectManager.register("...","...",otherparams);
>
> > if you use a lightweight framework like jQuery you could even tag your divs
> > with something like class="swfobject" and then use a .each() selector to
> > grab all the swfobjects on your page and then just instantiate your
> > swfobjects based on the meta data on your page.
>
> > i.e. <div id="foo" class="swfobject" >Alt Content</div>
>
> > Then your JS would be potentially reduced quite a bit:
>
> > $(document).ready(function() {
> > $(".swfobject").each(function() {
> > divId = $(this).id;
> > swfName = divId+".swf";
> > properties = {data:swfName, width:100, height: 100};
> > parameters = {menu: false};
> > swfobject.createSWF(properties, paramters, divId);
> > }
>
> > }
>
> > It does appear that you are reusing the global arrays for some reason, so
> > for maintainabilities sake, you might consider upgrading your arrays to a
> > type of SWFObjectManager class and make your calls a bit more compact.
>
> > i.e. your SWFObjectManager class would use a loop like the one above to
> > naturally grab all the divs of class swfobject and define them
> > appropriately, so your inline JS gets reduced to:
>
> > $(document).ready(function() {
> > SWFObjectManager.init();
>
> > });
>
> > So sorry, stream of consciousness after Chinese New Year. If this confuses
> > or is off point for you, then dump this in the recycle bin.
>
> > VincentOn Tue, Feb 16, 2010 at 9:57 AM, VocalPlayboy
> > <[email protected]> wrote:
> > > Check out these 2 demos.
>
> > > First one the page hangs -
> > >http://www.strangeloopstudios.com/swfobject_demo/
>
> > > Second one there is a slight delay but at least it loads the page
> > > quicker -http://www.strangeloopstudios.com/swfobject_demo2/
>
> > > I'll also check out your app later, got to head out now, but thanks.
>
> > > Doug
>
> > > On Feb 16, 5:02 pm, Steve <[email protected]> wrote:
> > > > Is it the size of your swfs themselves? If not, I have created an
> > > > application that does what you want and writes the code for you. Just
> > > > browse to your web page, drag and drop your swfs onto the page where
> > > > you want them, set their properties, and click publish:
>
> > > >http://norrisoftenhance.ning.com/
>
> > > > The application includes a getting started tutoriaal and help.
>
> > > > Steve
>
> > > > On Feb 16, 9:38 am, VocalPlayboy <[email protected]> wrote:
>
> > > > > Hi All,
>
> > > > > I'm building a modular video application with a bunch of Flex
> > > > > components and part of the requirement is to use javascript as a
> > > > > controller to communicate between my data model and my flex component
> > > > > views.
>
> > > > > The first part of this task involves embedding components to specific
> > > > > div tags in a html page. I've got this to work great but it's just
> > > > > really really really slow - like 10 seconds slow to embed 7 swfs. I've
> > > > > tested and the issue is to do with swfobject (possibly because of the
> > > > > way i've coded it).
>
> > > > > Here's my HTML:
>
> > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
> > >http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> > > > > <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
> > > > > <head>
> > > > > <title>AMX JS Player</title>
> > > > > <meta http-equiv="Content-Type" content="text/html;
> > > charset=utf-8" /
>
> > > > > <script type="text/javascript"
> > > src="./html/swfobject/swfobject.js"></
> > > > > script>
> > > > > <script type="text/javascript"
> > > src="./html/amxjs/player.js"></
> > > > > script>
> > > > > </head>
> > > > > <body>
> > > > > <div id="AMXJSPlayer_Model">
> > > > > <p>Model</p>
> > > > > </div>
> > > > > <div id="AMXJSPlayer_Category">
> > > > > <p>Category View</p>
> > > > > </div>
> > > > > <div id="AMXJSPlayer_Video">
> > > > > <p>Video View</p>
> > > > > </div>
> > > > > <div id="AMXJSPlayer_Meta">
> > > > > <p>Meta View</p>
> > > > > </div>
> > > > > <div id="AMXJSPlayer_Latest">
> > > > > <p>Latest View</p>
> > > > > </div>
> > > > > <div id="AMXJSPlayer_Programme">
> > > > > <p>Programme View</p>
> > > > > </div>
> > > > > <div id="AMXJSPlayer_List">
> > > > > <p>List View</p>
> > > > > </div>
> > > > > </body>
> > > > > </html>
>
> > > > > And here is the simple javascript i'm using in addition to
> > > > > swfobject.js:
>
> > > > > var FLASH_VERSION = "9.0.124";
> > > > > var DIV_IDS = new Array("AMXJSPlayer_Model", "AMXJSPlayer_Category",
> > > > > "AMXJSPlayer_Meta", "AMXJSPlayer_Video", "AMXJSPlayer_Latest",
> > > > > "AMXJSPlayer_Programme", "AMXJSPlayer_List");
> > > > > var moduleDivs = new Array();
> > > > > var moduleSwfs = new Array();
>
> > > > > if (swfobject.hasFlashPlayerVersion(FLASH_VERSION))
> > > > > {
> > > > > swfobject.addDomLoadEvent(validateDivs);}
>
> > > > > else
> > > > > {
> > > > > alert("No Flash Player or older version than is required!");
>
> > > > > }
>
> > > > > function validateDivs()
> > > > > {
> > > > > for (var i=0; i<DIV_IDS.length; ++i)
> > > > > {
> > > > > var divId = DIV_IDS[i];
> > > > > var currentDiv = document.getElementById(divId);
> > > > > if(currentDiv)
> > > > > {
> > > > > moduleDivs.push(currentDiv);
> > > > > }
> > > > > else
> > > > > {
> > > > > //no div available
> > > > > }
> > > > > }
> > > > > for (var j=0; j<moduleDivs.length; ++j)
> > > > > {
> > > > > var validDiv = moduleDivs[j];
> > > > > initializeSwf(validDiv);
> > > > > }
>
> > > > > }
>
> > > > > function initializeSwf(divId)
> > > > > {
> > > > > var divId = divId.id;
> > > > > var swfName = divId+".swf";
> > > > > var properties = { data:swfName, width:"100", height:"100"};
> > > > > var parameters = { menu:"false" };
> > > > > var theSwf = swfobject.createSWF(properties, parameters,
> > > divId);
> > > > > moduleSwfs.push(theSwf);
>
> > > > > }
>
> > > > > At first i thought it might be my flex swfs, so i created a
> > > > > framework.swz RSL...no difference.
> > > > > Then i decided to remove any trace of Flex and just published
> > > > > actionscript only swf's so file size went from 100800 bytes to 600
> > > > > bytes... still no difference
>
> > > > > So it's defo something to do with swfobject. I also tried the static
> > > > > embed approach but to be honest although it did work, it's a nightmare
> > > > > to ensure our clients will copy the code exactly as required when
> > > > > creating their own pages. Just adding a div with specific id to swap
> > > > > out is the preferred option.
>
> > > > > Anyone got any ideas what's happening in the background when i'm
> > > > > calling 'createSwf' and is there any way to make things happen any
>
> ...
>
> read more »
--
You received this message because you are subscribed to the Google Groups
"SWFObject" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/swfobject?hl=en.