PDA

View Full Version : AS3 center movieclip to stage problems. Please HELP!



FlawedKid
June 27th, 2007, 06:15 AM
Im sure theres an easy solution to my problem so here it goes.

Im making a document class that attaches 2 moviclips using the addchild method. One movieclip (bgGradient) needs to be stretched 100% stage width/height and the other movieclip (bgCenter) need to be aligned/stretched 20px from top,left,bottom,top.

Here is the class and the errors its producing:


"1120: Access of undefined property bgGradient."
"1120: Access of undefined property bgCenter."




package classes {

// List of imported classes
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;

public class WebSite extends Sprite {

public function WebSite() {
init();
}

private function init():void {
initStage();
addBackgrounds();
alignBackgrounds();
}

// Set the properties of our stage
private function initStage():void {
stage.frameRate = 30;
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
}

// Functions to hit when the stage is resized
private function resizeHandler(event:Event):void {
alignBackgrounds();
}

// Creates the backgrounds
private function addBackgrounds():void {

var bgGradient = new mainBackground;
addChild(bgGradient);

var bgCenter = new mainContent;
addChild(bgCenter);

}

// Align the backgrounds
private function alignBackgrounds():void {
bgGradient.x = 0;
bgGradient.y = 0;
bgGradient.width = stage.stageWidth;
bgGradient.height = stage.stageHeight;

bgCenter.x = 20;
bgCenter.y = 20;
bgCenter.width = stage.stageWidth - 40;
bgCenter.height = stage.stageHeight - 40;
}
}
}


Thanks :thumb2:

conannug
August 16th, 2007, 10:33 AM
Isnt it suppposed to be:

var bgGradient = new mainBackground()
var bgCenter = new mainContent()

And you need to import those two classes.

Hope it helps :)

Conan





Im sure theres an easy solution to my problem so here it goes.

Im making a document class that attaches 2 moviclips using the addchild method. One movieclip (bgGradient) needs to be stretched 100% stage width/height and the other movieclip (bgCenter) need to be aligned/stretched 20px from top,left,bottom,top.

Here is the class and the errors its producing:


"1120: Access of undefined property bgGradient."
"1120: Access of undefined property bgCenter."


package classes {

// List of imported classes
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;

public class WebSite extends Sprite {

public function WebSite() {
init();
}

private function init():void {
initStage();
addBackgrounds();
alignBackgrounds();
}

// Set the properties of our stage
private function initStage():void {
stage.frameRate = 30;
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
}

// Functions to hit when the stage is resized
private function resizeHandler(event:Event):void {
alignBackgrounds();
}

// Creates the backgrounds
private function addBackgrounds():void {

var bgGradient = new mainBackground;
addChild(bgGradient);

var bgCenter = new mainContent;
addChild(bgCenter);

}

// Align the backgrounds
private function alignBackgrounds():void {
bgGradient.x = 0;
bgGradient.y = 0;
bgGradient.width = stage.stageWidth;
bgGradient.height = stage.stageHeight;

bgCenter.x = 20;
bgCenter.y = 20;
bgCenter.width = stage.stageWidth - 40;
bgCenter.height = stage.stageHeight - 40;
}
}
}
Thanks :thumb2: