# Passing a variable to external .swf

**URL:** <https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417>\
**Category:** flash\
**Created:** [April 21, 2006, 3:31am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417 "2006-04-21T03:31:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 21, 2006, 3:31am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/1 "2006-04-21T03:31:06Z")

</div>

Hey guys i have a gallery that when any thumbnail is pressed it implements the following variable:

on (release) {  
set (\_global.thumb, dream1);  
\_parent.\_parent.\_parent.blank.loadMovie(“ProjectFrame.swf”);  
}

Now im trying to acces that variable “thumb” in ProjectFrame.swf but i cant seem to do it.

Anyone know how I can pass the variable out?

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 21, 2006, 1:40pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/2 "2006-04-21T13:40:07Z")

</div>

Is it not possible to send a variable to a loaded .swf?

---

<div class="post-metadata">

**Author:** ![vini](https://avatars.discourse-cdn.com/v4/letter/v/c77e96/32.png) [@vini](https://forum.kirupa.com/u/vini)\
**Post date:** [April 21, 2006, 1:50pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/3 "2006-04-21T13:50:49Z")

</div>

Well, I think it might be possible through LocalConnection

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 21, 2006, 1:53pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/4 "2006-04-21T13:53:38Z")

</div>

You can set it after the swf is loaded.

scotty(-:

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 21, 2006, 4:37pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/5 "2006-04-21T16:37:10Z")

</div>

So do i do like a onLoad function that then will set (\_global.thumb, dream1);?

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 21, 2006, 4:39pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/6 "2006-04-21T16:39:10Z")

</div>

■■■■ i need to get better at actionscript that or start sucking up to Voets.  
Maybe ill start buying him stuff.:ponder:

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 21, 2006, 4:51pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/7 "2006-04-21T16:51:30Z")

</div>

No, no onLoad, something like

```auto
//put this in the main time line on a frame
//change "thumb" to the path to your thumb
thumb.onRelease = function() {
	preload("ProjectFrame.swf", dream1);
};
function preload(clip, vari) {
	var temp = this.createEmptyMovieClip("temp", 999);
	blank.loadMovie(clip);
	temp.onEnterFrame = function() {
		if (blank._width) {
			//this will set variable 'thumb' inside ProjectFrame.swf
			blank.thumb = vari;
			delete this.onEnterFrame;
		}
	};
}

```

scotty(-:

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 21, 2006, 6:43pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/8 "2006-04-21T18:43:26Z")

</div>

Oh man scotty that looks great the thumbnails currently have rollovers in them as their basically just movieclips is there a way i can target the rollover from this code as well. The label inside is called “over”

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 21, 2006, 7:17pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/9 "2006-04-21T19:17:09Z")

</div>

```auto
thumb.onRollOver = function() {
    this.gotoAndPlay("over");
};

```

change thumb to the path you need.

scotty(-:

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 21, 2006, 8:06pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/10 "2006-04-21T20:06:31Z")

</div>

Scotty i cant thank you enough man thanks a lot this helps hugely.  
Chris

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 22, 2006, 5:21am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/11 "2006-04-22T05:21:49Z")

</div>

no problem :thumb:

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 23, 2006, 9:29pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/12 "2006-04-23T21:29:43Z")

</div>

Hey Scotty this is the changes i made to your code

**tech.main2.buttech1.onRelease** = function() {  
preload(“ProjectFrame.swf”, **[COLOR=darkred]tech1[/COLOR]**);

};  
function preload(clip, vari) {  
var temp = this.createEmptyMovieClip(“temp”, 999);  
blank.loadMovie(clip);  
temp.onEnterFrame = function() {  
if (blank.\_width) {  
//this will set variable ‘thumb’ inside ProjectFrame.swf  
blank.thumb = vari;  
delete this.onEnterFrame;  
}  
};  
}

Okay it works perfectly as far as opening up the movieclip projectframe.swf but its still telling me the variable is undefined.

Where in the code do I put where it sets the var THUMB when the button is clicked im assuming its this spot:  
preload(“ProjectFrame.swf”, **[COLOR=darkred]tech1[/COLOR]**);  
Now [COLOR=darkred] **tech1** [/COLOR] is the variable Im trying to pass but its not passing it.

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 24, 2006, 8:14am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/13 "2006-04-24T08:14:04Z")

</div>

Do you want to pass it as a string or you want to target tech1 in Project.swf?

scotty(-:

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 24, 2006, 5:53pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/14 "2006-04-24T17:53:41Z")

</div>

In the ProjectFrame.swf I have a loader in the first frame with this code that using the variable **thumb** will be able to load the appropriate Jpeg.

myLoader.\_alpha=0;  
myLoader.contentPath = thumb".jpg";  
this.onEnterFrame = function() {  
myLoader.\_alpha +=10;  
if(myLoader.\_alpha \>=100) {delete this.onEnterFrame;};  
}

