Hello!
I am building a portfolio website based on my study’s work. This is my first attempt at working with ActionScript 3.0, but especially with OOP. I’ll try and explain my problem as clearly as possible.
I use CS3 components for the basic interaction between the various objects on the screen. These components are organised in sprites. I populate these sprites (with Buttons, for example) using data from an XML file. I have four sprites:
- the years of my study (Buttons),
- the periods per year (Buttons),
- the various courses per period (List),
- the description of the course (TextArea).
When I click a year Button, it populates the periods Sprite with the periods Buttons. Then when I click a period Button, it adds the courses for that period to the List. When I click a course item in the List, the TextArea shows a description of the course.
I got everything described above working properly. For testing I wrote it all in the main class, but then I advanced to creating a custom class for the different components, called IDComponent. This class extends the Sprite class, so it can contain the components and I can position them all at once.
I instantiate the IDComponents like this:
_jarenContainer = new IDComponent(_idXML, 'jaren');
_jarenContainer.x = 10;
_jarenContainer.y = 10;
addChild(_jarenContainer);
_blokkenContainer = new IDComponent(_idXML, 'blokken');
_blokkenContainer.x = 10;
_blokkenContainer.y = 50;
addChild(_blokkenContainer);
(I’m Dutch… ‘jaren’ means ‘years’, ‘blokken’ means ‘periods’.)
The first argument of the constructor links to the XML file, the second one defines the type of component that has to be created.
The way I used to handle the Button-populating of the courses sprite was first removing all children within the sprite using a loop and then creating Buttons for the periods of the selected year. This worked fine when I had all the code in the Main class:
- listen for a MouseEvent.CLICK on a year button
- remove all children from the periods sprite
- create the new period Buttons
The problem (finally!) I now have is that because the containers are seperate instances from the IDComponent class I cannot reach the courses sprite when clicking a Button in the years sprite. I have been playing around a bit with dispatching events manually but can’t figure out how to solve the issue.
I’m hoping someone here can help me out!
Thanks a lot in advance.