?
Solved

Dynamic symbol function

Posted on 2009-04-30
11
Medium Priority
?
511 Views
Last Modified: 2013-11-11
Hi,

I have a code creating child movieclips to a parent movieclips like this:

this.attachMovie(sSymbol, "sym-"+i+"-"+line, nDepth + (line*nColumns) + i, {_x:xPos, _y:yPos});

the master symbo is "sSymbol" which has name,
each child movieclip gets a name like : sym-5-2

I then can do this

this[sym-5-2]._visible = false;

or

this[sym-5-2].gotoAndPlay (40);


this works well, so I can dynamically create and operate a child movieclip

but when I go into the master symbol, and edit it's first frame to add some code like

function myname () : String
{
      trace ("hi");
      return this._name;
}

it will not work, I tried all kind of the functions but none of the function calls gets by, no trace or nothing.

I checked the master symbol and it has checkboxes, exported for actionscript and exported in frame 1


why won't this work ?

thanks
0
Comment
Question by:moshem
  • 5
  • 4
  • 2
11 Comments
 
LVL 6

Expert Comment

by:biyik
ID: 24268917
After declaring you called the function, right?
function myname () : String
{
      trace ("hi");
      return this._name;
}

myname ()

0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 24268943
It can be achieve using following code:

var mc = this.attachMovie(sSymbol, "sym-"+i+"-"+line, nDepth + (line*nColumns) + i, {_x:xPos, _y:yPos});

mc.myName = function():String{
return this._name;
}


// now you can call it as following

trace(this[sym-5-2].myName());

0
 
LVL 6

Expert Comment

by:biyik
ID: 24268952
by the way, don't you need a parameter if you are using "return"?..
Or don't use "return" if you really don't need it and delete the " : String"...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:moshem
ID: 24269029
this didn't help:

in the symbol I wrote:

mc.myname = function () : String
{
      return this._name;
}

and called:

trace ( _root.front_mc["sym-7-1"].myname() );

it output "undefined"....


0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 24269131
as per my code, you didnt require to add this code inside your symbol..
you just have write is in the loop where you are attaching this symbol using its linkage id..

please just replace your following line of code:
//
this.attachMovie(sSymbol, "sym-"+i+"-"+line, nDepth + (line*nColumns) + i, {_x:xPos, _y:yPos});
//

replace above line with following code:
//
var mc = this.attachMovie(sSymbol, "sym-"+i+"-"+line, nDepth + (line*nColumns) + i, {_x:xPos, _y:yPos});

mc.myName = function():String{
return this._name;
}
//
// above code will dynamically add this function into each symbol after attaching it..
0
 
LVL 1

Author Comment

by:moshem
ID: 24269144
Ok, I will try that..

can't I use code directly inside the symbol ? it is a lot cleaner ... I don't understand why I can't call a function inside a symbol just like any other operation
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 24269305
you CAN right function/method in your SYMBOL,

If you symbol is a normal movieClip with just an linkage ID.
then it will be available instantly, (this is the case with your code)
attached movieClip needs atleast one frame to loads its function/child movies to make it available for use by anyother actionscript code outside the attachmovieclip.

to make the movieClip instantly available, you must to write it in a Class structure(if writing on a frame, then it must follow "AS1 class coding structure" or write it in an external AS2 class and link that class with the movieClip..

then this method will be available instantly after attachMovie command.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 24269311
CORRECTION:
If you symbol is a normal movieClip with just an linkage ID.
then it will NOT be available instantly, (this is the case with your code)
0
 
LVL 1

Author Comment

by:moshem
ID: 24269362
what is a linkage ID ?


it is a normal movieclip, with the export to actionscript checkbox on...\

so why not ? and how can I get it to be available ?
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 2000 total points
ID: 24269854
what is a linkage ID ?
ANSWER: LinkageID is the string name you choose after clicking "export to actionscript" checkbox


so why not ? and how can I get it to be available ?
ANSWER: I already suggested that you must write the code inside movieClip by following AS1 class structure or AS2 class structure.
or just follow my earliest suggested code which creates function inside movieClip dynamically after attaching movieclip..


If it is still not clear,
Just attach your FLA, I will update the code for you
0
 
LVL 1

Author Comment

by:moshem
ID: 24271146
Hi,

1. something is very wierd about the symbol, now this code won't even get launched after an attachMovie command:

this.onLoad = function ()
{
      trace ("load");
};


even onLoad won't work... ideas ?


2. Can you give an example of a code written with AS1 coding structure ? I would like to try that..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question