flash - Actionscript 3 - Accessing a variable on the main timeline -


i'm trying make file easy non-flash user use/reuse display content. key here file template novice user copy/paste minimal code create different "flash card" type swf files.

the file creating has multiple buttons on main timeline when clicked, attaches movie clip display dynamic text area content specific button clicked. content text area loaded separate text file.

for sake of example, i'm going refer 1 button...

so, on main timeline, in frame 1, have variable definition:

var myfilename1:string = "mysamplefile2.txt"; 

when button on main timeline, in frame 1 pressed, movie clip loaded contains text area. content text area located in file: mysamplefile2.txt.

if hard-code file name, works dream:

mytextloader.load(new urlrequest("mysamplefile2.txt")); 

but don't want hard code file name. want refer variable in main timeline. in 2, have been

mytextloader.load(new urlrequest(_root.myfilename1)); 

in as3 thought either:

mytextloader.load(new urlrequest(root.myfilename1)); 

or

mytextloader.load(new urlrequest(movieclip(this.parent.root).myfilename1)); 

when run code following error , when run trace file name null.

typeerror: error #2007: parameter url must non-null. 

how access file name stored in variable on main timeline?

*************************** update! *************************

so discovered issue related button on screen. button 1 buttons library. if remove button, works great. button on main timeline, makes cannot access variables using movieclip(root).variable_name;. unfortunately want button trigger events within movieclip. thoughts?

not idea

you not able achieve goals bad practice approach.

to use/reuse

the code want provide not reusable. heavily relies on 1 variable existing in place. therefore cannot use twice in project.

but don't want hard code file name.

and hard coding variable , location. if considered hard coding file name bad things, consider bad thing, too.

what problem is

basically speaking, problem component reaching out grab variable somewhere within project. not concern of component find content should display. not encapsulated.

learning existing things

you want display text. let's take @ textfield class see how displays text.

var tf:textfield = new textfield(); tf.text = "hello"; addchild(tf); 

as can see, text should display passed textfield object. there not arbitrary variable 1 has set in order modify text, planning do:

var tf:textfield = new textfield(); var somearbitraryvariablethatmodifiesatextfield = "hello"; addchild(tf); 

there no obvious connection textfield object , if there's second textfield, doesn't work @ all.

applying problem @ hand

just textfield, "flash card" should receive file parameter. either pass constructor seen in example below, or create method takes parameter.

var card:card = new card("mysamplefile2.txt"); addchild(card); 

additional thoughts

  1. create additional methods set values individually. there's nothing worse code 1 wants, operates on files , 1 doesn't have file. goal again, make easy reuse code
  2. use [inspectable] meta tag allow user of code modify properties @ author time. this can used extend of modifying properties belonging physics engine, call easy use novice user.
  3. instead of writing code , requiring recompile file again, take information (either path file or content) flashars passed .swf file when embedded html page. makes single .swf file truely reusable , easiest use, because there's no as3 coding required whatsoever.

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -