0

So:

I had this problem (Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.) and I followed the recommended solution:

// container ( IVisualElement ) for DisplayObjects
var container:UIComponent = new UIComponent();
addElement( container );

// displayObject goes to container
var displayO:Sprite = new Sprite();
container.addChild( displayO );

--> works great (sizing and layout is another problem aside), because my "child" swf is loading.

Using this method, how can I pass data from the parent to the child (and have the child read it)? It never has to go from Child to Parent, except to close the Child swf (if you've got an idea for that, it doesn't seem to be fond of the unload method).

I have to ask, because almost every method I have found to pass data between swfs is using the Loader class to call the other into view and I haven't had success with that at all. I'm using FlashBuilder 4.6 to code and package both swfs.

Thanks for the input! I'll probably keep updating this question with multiple edits as I get more info or think of something new to add. Thanks for the help!

EDIT 1 - March 27, 17:16 EST

Created a class:

Child.as:

package classes
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;

public class Child extends Sprite
{
public var location:String;

public function Child()
{
super();
var loader:Loader = new Loader;
var urlReq:URLRequest = new URLRequest("http://myswf.com/myswf.swf");
loader.load(urlReq);
addChild(loader);
}}}

and I am opening the child swf with the following method:

//in main code
public var containter:UIContainer = new UIComponent;
public var Locale:String;

private function CallSwf():void
{
container.x=0;
container.y=0;
container.width = totalSize.width;
container.height = totalSize.height;
addElement(container);

var displayO:Child = new Child;
container.addChild(displayO);
displayO.data = Locale;

if (container.visible = true) {
totalSize.visible = false;
}
}

What I need to be able to do, is get the string Locale to be read by the Child swf.

Community
  • 1
  • 1
SQLiteNoob
  • 2,958
  • 3
  • 29
  • 44
  • Look at this thread. Use events. http://stackoverflow.com/questions/3766138/access-a-function-inside-a-loaded-swf-file – FlavorScape Mar 26 '12 at 20:54

1 Answers1

0

You can extend Sprite.

public class Child extends Sprite
{

    public var data:Object;

    public function Child( )
    {

    }

}

and in parent class

// container ( IVisualElement ) for DisplayObjects
var container:UIComponent = new UIComponent();
addElement( container );

// displayObject goes to container
var displayO:Child = new Child();
container.addChild( displayO );
displayO.data = data;
Diode
  • 24,570
  • 8
  • 40
  • 51
  • That's a great solution, I'm going to give it a test run and I'll be back – SQLiteNoob Mar 27 '12 at 18:36
  • Ok, that looks like it's working, loading the new swf, etc. How do I get the child to read it? I keep getting "access of undefined property" errors. – SQLiteNoob Mar 27 '12 at 19:01
  • For that I have to see how you added child objects and how you tried to access from parent. – Diode Mar 27 '12 at 20:36
  • basically, how do I access `displayO.data` from the child? I followed your instructions to add the child to parent, but I'll put it up in an edit right now. – SQLiteNoob Mar 27 '12 at 21:15