Creating containers as objects?
Hello.
I'm trying to tidy up some code, and wanted to start using objects (new to Javascript, come from C#) but am having a problem.
My code is below, I get no errors but also get no shape. Using alerts I know the instance is being created, but the shape is not showing.
var panelOne = new _container(1520, 750);
panelOne.x = 225;
var panelOneShape = new createjs.Shape();
panelOneShape.graphics.beginFill("rgba(255,255,255,1)").rect(0,0,1520,750);
panelOne.addChild(panelOneShape);
function _container(Width, Height) {
var _contain = new createjs.Container();
_contain.width = Width;
_contain.height = Height;
}
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Lanny McNie on 24 Jan, 2013 04:31 PM
A few things:
1. Your _container function is not returning an instance to
_contain. This means that panelOne is null. You also should not use "new" on the function. I show a fixed version below, but would recommend just creating the container, not wrapping it in a function.You can not set the width or height of a container. All a container is is a grouping of Objects that can be moved/transformed together.
I also do not see is where you add the container to the stage. Is that just omitted from your post?
Try this instead:
Please note that this forum is not intended to provide help with programming in general - only issues with CreateJS. I recommend you check out our documentation and examples, and JavaScript references in general to get a better feel for the language and syntax.
Cheers.
Lanny McNie closed this discussion on 24 Jan, 2013 04:31 PM.