Passing a variable to external .swf

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?

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

Well, I think it might be possible through LocalConnection

You can set it after the swf is loaded.

scotty(-:

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

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

No, no onLoad, something like

//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(-:

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”

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

change thumb to the path you need.

scotty(-:

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

no problem :thumb:

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.

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

scotty(-:

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;};
}

see, you were sucking up to the wrong guy! :stuck_out_tongue:

To set the variable in the main fla

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

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

scotty(-:

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

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”??

If it would make more sense I posted the FLA’s here

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

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

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

and in frame 15

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

scotty(-: