Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Variables for object names

New Here ,
Aug 13, 2014 Aug 13, 2014

Hi all,

Is it possible to use variables in place of object names? So i have a function that looks like this:

public static function xmlText(OBJECT,TEXT):void

{

     some_mc.[OBJECT].some_mc.text = lodedXML.someNode.[TEXT].someNode;

}

I'm trying to create a  function that changes the variables in the paths to the objects passed when the function is called.

This might be a daft question but i just cant seem to find an answer!

Many Thanks

Matt

TOPICS
ActionScript
380
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 13, 2014 Aug 13, 2014

Give me an example of what you want to do and explain it and I will try to give you an example beyond this...

var someMC:Movieclip = new MovieClip();

at this stage you only need to target someMC since you have a direct reference to it, even if you make it a child of some other object.

Translate
LEGEND ,
Aug 13, 2014 Aug 13, 2014

If you assign a variable as a reference to an object you can use that to target the object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 13, 2014 Aug 13, 2014

Thanks Ned i was sure it could be done. Could you show me a quick example of how i'd write it?

Cheers!

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 13, 2014 Aug 13, 2014

Give me an example of what you want to do and explain it and I will try to give you an example beyond this...

var someMC:Movieclip = new MovieClip();

at this stage you only need to target someMC since you have a direct reference to it, even if you make it a child of some other object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2014 Aug 14, 2014

Thanks Ned ; )

The example in my first post is what i'm trying to acheive:

public static function populatePlatforms(COURSE:Object,PLATFORM:Object):void

  {

     Diagram_mc.COURSE.xmlData_mc.platform_mc.platformDetails_mc.data_txt.text  =  LoadedXML.platformDetails.PLATFORM.text;

  }


the function above has two parameters which are passed into the line of code within, so that i can target different items whenever i call it. However if i run this code i get an error "1119: Access of possibly undefined property COURSE through a reference with static type Class."

I'm just not sure what i'm doing wrong, perhaps i'm  using the wrong type of variables?

Cheers!

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2014 Aug 14, 2014
LATEST

The problem might lie in how you define these objects.

As I already indicated, if you have a variable assigned to the object already, then you do not need to target its parent to get to it, especially if its parent has no basis to know that it exists by that variable name.

  • public static function populatePlatforms(COURSE:Object,PLATFORM:Object):void 
  •   { 
  •      COURSE.xmlData_mc.platform_mc.platformDetails_mc.data_txt.text  =  PLATFORM.text; 
  •   }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines