Skip to main content
Known Participant
March 14, 2022
Question

trying to create color book

  • March 14, 2022
  • 1 reply
  • 161 views

i like to share with you the link with the color book.

http://hebrewgames.org/colorbook/clorbooktest

 

i have in the labrary 2 pictures

every picture has a linkage name  (pic1, pic2)

each part in pic1 has a movie clips name by a1 a2 a3 a4 ...

 each part in pic2 has a movie clips name by a1 a2 a3 a4 ...

when i am loading pic1 all work i can chage the color.

when i click new pic buton 

pic1 removed and place pic2

the prablem is: that now the color not chnage. it does not recognize the a1 instanc name in pic2.

--------------------------------------------------

this is the code

this.stop();
root=this;

var picNum=1;
var MyInstance = new lib["pic"+1]();
var MyInstance1 = new lib["pic"+2]();
//var MyInstance2 = new lib["pic"+3]();
// var MyInstance3 = new lib["pic"+4]();
this.addChild(MyInstance);

MyInstance.x=170;
MyInstance.y=60;



MyInstance.a1.addEventListener("click", a_1.bind(this));
function a_1()
{
alert ("hello1");
MyInstance.a1.shape.graphics._fill.style ="#ff0000";
}


MyInstance.a2.addEventListener("click", a_2.bind(this));
function a_2()
{
alert ("hello2");
MyInstance.a2.shape.graphics._fill.style ="#ff00ff";
}

MyInstance.a3.addEventListener("click", a_3.bind(this));
function a_3()
{
alert ("hello3");
MyInstance.a3.shape.graphics._fill.style ="#000123";
}

MyInstance.a4.addEventListener("click", a_4.bind(this));
function a_4()
{
alert ("hello4");
MyInstance.a4.shape.graphics._fill.style ="#6699cc";
}


this.npic.addEventListener("click", newPic.bind(this));
function newPic()
{
alert ("new Picture");

root.removeChild(MyInstance);
MyInstance=null;
picNum=2;
MyInstance = new lib["pic"+picNum]();
//MyInstance.name="newpp";
root.addChild(MyInstance);
MyInstance.x=370;
MyInstance.y=60;
MyInstance["a"+picNum+4].shape.graphics._fill.style ="#6699cc";
}

 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    March 15, 2022

    try:

     

    this.stop();
    var totalPics = 3;
    var totalSubPics = 4;
    var colorA = ["#ff0000","#ff00ff","#000123","#6699cc"];
    initPicsF.bind(this)();
    addPicF.bind(this)(1);

    function initPicsF(){
    for(var i=1;i<=totalPics;i++){
    this["instance"+i] = new lib["pic"+i]();
    this["instance"+i].x = 170+(i-1)*200; //?
    this["instance"+i].y = 60;
    for(var j=1;j<=totalSubPics;j++){
    this["instance"+i]["a"+j].subNum = j;
    this["instance"+i]["a"+j].addEventListener("click",colorF.bind(this));

    }
    }
    }
    function colorF(e){
    console.log("hello",e.currentTarget.subNum);
    e.currentTarget.shape.graphics._fill.style = colorA[e.currentTarget.subNum-1];
    }
    function addPicF(num){
    if(this["instance"+this.activePic] && this["instance"+this.activePic].stage){
    this.removeChild(this["instance"+this.activePic]);
    }
    this.activePic = num;
    this.addChild(this["instance"+this.activePic]);
    }

    this.npic.addEventListener("click", newPic.bind(this));

    function newPic(){
    if(this.activePic<totalPics){
    addPicF.bind(this)(this.activePic+1);
    } else {
    addPicF.bind(this)(1);
    }
    }