Hi all,
I’ve got a confusing situation which wont seem to fix itself!
So basically I have my main class, my iContent class (which will hold each page and have functions for all pages), and my individual pages.
The homepage is instantiated by calling the iContentClass.goHome method in the main document class. The home page contains a button to go on to the next page.
This button references the goColourBrowserPage function within the iContentClass, which removes the child (being the home page) and attempts to add a child (colourBrowserPage).
For some reason this doesnt work! It doesnt seem to add the child and wont let me remove the child of the home page! I’ve been sitting here for 3 hours trying to work it but to no avail!
Any advice?
Code below:
Main Class
public class LetsColour extends MovieClip
{
public var holder:iContent = new iContent;
public function LetsColour() {
holder.goHomePage();
addChild(holder);
}
/*public static function get addPage():LetsColour {
return;
}*/
}
I content class
public class iContent extends MovieClip
{
public var currentPage:MovieClip;
public var homePage:HomePage = new HomePage();
public var colourBrowserPage;
//public var homePage:HomePage = new HomePage();
public function iContent() {
// anything which is needed for the iContent in here
//when iContent is called instantly invoke the pageTransitions to moveIn
pageTransitions("moveIn");
}
public function pageTransitions(transitionType:String) {
//defines the transitions of the page
switch (transitionType) {
case "moveIn":
//actions for sliding in
Tweener.addTween(this, {x:0, time: 0.5, transition: "easeOutBack"})
break;
case "moveOut":
//actions for sliding out
Tweener.addTween(this, {x:-500, time: 0.5, transition: "easeInBack", onComplete:function(){this.parent.removeChild(this)}})
break;
}
}
public function doRemove() {
if (currentPage != null) {
removeChild(currentPage);
}
}
public function goHomePage() {
doRemove();
addChild(homePage);
currentPage = homePage;
trace(currentPage);
}
public function goColourBrowserPage() {
removeChild(currentPage);
doRemove();
addChild(colourBrowserPage);
currentPage = colourBrowserPage;
}
HomePage Class
public class HomePage extends MovieClip
{
public var browseBtn:SelectBtn = new SelectBtn();
public var pickBtn:SelectBtn = new SelectBtn();
private var lc;
//public var homeImg:letsColourHomeImg = new letsColourHomeImg();
// class for main HomePage
public function HomePage() {
trace("its here");
browseBtn.x = 16;
browseBtn.y = 600;
browseBtn.buttonMode = true;
browseBtn.mouseChildren = false;
browseBtn.name = "browse";
browseBtn.btnTextArea.text = "Browse the colour range";
browseBtn.addEventListener(MouseEvent.CLICK, browseClickHandler);
addChild(browseBtn);
pickBtn.x = 16;
pickBtn.y = 500;
pickBtn.buttonMode = true;
pickBtn.mouseChildren = false;
pickBtn.btnTextArea.text = "Pick a colour from a photo";
pickBtn.addEventListener(MouseEvent.CLICK, pickClickHandler);
addChild(pickBtn);
/*homeImg.x = (stage.stageWidth / 2) - (homeImg.width / 2);
homeImg.y = (stage.stageHeight / 2) - (homeImg.height / 2);
addChild(homeImg);*/
}
private function browseClickHandler(e:MouseEvent):void {
trace("clicked");
lc = new iContent();
lc.goColourBrowserPage();
}
private function pickClickHandler(e:MouseEvent):void {
}
}