# Applying functions to external SWFs

**URL:** <https://forum.kirupa.com/t/applying-functions-to-external-swfs/222471>\
**Category:** Uncategorized\
**Created:** [April 13, 2007, 6:59pm UTC](https://forum.kirupa.com/t/applying-functions-to-external-swfs/222471 "2007-04-13T18:59:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![princematt](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@princematt](https://forum.kirupa.com/u/princematt)\
**Post date:** [April 13, 2007, 6:59pm UTC](https://forum.kirupa.com/t/applying-functions-to-external-swfs/222471/1 "2007-04-13T18:59:51Z")

</div>

Hey guys,

First post here, and I need help…I’m a graphic designer trying to muddle through enough AS to create a bilingual site and I would apreciate it immeasurably if someone could offer me some advice with an AS dilemma. So here goes…

I start it off by setting a variable, “currentlang” upon clicking either the “english” or “french” button. Like so:

[COLOR=blue]on (release) {[/COLOR]  
[COLOR=blue]\_global.currentlang = 1; [COLOR=dimgray]//english[/COLOR]  
\_parent.gotoAndStop(3); [COLOR=gray]//action begins on the 3rd frame of main movie[/COLOR]

}[/COLOR]

[COLOR=black]or[/COLOR]

[COLOR=blue]on (release) {[/COLOR]  
[COLOR=blue]\_global.currentlang = 0; [COLOR=dimgray]//french[/COLOR]  
\_parent.gotoAndStop(3);

}[/COLOR]

[COLOR=black]It seems to work fine. We’re in.[/COLOR]

Then I’ve created a function in my main movie that toggles the language back and forth from English to French by telling movie clips on the stage to go to the frame with French/English content. Here’s the code on the timeline of the main movie:

[COLOR=blue]toggleLanguage = function () { if (\_global.currentlang == 0) {[/COLOR]  
[COLOR=blue]content.gotoAndPlay(2);[/COLOR]  
[COLOR=blue]\_global.currentlang=1;[/COLOR]

[COLOR=blue]} else if[/COLOR]  
[COLOR=blue](\_global.currentlang == 1){[/COLOR]  
[COLOR=blue]content.gotoAndPlay(1);[/COLOR]  
[COLOR=blue]\_global.currentlang=0;[/COLOR]

[COLOR=blue]}[/COLOR]  
[COLOR=blue]}[/COLOR]

Here’s the code on my button that I click to toggle back and forth:

[COLOR=blue]on (release) {[/COLOR]  
[COLOR=blue]\_parent.toggleLanguage();[/COLOR]  
[COLOR=blue]}[/COLOR]

This works fine for the clips on the main movie, but what happens when I load in external SWF’s. How could I make my function “toggleLanguage” talk to newly loaded clips? On the external clip I’m loading in, I have the following code on the timeline:

[COLOR=blue]if (\_global.currentlang == 1) {[/COLOR]  
[COLOR=blue]this.header.gotoAndPlay(1);[/COLOR]  
[COLOR=blue]} else if (\_global.currentlang == 0) {[/COLOR]  
[COLOR=blue]this.header.gotoAndPlay(2);[/COLOR]  
[COLOR=blue]}[/COLOR]

This works fine when the new movie loads in, meaning that if my [COLOR=blue]"\_global.currentlang" [/COLOR][COLOR=black]on the container movie is set to French, the loaded SWF will display “Bienvenue” rather than “welcome”, and vice versa. The problem arises when I[/COLOR][COLOR=black] try to toggle the language. It only toggles the language of the clips on the main timeline and not the newly loaded ones. Like I said, any help would be greatly appreciated, as this is starting to drive me bananas, not being an experienced scripter and all. [/COLOR]

Have at it!

Thanks!

Matt
