5 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 50+ items on Envato Market
  • Located in United States
siliconstudio says

I have a function sitting in the 1st frame on level 0 of my movie. This function loads an xml file and processes the extracted data. Works fine. Within the function I’ve created a variable myLogo from an xml array and I can see it fine in the debugger:-

myLogo = logoPath; // logoPath is from xml array

My problem is that I have a movie clip that hangs off the root that needs one variable from within this function to load an external file:-

var logo = _level0.root.myLogo; // logo is path to the file to be imported

this.createEmptyMovieClip(“holder_mc”, 1);

var mcl:MovieClipLoader = new MovieClipLoader();

mcl.addListener(this);

mcl.loadClip(“logo”, holder_mc); // grab logo

I’ve tried setting the root variable to _global but I still can’t see it in the above mc script in the debugger.

Does anyone know how to extract a variable in a function from another mc?

Many thanks.

3868 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
flashjunkie says

set up the var outside the function, then you can use it anywhere :)

so instead of

function myFunction() {
     var myVar:String = "blah";
}

use

var myVar:String = new String;
function myFunction() {
      myVar = "blah";
}
189 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
mbudm says

Or if it’s a variable of a type that you can only set up when you have certain parameters, like a custom class that needs xml data for example, then put the variable you create within the function into an array or object that you create outside of the function… like so

var myObj:Object = new Object(); function myFunction() { var myVar:someCustomType = new someCustomType(param); myObj.myVar = myVar; }

then you can access myObj.myVar from outside the function too.

Ok so I’m probably complicating matters but this is something that had me tearing my hair out a while back…

5 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 50+ items on Envato Market
  • Located in United States
siliconstudio says

Thanks for getting back guys.

flashjunkie I would set up the variable outside of the function if I could but it’s a custom class that needs xml data.

mbudm I think you’re on the right track. I actually need to send about 10 variables out of this function so an array seems the most efficient method. For testing I set up an array outside of the function and it works fine. However I can’t read the array when I put it in the function. Is the scope of an array the same as variables when used in functions? Any idea how I can read the array outside of the function?

many thanks again for your time

5 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 50+ items on Envato Market
  • Located in United States
siliconstudio says

I setup an empty array outside of the function:-

configImport = new Array();

and within the function pushed some strings to populate the array:- pushed = configImport.push(“logoPath”, “soundAuto”,”soundMiniPlayer”, “soundShowPlayer”, “soundInitVol”); trace(pushed);

Doesnt work either

107 posts
  • Has been part of the Envato Community for over 6 years
  • Has sold $100+ on Envato Market
the_asman says

you are forgeting this is event driven

since there is load time involved with loading the xml and then parsing it the data will not exist untill that happens

since you have stated that it is a custom xml class. what you need to do in the method in that class that parses the xml you need to dispatch an event.COMPLETE or dispatch a custom event

then when you instantiate your custom xml class you need to add an event listener to it like.

var myCustomXmlClass:myCustomXmlClass = new myCustomXmlClass( )
myCustomXmlClass.addEventListener( event.COMPLETE, myCallBackFunc );

function myCallBackFucntion( e:Event ){
// do the work here
}


AS3 is very good in handling events fired from class objects. Dont over complicate things. oh and almost forgot in your custom class you need to have a public variable that the data is assigned to IE: public var data:Array; so in your call back function you can grab it with e.target.data

disclaimer: I wrote this off the top of my head and am sure i forgot something but it is a start for you. email me if you still dont get it

by
by
by
by
by
by