PDA

View Full Version : AS3.0 Project Structure - Placement of Actionscript code



JimTester
August 20th, 2009, 04:22 AM
Hi

I hope you can help.

Question
How do you access a MovieClip on stage (which has an instance name) from within a .AS class file (where the class file is not the document class)?

Background:
I have an instance name on stage called "world"
Within that I have another MC called "hitCountBelt"
Within that I have a textfield called "hitCount"

So in my external class (PushHitCount.as) I'm trying to populate the text property of hitCount something like this:

world.hitCountBelt.hitCount.text = "999";
//Where 999 actually gets replaced by a value returned from an .aspx script

The trouble is - I don't know how to correctly access the MC instances on stage from within this external class file.

Am I approaching this the wrong way in terms of project structure? Should I even be trying to access the instances this way?

Can anyone help?

Thanks a bunch

James :-)

senocular
August 20th, 2009, 07:31 AM
That all depends on what you're using PushHitCount for. Classes are definitions. They're blueprints for creating instances. Code in classes are used with objects created at runtime. Where the object(s) created with your class is defined determines how it is able to find and reference other objects.

JimTester
August 20th, 2009, 10:20 AM
Thanks for your reply Senocular

Here's some background:
PushHitCount.as is a class that 'manages' the visitor/hit count for my PUSH website (a temporary version of the website can be found here:
http://www.pushwebdesign.co.uk/MONSTER_WORLD_986x562_PRELOADER.html).

The purpose of PushHitCount.as is to call an ".aspx" file that updates a table called HitCount in a SQL database and returns the new value for HitCount. PushHitCount.as has an event handler in it. I want this event handler to take the value returned from the ".aspx" script and populate the hitCount Textfield on stage (this is the belt that the boxer is holding above his head).

Does this background information help to answer my initial question?

Thanks again.

James