-
change settextformat of the text on button click
i have 2 textformats i m trying to settextformat of the text based on when i click on it and when i click on some other thing but its not working plz help
Code:
stop();
var myclick_fmt:TextFormat = new TextFormat();
myclick_fmt.color = 0xFFFFFF;
myclick_fmt.size = 14;
myclick_fmt.underline = false;
myclick_fmt.font = "Arial";
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0x000000;
my_fmt.size = 14;
my_fmt.underline = false;
my_fmt.font = "Arial";
var categoryid:Array = new Array();
var nocat:Number=5;
for (i=0;i<nocat;c++){
categoryid[i] = i;
}
_root.createEmptyMovieClip("categorylist", _root.getNextHighestDepth());
categorylist._x = 150;
categorylist._y = 150;
for(j=0; j < nocat; j++)
{
_root.categorylist.createEmptyMovieClip("catname" + j, categorylist.getNextHighestDepth());
_root.categorylist["catname" + j].createTextField("mainText", 0, 0, 0, 80, 22);
_root.categorylist["catname" + j].mainText.selectable = false;
_root.categorylist["catname" + j].mainText.html = true;
_root.categorylist["catname" + j].mainText.multiline = false;
_root.categorylist["catname" + j].mainText.wordWrap = true;
_root.categorylist["catname" + j].mainText.autoSize = false;
_root.categorylist["catname" + j].mainText.border = false;
_root.categorylist["catname" + j].mainText.htmlText = categoryid[j] ;
if (j==0)
{
_root.categorylist["catname" + j].mainText.setTextFormat(myclick_fmt);
}
else
{
_root.categorylist["catname" + j].mainText.setTextFormat(my_fmt);
}
_root.categorylist["catname" + j]._x = 10;
_root.categorylist["catname" + j]._y = 30 * j;
_root.categorylist["catname" + j].onReleaseOutside = function()
{
_root.categorylist["catname" + j].mainText.setTextFormat(my_fmt);
}
_root.categorylist["catname" + j].onRelease = function()
{
_root.categorylist["catname" + j].mainText.setTextFormat(myclick_fmt);
}
}
-
.
Hi,
You had a few errors in there, perhaps you can see what i changed, this first was the worst as it had the dreaded abort script message:
PHP Code:
stop();
var myclick_fmt:TextFormat = new TextFormat();
myclick_fmt.color = 0xFFFFFF;
myclick_fmt.size = 14;
myclick_fmt.underline = false;
myclick_fmt.font = "Arial";
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0x000000;
my_fmt.size = 14;
my_fmt.underline = false;
my_fmt.font = "Arial";
var categoryid:Array = new Array();
var nocat:Number = 5;
for (i = 0; i < nocat; i++)
{
categoryid[i] = i;
}
_root.createEmptyMovieClip("categorylist",_root.getNextHighestDepth());
categorylist._x = 150;
categorylist._y = 150;
for (j = 0; j < nocat; j++)
{
_root.categorylist.createEmptyMovieClip("catname" + j,categorylist.getNextHighestDepth());
_root.categorylist["catname" + j].createTextField("mainText",0,0,0,80,22);
_root.categorylist["catname" + j].mainText.selectable = false;
_root.categorylist["catname" + j].mainText.html = true;
_root.categorylist["catname" + j].mainText.multiline = false;
_root.categorylist["catname" + j].mainText.wordWrap = true;
_root.categorylist["catname" + j].mainText.autoSize = false;
_root.categorylist["catname" + j].mainText.border = false;
_root.categorylist["catname" + j].mainText.htmlText = categoryid[j];
if (j == 0)
{
_root.categorylist["catname" + j].mainText.setTextFormat(myclick_fmt);
}
else
{
_root.categorylist["catname" + j].mainText.setTextFormat(my_fmt);
}
_root.categorylist["catname" + j]._x = 10;
_root.categorylist["catname" + j]._y = 30 * j;
_root.categorylist["catname" + j].onReleaseOutside = function()
{
this.mainText.setTextFormat(my_fmt);
};
_root.categorylist["catname" + j].onRelease = function()
{
this.mainText.setTextFormat(myclick_fmt);
};
}
My Hobby
Last edited by fruitbeard; 01-22-2013 at 02:16 PM.
Reason: Hobby Link
-
on selecting different category i.e onReleaseOutside is not setting the textformat to my_fmt
-
.
Hi,
Yes it does, click once to change, click and release outside to change again, it works alternately, not on every click as your original code suggested
-
.
Hi,
Here is an alternate version then, changes on every click.
PHP Code:
stop(); var myclick_fmt:TextFormat = new TextFormat(); myclick_fmt.color = 0xFFFFFF; myclick_fmt.size = 14; myclick_fmt.underline = false; myclick_fmt.font = "Arial";
var my_fmt:TextFormat = new TextFormat(); my_fmt.color = 0x000000; my_fmt.size = 14; my_fmt.underline = false; my_fmt.font = "Arial";
var categoryid:Array = new Array();
var nocat:Number = 5;
for (i = 0; i < nocat; i++) { categoryid[i] = i; }
_root.createEmptyMovieClip("categorylist",_root.getNextHighestDepth()); categorylist._x = 150; categorylist._y = 150;
for (j = 0; j < nocat; j++) { _root.categorylist.createEmptyMovieClip("catname" + j,categorylist.getNextHighestDepth()); _root.categorylist["catname" + j].createTextField("mainText",0,0,0,80,22); _root.categorylist["catname" + j].mainText.selectable = false; _root.categorylist["catname" + j].mainText.html = true; _root.categorylist["catname" + j].mainText.multiline = false; _root.categorylist["catname" + j].mainText.wordWrap = true; _root.categorylist["catname" + j].mainText.autoSize = false; _root.categorylist["catname" + j].mainText.border = false; _root.categorylist["catname" + j].mainText.htmlText = categoryid[j];
if (j == 0) { _root.categorylist["catname" + j].mainText.setTextFormat(myclick_fmt); } else { _root.categorylist["catname" + j].mainText.setTextFormat(my_fmt); } _root.categorylist["catname" + j]._x = 10; _root.categorylist["catname" + j]._y = 30 * j;
_root.categorylist["catname" + j].onRelease = function () { if (Clicked) { this.mainText.setTextFormat(myclick_fmt); } else { this.mainText.setTextFormat(my_fmt); } Clicked = !Clicked; }; }
-
in the code u gave i have to click on the category again to change its color...that not what i m trying to get
say the categories are 0 1 2 3 4 5 ...but default 0 is white and rest are black.
what i m trying to get is when i click on say 2 then 0 which is white should turn black and 1 should turn white again when i say click 5 then 1 which is now white should turn black and 5 should turn white.
but in the code if 0 is white i have to click on it twice to get it to become black.
-
.
Hi,
Here you go,I think that is what you mean!!
But if not, then you have enough varieties within the three posts to be able to mix and match your own version.
PHP Code:
stop();
var myclick_fmt:TextFormat = new TextFormat();
myclick_fmt.color = 0xFFFFFF;
myclick_fmt.size = 14;
myclick_fmt.underline = false;
myclick_fmt.font = "Arial";
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0x000000;
my_fmt.size = 14;
my_fmt.underline = false;
my_fmt.font = "Arial";
var categoryid:Array = new Array();
var nocat:Number = 5;
for (i = 0; i < nocat; i++)
{
categoryid[i] = i;
}
_root.createEmptyMovieClip("categorylist",_root.getNextHighestDepth());
categorylist._x = 150;
categorylist._y = 150;
for (j = 0; j < nocat; j++)
{
_root.categorylist.createEmptyMovieClip("catname" + j,categorylist.getNextHighestDepth());
_root.categorylist["catname" + j].createTextField("mainText",0,0,0,80,22);
_root.categorylist["catname" + j].mainText.selectable = false;
_root.categorylist["catname" + j].mainText.html = true;
_root.categorylist["catname" + j].mainText.multiline = false;
_root.categorylist["catname" + j].mainText.wordWrap = true;
_root.categorylist["catname" + j].mainText.autoSize = false;
_root.categorylist["catname" + j].mainText.border = false;
_root.categorylist["catname" + j].mainText.htmlText = categoryid[j];
if (j == 0)
{
_root.categorylist["catname" + j].mainText.setTextFormat(myclick_fmt);
}
else
{
_root.categorylist["catname" + j].mainText.setTextFormat(my_fmt);
}
_root.categorylist["catname" + j]._x = 10;
_root.categorylist["catname" + j]._y = 30 * j;
_root.categorylist["catname" + j].onReleaseOutside = function()
{
for (s = 0; s < nocat; s++)
{
_root.categorylist["catname" + s].mainText.setTextFormat(my_fmt);
this.mainText.setTextFormat(myclick_fmt);
}
};
_root.categorylist["catname" + j].onRelease = function()
{
for (s = 0; s < nocat; s++)
{
_root.categorylist["catname" + s].mainText.setTextFormat(my_fmt);
this.mainText.setTextFormat(myclick_fmt);
}
};
}
-
thank u so so so much ...!!it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|