Hi guys I am a beginner in AS 3.0, I have done the scripting for
There are 4 input text boxex in the stage, 1 Submit button, and there are three MC of equal width of different colors says for ex red_mc, blue_mc, green_mc. Now when the end user enters 4 values (in ascending order) in the input box and press the submit button program has to check for the difference between four values that is val2-val1, val3-val2, val4-val3 from these three results the 3 MC should scale accordingly that if u enter 10,25,40,150 then result is 15, 15, 110 so the red_mc should scale only 15%, blue_mc should scale 15% and green_mc has to scale 70%… this was the concept, there is a rest button too, and value 5is for movig the pointer to the MC which will scale larger I created a code by when the person saw this code he told that the logic has to be improved a lot but can some one suggest me what is wrong with this and how to improve the logic and code please, I have attached the code too
var val1:Number = mc.red_mc.x;
mc.x = stage.x;
submit_but.addEventListener(MouseEvent.CLICK, begin, false, 0, true);
reset_but.addEventListener(MouseEvent.CLICK, reset, false, 0, true);
function reset(evt:MouseEvent):void
{
ip1_txt.text = “”;
ip2_txt.text = “”;
ip3_txt.text = “”;
ip4_txt.text = “”;
ip5_txt.text = “”;
mc.red_mc.width = mc.blue_mc.width = mc.yel_mc.width = 100;
mc.red_mc.x = val1;
mc.blue_mc.x = val1 + mc.red_mc.width;
mc.yel_mc.x = mc.blue_mc.width + mc.blue_mc.x;
mc.move_mc.x = 5;
}
function begin(evt:MouseEvent):void
{
var val1:Number = parseInt(ip1_txt.text);
var val2:Number = parseInt(ip2_txt.text);
var val3:Number = parseInt(ip3_txt.text);
var val4:Number = parseInt(ip4_txt.text);
var val5:Number = parseInt(ip5_txt.text);
trace(val1);
var res1:Number = (val2-val1);
var res2:Number = (val3-val2);
var res3:Number = (val4-val3);
trace(res1,res2,res3);
trace(mc.red_mc.width);
if(res1>res2 && res1>res3)
{
mc.red_mc.width = 300 - (res2+res3);
trace(mc.red_mc.width);
mc.blue_mc.x = mc.red_mc.width;
mc.blue_mc.width = res2;
trace(mc.blue_mc.width);
mc.yel_mc.x = (mc.blue_mc.width + mc.red_mc.width);
mc.yel_mc.width = res3;
}
else if (res2>res1 && res2>res3)
{
mc.red_mc.width = res1;
mc.blue_mc.width = 300 - (res1+res3);
trace(mc.red_mc.width);
mc.blue_mc.x = mc.red_mc.width;
trace(mc.blue_mc.width);
mc.yel_mc.x = (mc.blue_mc.width + mc.red_mc.width);
mc.yel_mc.width = res3;
}
else if(res3>res1 && res3>res2)
{
mc.red_mc.width = res1;
trace(mc.red_mc.width);
mc.blue_mc.x = mc.red_mc.width;
mc.blue_mc.width = res2;
trace(mc.blue_mc.width);
mc.yel_mc.x = (mc.blue_mc.width + mc.red_mc.width);
mc.yel_mc.width = 300 - (res1 + res2);
}
if(val5>val1 && val5<val2)
{
mc.move_mc.x = mc.red_mc.width /2;
}
else if(val5>val2 && val5<val3)
{
mc.move_mc.x = mc.blue_mc.width / 2;
}
else if(val5>val3 && val5<val4)
{
mc.move_mc.x = mc.yel_mc.width / 2;
}
}