A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: simple loop- missing something

  1. #1
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707

    simple loop- missing something

    hi all, while continuing my quest to "sample colors" i made a small little test app with the following code.
    Code:
    function getSample() {
    	bmp.draw(mcHolder);
    	sample = bmp.getPixel(_xmouse, _ymouse);
    	newColor = sample.toString(16);
    	//return newColor;
    	changeBoxColor(newColor);
    	//hexadecimal formula- can use this variable later to pass to new color
    }
    //____________________________________________________________________add mouse listener
    var oMouseListen:Object = new Object();
    oMouseListen.onMouseDown = function() {
    	getSample();
    };
    Mouse.addListener(oMouseListen);
    //____________________________________________________________________ change sample box to selected color
    var box = sampleBox_mc0.theBox;//make 5 instances of this guy
    var txBox:TextField = sampleBox_mc0.txSample;
    var border=sampleBox_mc0.mcBorder
    function changeBoxColor(newColor) {
    	thisColor = "0x"+newColor;
    	var boxColor:Color = new Color(box);
    	var txStyle:TextFormat = new TextFormat();
    	txStyle.color = thisColor;
    	boxColor.setRGB(thisColor);
    	txBox.setTextFormat(txStyle);
    }
    box.onRelease=function(){
    	setBorder(this);
    	this.selectedBox=true;
    }
    works fine. However, i would like to add 4 more instantces of "box" . i was trying to do this with a loop, but not finding success...any ideas

    Code:
    //____________________________________________________________________ get pixels function
    function getSample() {
    	bmp.draw(mcHolder);
    	sample = bmp.getPixel(_xmouse, _ymouse);
    	newColor = sample.toString(16);
    	//return newColor;
    	changeBoxColor(newColor);
    	//hexadecimal formula- can use this variable later to pass to new color
    }
    //____________________________________________________________________add mouse listener
    var oMouseListen:Object = new Object();
    oMouseListen.onMouseDown = function() {
    	getSample();
    };
    Mouse.addListener(oMouseListen);
    //____________________________________________________________________ change sample box to selected color
    box = [];
    txBox = [];
    function changeBoxColor(newColor) {
    	for (i=0; i<4; i++) {
    		var txStyle:TextFormat = new TextFormat();
    		thisColor = "0x"+newColor;
    		box = sampleBox_mc[i].theBox;
    		txBox = sampleBox_mc[i].txSample;
    		boxColor = new Color(box);
    		boxColor.setRGB(thisColor);
    		txBox.setTextFormat(txStyle);
    		txStyle.color = thisColor;
    	}
    }
    box.onRelease = function() {
    };

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Do you want to add the the instances of the box with that code?
    The code is a bit difficult to understand, but I guess that if you want to create four boxes, that's no the piece of code you have to modify.
    That piece seems to change the colour of a movie clip, just like the name of the function indicates. I don't think it's used to create a box.

    Or have you already added the boxes, and want to change their colour?

    Wouldn't you like to upload a .fla with a very simple example so that someone can look at it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center