ActiveDen

Yup another help request from me: Passing flashVars to a subloaded swf

836 posts
  • Has been a member for 3-4 years
  • Won a Competition
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
marcfolio says

First I need to say thank you to the great community we have here. We have some smart actionscripting cookies here.

Now on to my question: So I’ve been able to load a swf into my parent swf and pass some flashvars via the query string. Genius. So for example:

var video:Loader=new Loader();
video.load(new URLRequest("local_video.swf?v=movie.mp4"));
video.contentLoaderInfo.addEventListener(Event.COMPLETE, videoloaded);
function videoloaded(e:Event):void {
    addChild(video);
}

It works great. But I’m afraid that if I use the method multiple times each time because the variables will be different it’ll cause the viewers browser to download new version of the same swf file each time verses using the cached version like it would if there was no query string.

So I’m wondering is there’s another way to pass the flashvars to the subloaded swf.

1 year ago
6471 posts
  • Has been a member for 4-5 years
  • Won a Competition
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 50 and 99 items
  • United Kingdom
  • Referred between 10 and 49 users
MSFX says

you can cast the loaded swf as a movieclip and then access its public variables and functions in the same way you’d access those within a class…

So, for example:

var loader:Loader = new Loader();
... code for loading...

function loaded(e:Event):void
{
    // cast loaded swf to movieclip
    var swfAsMovieClip:MovieClip = MovieClip(e.currentTarget.content); 

    // access variable and functions
    swfAsMovieClip.variableName = "whatever you want";
    swfAsMovieClip.functionName("with parameter");

    // add to the display list
    addChild(swfAsMovieClip); 
}

So in the above your loaded swf has a variable called ‘variableName’ and a function with one parameter called ‘functionName’ both of which you can read and write :)

Hope that helps :)

1 year ago
MSFX is a moderator
836 posts
  • Has been a member for 3-4 years
  • Won a Competition
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
marcfolio says

Fantastic. I’ll give it a try. Thank you for coming to the rescue.

1 year ago
6471 posts
  • Has been a member for 4-5 years
  • Won a Competition
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 50 and 99 items
  • United Kingdom
  • Referred between 10 and 49 users
MSFX says

you’re welcome :)

1 year ago
MSFX is a moderator
by
by
by
by
by