Skip to main content
oluc
Known Participant
January 24, 2010
Question

question regarding controling object from child .as file

  • January 24, 2010
  • 1 reply
  • 1731 views

If I import pgming from one AS into an overall one like this:

import asFiles.slideshow.*;

public var slideshowAS:Slideshow;

//then later:

slideshowAS = new Slideshow;

mainSprite.addChild(slideshowAS);

//this code works fine in the the as file and loads fine

how do I control one object that is within that child .as file from the parent .as file?

so for instance if in the slideshowAS there is an item called "nextBtn" and I want to be able to do something with it in the parent main menu .as file.

If you could even direct me on what to search under I that would be very helpful! I tried googling it but did not know how to search for it.

Thanks!

This topic has been closed for replies.

1 reply

January 24, 2010

can you add what

mainSprite

in this class looks like?

did you instantiate it in the class you just showed us?

oluc
olucAuthor
Known Participant
January 24, 2010

mainSprite is a holder which I put it in along with some other objects from the MainMenu .as file.

so its just:

public var mainSprite:Sprite;

mainSprite =  new Sprite();

addChild(mainSprite);

does that answer your question?

January 24, 2010

yeah what i was hoping was that mainSprite was a clas that you had next button as an object within.  that would have been ideal.

before someone tells you to use parent.button.object.method()

let me explain something.  objects can work together when and only when at least 1 has subscribed to another in any way shape or form.

this is why parent.button.object.someMethod will work.  you are referencing all kids down a chain to get to a method from a starting point but this is sloppy and can be avoided and should be if it can be.

so to get out of this situation is very unlikely in a clean manner without writting a bit more code.

but since you said mainSprite holds slideshow and a button right?  is it possible for you to add your button into slideshow in the same class?

document class declares an instance of SlideShow.as  and NextButton as.  and adds them into itself at run time.

Let me know if this is possible before i continue.

but where this is heading is then have nextButton on mouseDown talk to slideShow instance method to change what is visible.