A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: targeting elements

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849

    targeting elements

    Continuing my experiments, I created a button within a movieclip and then tried to change the contents of a textfield called "statusDisplay" on the root timeline.

    So I started with:

    Code:
    button1.addEventListener(MouseEvent.CLICK, changeText);
    function changeText(evt) {
      parent.statusDisplay.text="blah";
    }
    Gives an error. So does root.statusDisplay.text.

    Through a little experimentation, I found I could change the text via either:

    Code:
    evt.target.parent.parent.statusDisplay.text="blah";
    or

    Code:
    TextField(parent.getChildByName("statusDisplay")).text="blah";
    Seems awfully verbose just to change something one level up. Is there a better way to do this?

  2. #2
    Member
    Join Date
    May 2007
    Posts
    35
    The parent property is a DisplayObject. It isn't dynamic.

    You have to cast to MovieClip which is dynamic so that you can access dynamically added properties.

    So you can try:

    MovieClip(parent).statusDisplay.text = "blah";
    or TextField(MovieClip(parent).statusDisplay).text = "blah";

    Not quite sure if the first one works - I'm a little tired :P The second one should work for sure.


    If you're "MovieClip" is actually a subclass of a MovieClip, then there's some other ways to fix this without forcing your class to be dynamic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center