843 posts
  • Elite Author
  • Exclusive Author
  • Has been a member for 6-7 years
  • Won a Competition
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+2 more
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.

8194 posts Community Moderator
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 6-7 years
  • United Kingdom
  • Contributed a Tutorial to a Tuts+ Site
  • Won a Competition
  • Contributed a Blog Post
  • Beta Tester
  • Bought between 50 and 99 items
+4 more
MSFX Volunteer moderator 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 :)

843 posts
  • Elite Author
  • Exclusive Author
  • Has been a member for 6-7 years
  • Won a Competition
  • Sold between 100 000 and 250 000 dollars
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+2 more
marcfolio says

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

8194 posts Community Moderator
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 6-7 years
  • United Kingdom
  • Contributed a Tutorial to a Tuts+ Site
  • Won a Competition
  • Contributed a Blog Post
  • Beta Tester
  • Bought between 50 and 99 items
+4 more
MSFX Volunteer moderator says

you’re welcome :)

by
by
by
by
by
by