Skip to main content
Participant
November 25, 2008
Question

Passing Variables between two AS3 swf's

  • November 25, 2008
  • 1 reply
  • 1771 views
I am trying to pass value and string from AS3 main.swf to AS3 child.swf loaded in it.
But, Nothing is working and i can't get the value from one to another. As Beginner in AS3, i was working for a long time and still i face these problems and no output yet.
Can any one please help me out in getting value from main.swf to child.swf and also child.swf to main.swf

I got some samples in web and i didn't get it properly.
The sample in child.swf is ....
function showNumber(n:Number):void
{
trace("The number is: " + n);
}

Sample in Main.swf is....
var clip:MovieClip = loader.getChildAt(0) as MovieClip;
clip.showNumber(23);

But, i didn't get the output...

---------------------------------------------------------------------
Few Scripts from my Main.swf

var xmlData:XML;
var tocData:XML;
var xp:Number;
var fn:Number;
var loader:Loader = new Loader();

function createtext(fn, xp) {
gloval.toload = fn;
var button:Sprite = new Sprite();
var tag_button:Sprite = new Sprite();
var modi_button:Sprite = new Sprite();
var mtitle_button:Sprite = new Sprite();
var ctitle_button:Sprite = new Sprite();
var ltitle_button:Sprite = new Sprite();
var stitle_button:Sprite = new Sprite();
var sid_button:Sprite = new Sprite();
var textLabel:TextField = new TextField();
gloval.x_pos = xp;
gloval.y_pos = gloval.y_pos + 25;
ButtonInteractivity();
function ButtonInteractivity() {
//trace("ButtonInteractivity()");
drawButton();
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
//hideclip.scrollbar.text.removeChild(button);
hideclip.scrollbar.text.addChild(button);
}
function drawButton():void {
button.name = gloval.dummy;
tag_button.name = gloval.slidetag;
modi_button.name = gloval.slidemodi;
mtitle_button.name = gloval.mtitle;
ctitle_button.name = gloval.ctitle;
ltitle_button.name = gloval.ltitle;
stitle_button.name = gloval.stitle;
sid_button.name = gloval.sid;
//trace("Button Name: "+button.name);
//trace("Initial Button Position: X="+button.x+" Y="+button.y);
textLabel.text = gloval.sn;
textLabel.autoSize = "left";
button.x = gloval.x_pos;
button.y = gloval.y_pos;
//trace("Aligned Button Position: X="+button.x+" Y="+button.y);
textLabel.selectable = false;
button.addChild(textLabel);
}

function mouseDownHandler(event:MouseEvent):void {
trace("Clicked Object: "+button.name);
gloval.tname = button.name;
gloval.pname = gloval.cname;
gloval.cname = gloval.tname;
trace("sunnnn :"+gloval.cname);
var request:URLRequest = new URLRequest(gloval.cname);
loader.unload();
loader.load(request);
cont_loder.addChild(loader);
trace("Clicked Object text: "+textLabel.text);
//mod_title.text = textLabel.text;
mod_title.text = mtitle_button.name;
chp_title.text = ctitle_button.name;
les_title.text = ltitle_button.name;
sld_title.text = stitle_button.name;
sld_tag.text = tag_button.name;
last_modi.text = modi_button.name;
sid.text = sid_button.name;
/*cont_loder.name = "passcont";
trace("cont_loder.name = "+cont_loder.name);
MovieClip(cont_loder).asdf = "yyyyyyyyyy";
this.cont_loder.asdf = "yyyyyyyyyy";
cont_loder.sample= "sdfsdaf";*/
//var clip:MovieClip = cont_loder.getChildAt(0) as MovieClip;
var clip:MovieClip = cont_loder.currentTarget;
clip.showNumber(23);
}
}

In Child.swf i had created a textfield.

Can any one send me a sample working file to pass values between two AS3 swf
This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
November 25, 2008
the main timeline of your loaded swf is the content property of your loaded. also, you shouldn't call the loaded swf's function until loading is complete.