Log in

View Full Version : working with the display list, memory and errors



evan
07-15-2008, 10:03 PM
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.

Medyman
07-15-2008, 11:12 PM
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.


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