---

<div class="post-metadata">

**Author:** ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)\
**Post date:** [April 24, 2006, 6:26pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/15 "2006-04-24T18:26:01Z")

</div>

> [@Solidus](#):
>
> damn i need to get better at actionscript that or start sucking up to Voets.  
> Maybe ill start buying him stuff.:ponder:

see, you were sucking up to the wrong guy! 😛

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 24, 2006, 6:35pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/16 "2006-04-24T18:35:20Z")

</div>

To set the variable in the main fla

```auto
btn.onRelease = function() {
	preload("ProjectFrame.swf", "tech1");
};
function preload(clip, vari) {
	var temp = this.createEmptyMovieClip("temp", 999);
	blank.loadMovie(clip);
	temp.onEnterFrame = function() {
		if (blank._width) {
			blank.setvar(vari);
			delete this.onEnterFrame;
		}
	};
}

```

and in Project Frame fla

```auto
function setvar(vari) {
	container.loadMovie(vari+".jpg");
	//or put what you want to do here
}

```

scotty(-:

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 24, 2006, 9:00pm UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/17 "2006-04-24T21:00:32Z")

</div>

Scotty thanks for the patience man ill try this out tonight and let you know if it worked.  
Thanks again man!  
Chris

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 25, 2006, 4:33am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/18 "2006-04-25T04:33:30Z")

</div>

Scotty please dont hate me forever cause im so lame at this stuff but It still is telling me the variable is undefined when I export it.

In the Main.swf I have this Actionscript:  
tech.main2.buttech1.onRelease = function() {  
preload(“ProjectFrame.swf”, “tech1”);  
};  
function preload(clip, vari) {  
var temp = this.createEmptyMovieClip(“temp”, 999);  
blank.loadMovie(clip);  
temp.onEnterFrame = function() {  
if (blank.\_width) {  
blank.setvar(vari);  
delete this.onEnterFrame;  
}  
};  
}

And then in frame 15 of projectframe.swf I have this:

function setvar(vari) {  
}  
myLoader.\_alpha=0;  
myLoader.contentPath = vari+".jpg";  
this.onEnterFrame = function() {  
myLoader.\_alpha +=10;  
if(myLoader.\_alpha \>=100) {delete this.onEnterFrame;};  
}

Now I could just be completely dumb but should I be changing somewhere that I am setting the variable Vari to equal tech1 when the button: buttech1is pressed. Cause right now I dont see where its defining either the variable “vari” or the variable “thumb”??

---

<div class="post-metadata">

**Author:** ![Solidus](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Solidus](https://forum.kirupa.com/u/Solidus)\
**Post date:** [April 25, 2006, 4:39am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/19 "2006-04-25T04:39:37Z")

</div>

If it would make more sense I posted the FLA’s [here](http://www.globalstudio.com/clients/flash.zip)

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [April 25, 2006, 6:32am UTC](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417/20 "2006-04-25T06:32:48Z")

</div>

iIn Projects fla, skip all actions you have on the (tech) buttons and rename buttech1 to tech1.  
Change the code in frame 64 (main timeline) like this

```auto
stop();
if (_global.project == 1) {
	tech.gotoAndPlay(2);
}
if (_global.project == 2) {
	dream.gotoAndPlay(2);
}
for (var i = 1; i<=6; i++) {
	var btn = tech.main2["tech"+i];
	btn.id = i;
	btn.onRollOver = function() {
		this.gotoAndPlay("over");
	};
	btn.onRelease = function() {
		preload("ProjectFrame.swf", "tech"+this.id);
	};
}
function preload(clip, vari) {
	var temp = this.createEmptyMovieClip("temp", 999);
	blank.loadMovie(clip);
	temp.onEnterFrame = function() {
		if (blank._width) {
			blank.setvar(vari);
			delete this.onEnterFrame;
		}
	};
}

```

In ProjectFrame in make an empty mc (instance name ‘container’) and put it where you want the topleft of your picture (it’s now in a masked layer called container)  
In frame1

```auto
var pic;
function setvar(vari) {
	pic = vari+".jpg";
}

```

and in frame 15

```auto
tlistener = new Object();
tlistener.onLoadInit = function(target_mc) {
	target_mc._alpha = 0;
	target_mc.onEnterFrame = function() {
		this._alpha += 7;
		if (this._alpha>100) {
			this._alpha = 100;
			delete this.onEnterFrame;
		}
	};
};
myLoader = new MovieClipLoader();
myLoader.addListener(tlistener);
myLoader.loadClip(pic, container);

```

[http://gertdesign.info/kirupa/projects.zip](http://gertdesign.info/kirupa/projects.zip)

scotty(-:

[Next page](https://forum.kirupa.com/t/passing-a-variable-to-external-swf/186417.md?page=2)
