A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Referencing a Sprite subclass's properties

  1. #1
    Member
    Join Date
    May 2007
    Posts
    46

    Referencing a Sprite subclass's properties

    Hi there allow me to begin explaining my confusing.

    Class A extends Sprite {}

    Say we want to create a list of A objects on screen. 1 below the other.

    var array:Array = new Array();

    for (var i:int = 0; i < 10; i++)
    {
    var a:A = new A();
    addChild(a);

    if (array.length > 0)
    {
    a.y = array[i-1].y + array[i-1].height;
    }
    }

    Im not sitting infront of Flex or Flash just now, but you get the basic idea.

    In my project, these are news Items loaded with XML, if i trace inside the A class, i can do

    trace(this.height) //160;

    however, when i do this on the same object outside the class

    trace(a.height) //0;

    Incredibly frustrating!!

    The A class is on the stage, i physically can see it there and it looks about 200px high so why is its height property returning as 0?

    Thanks

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    If the height is created after your trace action, it will be 0. Everything is dependent on the timing.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    May 2007
    Posts
    46
    Thanks u

    I see what you mean!

    When i create an A i give it a delay in the constructor for a casdading effect. So the A is building itself 1 second after i have asked for the height.

    Can i ask, see with delays? Is the best way just to use timers? Coz if you have a pretty motion intensive actionscript project, the code starts to look really messy

    var t:Timer = new Timer(1000);
    t.addEventListener(TimerEvent.Timer, onTimer)
    t.stop();

    function onTimer(t:TimerEvent): void
    {
    t.target.stop();
    t.target.removeEventListener(TimerEvent.Timer, onTimer);
    }

    I am so used to typing this and have often wondered if there is a better way to create delays other than 7 lines of code!

    Thanks

    R

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Click on the Flashscript classes in my footer. In the biz folder you find a folder events. There is a class CustomDispatcher, which I modified from the original Adobe class. Then check any of the component scripts, for example in the datechooser folder DateChooserModul.as how to use this class.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    If it takes time for your A() sprite to be created, and you can't proceed with the next part of your code until they are all ready, then make the A() sprites dispatch events upon completion, and have your main code sit waiting for the last one before it continues.

    Using a timer like you do now only works because you pretty much know the sprite will exist after that amount of time. You'll probably be right 99% of the time, but the upshot is that there's a potential race condition waiting to happen.

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