A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS2.0 - The project that won't DIE!

  1. #1
    Member
    Join Date
    Sep 2008
    Location
    Chesapeake, VA
    Posts
    35

    Question AS2.0 - The project that won't DIE!

    Over the past few months a few people here have helped me by rewriting my code to better execute my process. Now the rules have changed a bit and I need some help again. I am having a time and a half getting two big things to work again.

    Recently I added more data to the chart (no longer three columns), its now 5.

    1. As a result reset is not working properly
    2. The cascading sharing is not working either. (this means if a bar is grabbed and dragged it borrows from the next up to populate it and when that one is extinguished it then borrows from the next one)

    I was so happy when this was working beautifully, then someone aboveme said let's change things.

    Can anyone help me please?

    here is my code...

    Code:
    /* Things to do...
    
    2. Calibrate bar heights to smaller scale numbers 1-20, if needed.
    
    3. Fix Reset code to accept all 5 bars
    
    4. Fix hierarchial cascading borrowing (1 borrows from 2 and 2 from 3 and so forth)
    
    */
    stop();
    var home = this;
    var g_x = 200;
    var g_seperator = 140;
    var g_width = 50;
    var g_base = 550;
    
    var hold = new Array();
    var maxs = new Array();
    var bars = new Array();
    var lims = new Array();
    
    // [1, 10, 10] = [location, available, minimum] 
    bars.push({boxes:[[1, 10,  5], [2, 50,  6], [3, 10, 12]], id:"IMS"});
    bars.push({boxes:[[1, 60, 10], [2, 50, 12], [3, 10,  5]], id:"IRE"});
    bars.push({boxes:[[1, 30, 20], [2, 70, 10], [3, 15, 10]], id:"MP"});
    bars.push({boxes:[[1, 23, 20], [2, 30, 70], [3,  7, 10]], id:"DBM"});
    bars.push({boxes:[[1,  5,  5], [2, 70, 70], [3, 60, 10]], id:"IA"});
    // bars.push({boxes:[[1, 10, 10], [2, 12, 12], [3, 10, 10], [4, 20, 20], [5, 15, 15], [6, 25, 25], [7, 21, 21], [8, 31, 31], [9, 50, 50], [10, 20, 20], [11, 40, 40], [12, 10, 10], [13, 20, 23], [14, 60, 14], [15, 20, 8]], id:"1N14x"});
    
    var totalBars = bars.length;
    var color_set = new Array(0x660033, 0x990033, 0xff0066, 0xff6699, 0xff99cc, 0x002849, 0x181ba1, 0x6061a8, 0x8086d4, 0x7da7d9, 0x663300, 0xa15128, 0xcc6633, 0xff9900, 0xffcc99);
    var flag_color = 0xFFFF00;
    var today = new Date(year, month, day);
    
    DateField.text = "chart current as of "+today.getDay()+"-"+today.getMonth()+"-"+today.getFullYear();
    function drawBox(mc, w, h, color) {
    	mc.beginFill(color);
    	mc.lineStyle(0,color,100);
    	mc.moveTo(0,0);
    	mc.lineTo(0,-h);
    	mc.lineTo(w,-h);
    	mc.lineTo(w,0);
    	mc.lineTo(0,0);
    	mc.endFill();
    }
    function colorFlag(me, hex) {
    	var my_color = new Color(me.flag);
    	my_color.setRGB(hex);
    }
    function makeBox(barNum, boxNum, posX, posY, wide, tall, color, minReq, LocNum) {
    	var myBox = home.createEmptyMovieClip(barNum+"_Loc"+"-"+boxNum, home.getNextHighestDepth());
    	trace (myBox);
    	var myFlag = myBox.createEmptyMovieClip("flag", 0);
    	drawBox(myFlag,6,tall,color);
    	hold[barNum][boxNum] = myBox;
    	//trace (myBox);
    	myBox._x = posX;
    	myBox._y = posY;
    	myBox.barNum = barNum;
    	myBox.boxNum = boxNum;
    	myBox.baseVal = tall;
    	myBox.minReq = minReq;
    	myBox.LocNum = LocNum;
    	myBox.minVal = (barNum == 0) ? tall : 0;
    	// new addition
    	myBox.dragging = false;
    	drawBox(myBox,wide,tall,color);
    	myBox.onMouseUp = function() {
    		this.dragging = false;
    	};
    	myBox.onRollOver = function() {
    		cap._x = this._x+(g_width-1);
    		cap._y = this._y-14;
    		captionFN(true,this._height,this.boxNum+1);
    		this.onRollOut = function() {
    			captionFN(false);
    		};
    	};
    	myBox.onMouseDown = function() {
    		if (this.hitTest(_xmouse, _ymouse) && !this.dragging) {
    			this.startY = _ymouse;
    			this.startX = _xmouse;
    			this.startH = this._height;
    			this.dragging = true;
    		}
    	};
    	myBox.onMouseMove = function() {
    		if (this.dragging) {
    			var num = (this.barNum-1<0) ? totalBars-1 : this.barNum-1;
    			var prevBar = hold[num][this.boxNum];
    			num = (this.barNum+1>=totalBars) ? 0 : this.barNum+1;
    			var nextBar = hold[num][this.boxNum];
    			var dist = this.startH-(_ymouse-this.startY);
    			(dist>this.limit) ? dist=this.limit : null;
    			(dist<this.minVal) ? dist=this.minVal : null;
    			var chg = dist-this._height;
    			//
    			captionFN(true,this._height,this.LocNum);
    			if (chg>0) {
    				if (this.barNum == 0) {
    					tmp = nextBar;
    					nextBar = prevBar;
    					prevBar = tmp;
    				}
    				if (prevBar._height-chg<prevBar.minVal) {
    					chg = prevBar.minVal-(prevBar._height-chg);
    					prevBar._height = prevBar.minVal;
    				} else {
    					prevBar._height -= chg;
    					chg = 0;
    				}
    				if (nextBar._height-chg<nextBar.minVal) {
    					chg = nextBar.minVal-(nextBar._height-chg);
    					nextBar._height = nextBar.minVal;
    				} else {
    					nextBar._height -= chg;
    					chg = 0;
    				}
    				dist += chg;
    			} else if (chg<0) {
    				if (this.barNum == 1) {
    					tmp = nextBar;
    					nextBar = prevBar;
    					prevBar = tmp;
    				}
    				if (prevBar._height-chg>prevBar.limit) {
    					chg = prevBar.limit-(prevBar._height-chg);
    					prevBar._height = prevBar.limit;
    				} else {
    					prevBar._height -= chg;
    					chg = 0;
    				}
    				if (nextBar._height-chg>nextBar.limit) {
    					chg = nextBar.limit-(nextBar._height-chg);
    					nextBar._height = nextBar.limit;
    				} else {
    					nextBar._height -= chg;
    					chg = 0;
    				}
    				dist += chg;
    			}
    			if (dist-this._height != 0) {
    				this._height = dist;
    				captionFN(true,this._height,this.LocNum);
    				// this is displayed in the info block at the top right
    				home.boxValue.text = this._height;
    				home.boxName.text = "loc-"+(this.LocNum);
    				updateAll();
    				this.startH = this._height;
    				this.startY = _ymouse;
    				for (var i = 0; i<hold.length; i++) {
    					for (var j = 0; j<hold[i].length-1; j++) {
    						hold[i][j+1]._y = hold[i][j]._y-hold[i][j]._height;
    					}
    				}
    			}
    		}
    	};
    	Mouse.addListener(myBox);
    }
    function updateAll() {
    	for (var i = 0; i<hold.length; i++) {
    		for (var j = 0; j<hold[i].length; j++) {
    			hold[i][j+1]._y = hold[i][j]._y-hold[i][j]._height;
    			if (hold[i][j]._height<hold[i][j].minReq) {
    				colorFlag(hold[i][j],flag_color);
    			} else {
    				colorFlag(hold[i][j],color_set[j]);
    			}
    		}
    	}
    }
    captionFN = function (showCaption, captionText, bName) {
    	if (showCaption) {
    		home.createEmptyMovieClip("hoverCaption",100000);
    		cap._width = 7*cap.desc.text.length;
    		cap._alpha = 100;
    		cap.desc.text = "Current value - "+captionText;
    		cap.desc2.text = "name"+bName;
    		// cap.desc3.text = "Needed - "+bName.minVal;
    		if ((bName._width+bName._x+cap._width)>Stage.width) {
    			xo = -15-cap._width;
    			yo = -10;
    		} else {
    			xo = 15;
    			yo = -10;
    		}
    		hoverCaption.onEnterFrame = function() {
    			cap._visible = true;
    		};
    	} else {
    		delete hoverCaption.onEnterFrame;
    		cap._visible = false;
    	}
    };
    function doInit() {
    	for (var j = 0; j<totalBars; j++) {
    		hold[j] = new Array();
    		var baseX = g_x+(j*g_seperator);
    		var baseY = g_base;
    		for (var i = 0; i<bars[j].boxes.length; i++) {
    			makeBox(j,i,baseX,baseY,g_width,bars[j].boxes[i][1],color_set[i],bars[j].boxes[i][2],bars[j].boxes[i][0]);
    			baseY -= bars[j].boxes[i][1];
    		}
    	}
    	maxs = new Array();
    	for (var m in hold) {
    		for (var n in hold[m]) {
    			(maxs[n] == undefined) ? maxs[n]=0 : null;
    			hold[m][n].limit = maxs[n]+hold[m][n].baseVal;
    			maxs[n] += hold[m][n].baseVal;
    			//trace (m);
    		}
    	}
    	updateAll();
    }
    btnReset.onPress = function() {
    	for (var m in hold) {
    		for (var n in hold[m]) {
    			hold[m][n].removeMovieClip();
    			trace ("reset"+hold[m][n]);
    			
    		}
    	}
    	doInit();
    };
    
    // Starts the process
    doInit();
    Thanks so much,
    ICR8STF

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    we will need actually a bit more explanation of your project to understand what exactly you are trying to do... maybe give us a link? also check out my xml driven flash bar chart in my library (not sure how much it will help but may give you some ideas)
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Member
    Join Date
    Sep 2008
    Location
    Chesapeake, VA
    Posts
    35

    Question

    here is the gist of the project...

    let's say we have 5 classrooms. 1 for each grade 1-5.

    column one shows grade 1 - in this classroom there are three job or duty positions (chalkboard cleaner, sweeper and desk organizer). The other grades also have these duty positions.

    Now say you view the graph and you notice that the 3rd grade class is short a board cleaner and you want to adjust the graph to "borrow" from another grade. Well as it ends up the 3rd grade cleaners have a few more skills than a 2nd or 1st grader can do so you can only borrow from a higher grade. Let's also imagine after borrowing all the 4th grade board cleaners you still need more. Well this graph used to intelligently cascade into the 5th grade and borrow from there. However it is no longer doing that. I am not overly concerned about the minimums at this point.

    If you only have three data arrays (instead of the original 5) ...
    Code:
    bars.push({boxes:[[1, 10,  5], [2, 50,  6], [3, 10, 12]], id:"IMS"});
    bars.push({boxes:[[1, 60, 10], [2, 50, 12], [3, 10,  5]], id:"IRE"});
    bars.push({boxes:[[1, 30, 20], [2, 70, 10], [3, 15, 10]], id:"MP"});
    //bars.push({boxes:[[1, 23, 20], [2, 30, 70], [3,  7, 10]], id:"DBM"});
    //bars.push({boxes:[[1,  5,  5], [2, 70, 70], [3, 60, 10]], id:"IA"});
    the hierarchy/cascading borrowing works fine. Add in more and things go a bit differently.

    As for the reset it is broken somehow. I am thinking it is a naming issue of the MC's.

    Does this shed a bit more light on the subject. I am sorry I left that out of the initial posting.

    Thank you.

Tags for this Thread

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