Groups | Blog | Home
all groups > flash (macromedia) > june 2004 >

flash (macromedia) : this simple thing is too difficult


tralfaz
6/2/2004 5:28:34 PM

[quoted text, click to view]


If you want to use a function located in another movieclip you will need to
use it's path. If you don't include a path, it is assumed that the object
referred to is located within the object where the code is written. Since
M1 is not located inside of M2 you will need to tell it where to find M1.
In your case, probably at _root.m1 or _parent.m1

on (release) {
txtv.text = _root.m1.f1(5) + _root.m1.f2(10, 20);
}

Library objects are not included in your movie unless you use them. If you
have an m1 movieclip in the library, it does no good unless you drag an
instance of m1 onto the stage. then you have to give m1 the instance name
of m1 to make it usable by other clips.
A quick test using your code showed a 40 in the text box. The text box
needs to be dynamic text with either an instance name of txtv or a variable
name of txtv (that's the Flash 5 and earlier method)
If you have a text box with instance name of txtv use this syntax:
txtv.text = _root.m1.f1(5) + _root.m1.f2(10, 20);
If you have a text box with a variable name of txtv use this syntax:
txtv = _root.m1.f1(5) + _root.m1.f2(10, 20);

good luck,
tralfaz






flashin
6/2/2004 11:22:39 PM
I what to create a movie clip M1.fla which contains only the following, with
empty content (no graphics on stage).

function f1(x) { return 2*x; }
function f2(x, y) { return x +y; }

I want to call the M1 functions in movei M2.fla. M2 has two objects and a
button event handler and an instance of imported M1 library.

- a button instance btn
- a text field instance txt with variable name "txtv"


- a button event handler as follow:
on (release) { txtv = m1.f1(5) + m1.f2(10, 20); }

Instead of seeing number 40 in the text field, I either see nothing or see
"undefined". Maybe the problem is related to how to create the movie clip with
empty graphic content and with action code alone. What's the right way to
create a movie clip containing only action script ?
flashin
6/3/2004 2:03:34 AM
[txtv = _root.m1.f1(5) + _root.m1.f2(10, 20);]

That works! Thank you so much. I see the number 40 the first time! that "_root" makes such difference.
This forum is great.
AddThis Social Bookmark Button