Results 1 to 2 of 2

Thread: working with the display list, memory and errors

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default working with the display list, memory and errors

    This is not a question directly related to managing text so much as any object that is placed progamatically

    by using

    var hello_mc:Movieclip = new Hello_mc();
    addChild (hello_mc);
    hello_mc.x=100;
    hello_mc.y=100;
    "hello_mc" can be called from the library if it's linked with actionscript etc.

    I can even call it with an event assigned to a button or a set of conditions -pretty basic.


    but...

    let's say I have assigned values to it before it's in memeory

    as with this code:

    hello_mc.mytext.border=true;
    hello_mc.mytext.background=true;

    var format:TextFormat = new TextFormat();
    format.color= 0x000000;
    hello_mc.mytext.setTextFormat(format);


    //this function changes the text color to blue
    //

    blue_btn.addEventListener(MouseEvent.CLICK,bluetext);
    function bluetext(e:MouseEvent):void{


    var format:TextFormat = new TextFormat();
    format.color= 0x3612CB;
    hello_mc.mytext.setTextFormat(format);
    }

    in this case hello_mc includes mytext

    if it is placed on the stage, then all is good.

    but if I don't have it on the stage and I in fact want to use have it appear with an event handler,

    then I would get this error:
    1120: Access of undefined property hello_mc.mytext
    not surprising.

    The way I have been dealing with this is by creating an instance or hello_mc off the visible stage like at x,y -100 or so.

    I was wondering if there was a more efficient way of doing it ie putting it into the memory without displaying it.

    an array maybe?


    The end result I am looking for is to start with ablank screen and a button,

    call a movie clip, and what is inside them respectively, assign default properties and

    with other buttons or I would like to change their properties.

    the trouble is that if they don't exist in memory yet then you can't assign defaults. -UNLESS the defaults are conditional to the objects being placed onto the stage.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hey Evan...

    Your logic is correct. You can't add items to a display that doesn't exist. That's like mailing a letter to a construction site where houses will be built later on. If you want to know the number of bedrooms in each house on the street, you'll have to wait until it's constructed.

    Is there a reason you're doing these actions separately?

    You might want to take this step to map out your logic in your functions. From the code that you've posted (in this thread and elsewhere), I think you're falling into a trap of making functions and function calls highly specialized.

    There is no real way to do what you want. And, if you think about the situation, why would there be? You shouldn't be attaching properties to non-existent objects. So, if you want hello_mc to exist after clicking a button, create that event listener and within it's callback function, add hello_mc to the display last and then change the properties of the text object.

    If the properties will be changing before the item is in the display list, create the object but don't add it to the display list until it's required.

    Code:
    var movieclip:Movieclip = new Movieclip();
    still creates the movieclip object. It's not visible as yet, but it's properties are available.

  3. The Following User Says Thank You to Medyman For This Useful Post:

    evan (07-16-2008)

Bookmarks

Posting Permissions

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