Link to home
Start Free TrialLog in
Avatar of ivmedia
ivmedia

asked on

How do I call a function that is in a class from my main timeline - Flash 8

I have an fla file that publishes error free in flash 6, 7 and 8
However it only works if I publish in flash 6

I have used trace to track the error to a call I am making to a function that is inside a class

(I can confirm that the class is proper because other elements connect to aspects of the class correctly)

However, I need to find a way to access one of the function within this class from my main time line

here is the code I am using that works fine publishing via flash 6

_root.myClass_1.myPublicFunction();

Thank you for your help!
Avatar of najh
najh
Flag of United Kingdom of Great Britain and Northern Ireland image

ok well if you've got a separate class, and it's a "proper class" rather than something you're just "including", then first of all you need to make an instance of the class on your main timeline.

So you can do that by doing:

// this declares and instantiates myClassInstance, then calls the constructor method of myClass_1
var myClassInstance:myClass_1 = new myClass_1();

// now you have a reference to the class (or rather an instance of it)
// to access your public method you call:

myClassInstance.myPublicFunction();

and that should call it.



Avatar of ivmedia
ivmedia

ASKER

your suggestion is indeed the correct method for flash 8
however in my case there is a symbol that is in the library that is instantiating the class

so there is already an instance of the class myClass called myClass_1

your solution worked to a point but when I did that all I was doing was creating another instance of the class and then the symbol was no longer tied to the new instance

any suggestions for access from the main movie line a class that is alread instantiated?

It just bugs me that this works is fla 6 AS 2.0

_root.myClass_1.myPublicFunction();

but in 7 or 8 AS 2.0

it doesnt work!!!

again, your code above is a correct answer but I neglected to mention that the class is instantiated

please help if you can see something
ASKER CERTIFIED SOLUTION
Avatar of najh
najh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ivmedia

ASKER

yes!!

you are exactly correct!!!!

the exact answer is this

OOP's did it again!

in flash 8, if a symbol instantiates a class then the scope of the class must be accessed via the symbol

in my case the exact solution was

this.mySymbol_1.myPublicFunction();

where mySymbol_1 is the instance of mySymbol that is running

as you can see their is not requirement to reference the class again since it is tied to the symbol

thank you- a class instantiated by a symbol is accessed by the symbol instance name
Avatar of ivmedia

ASKER

thank you for staying with this!!!!!