Cannot see the content inside of a MovieClip - actionscript-3

I don't know why this is happening. What I want to do is easy: Create a container and then add a grid of squares in order to build a trivia:
private var square:MovieClip = new MovieClip();
square.width = 308;
square.height = 400;
square.x = 48;
square.y = 223;
square.name = "square";
addChild(square);
private function generarGrilla():void {
var cant = 36;
var col:Number = 5;
var yCounter:Number = -4;
var xCounter:Number = 4;
var sY:Number = 10;
var sX:Number = 10;
for (var j = 1; j < cant; j++) {
var caja:clip = new clip();
caja.name = "opcion" + j;
caja.x = 20 + caja.width * j * 1.2;
caja.y = 20 + caja.height * j * 1.2;;
// caja.x = (sX + caja.width) * xCounter ;
// caja.y = (sY + caja.height) * yCounter;
caja.addEventListener(MouseEvent.CLICK, seleccionarOpcion);
caja.buttonMode = true;
caja.mouseChildren = false;
var contentText = new TextField();
var formato = new TextFormat();
formato.size = 14;
contentText.defaultTextFormat = formato;
contentText.width = 36;
contentText.height = 34;
contentText.x = -10;
contentText.y = -10;
for(var u:uint = 0; u < cant; u++){
contentText.text = "" + u;
}
square.addChild(caja);
caja.addChild(contentText);
}
var barra:score = new score();
barra.x = 80;
barra.y = -200;
barra.puntajeTXT.text = "hola";
addChild(barra);
barra.botonSalir.buttonMode = true;
barra.botonSalir.addEventListener(MouseEvent.CLICK, salirJuego);
}
The square movieclip is placed on the stage without any problem, but I cannot see the grid...

Related

How to Get (& Set) cell values from one sheet to another in Google Sheets?

Looking to get values from several cells in the first sheet (POTemplate) of my Google Sheet file that serves as an order entry form. Line 22 is the first line in the form that collects data from our user regarding items requested for order.
The tab to which I'd like to set these values (POHistory) will serve as a running log of all order details keyed into the POTemplate tab with each order. Each entry recorded in the PO template log should include each orders' unique PO No. (found in cell N3 of the POTemplate tab) & PO Date (cell N4 of the POTemplate tab). I sincerely appreciate the help.
function submit() {
var app = SpreadsheetApp;
var tplSheet = app.getActiveSpreadsheet().getSheetByName("POTemplate");
var tplFRow = 22, tplLRow = tplSheet.getLastRow();
var tplRowsNum = tplLRow - tplFRow + 1;
var tplFCol = 1, tplLCol = 16;
var tplColsNum = tplLCol - tplFCol + 1;
var rangeData = tplSheet.getRange(22, 1, tplRowsNum, tplColsNum).getValues();
var colIndexes = [0, 3, 10, 12, 15];
var fData = filterByIndexes(rangeData, colIndexes);
var target = "POHistory";
var targetSheet = app.getActiveSpreadsheet().getSheetByName(target);
var tgtRow = targetSheet.getLastRow() + 1;
var tgtRowsNum = fData.length - tgtRow + 1;
var tgtCol = 1;
var tgtColsNum = fData[0].length - 1 + 1;
targetSheet.getRange(tgtRow, tgtCol, tgtRowsNum,
tgtColsNum).setValues(fData);
}
function filterByIndexes(twoDArr, indexArr) {
var fData = [];
twoDArr = twoDArr.transpose();
for(var i=0; i<indexArr.length; i++) {
fData.push(twoDArr[indexArr[i]]);
}
return fData.transpose();
}
Array.prototype.transpose = function() {
var a = this,
w = a.length ? a.length : 0,
h = a[0] instanceof Array ? a[0].length : 0;
if (h === 0 || w === 0) {return [];}
var i, j, t = [];
for (i = 0; i < h; i++) {
t[i] = [];
for (j = 0; j < w; j++) {
t[i][j] = a[j][i];
}
}
return t;
}
I can offer you a modification of the submit() function you have given.
function process(){
submit();
submitDate();
}
function submitDate() {
var app = SpreadsheetApp;
var tplSheet = app.getActiveSpreadsheet().getSheetByName("POTemplate");
var tplFRow = 1, tplLRow = 21;
var tplRowsNum = tplLRow - tplFRow + 1;
var tplFCol = 1, tplLCol = 16;
var tplColsNum = tplLCol - tplFCol + 1;
var rangeData = tplSheet.getRange(tplFRow, tplFCol, tplLRow, tplColsNum).getValues();
var colIndexes = [13];
var fData = filterByIndexes(rangeData, colIndexes);
var target = "POHistory";
var targetSheet = app.getActiveSpreadsheet().getSheetByName(target);
var tgtRow = targetSheet.getLastRow() + 1;
var tgtRowsNum = fData.length - tgtRow + 1;
var tgtCol = 1;
var tgtColsNum = fData[0].length - 1 + 1;
Logger.log(fData)
fData=fData.transpose();
Logger.log(fData)
targetSheet.getRange(tgtRow-1, 5, fData.length,
fData[0].length).setValues(fData);
}
function submit() {
var app = SpreadsheetApp;
var tplSheet = app.getActiveSpreadsheet().getSheetByName("POTemplate");
var tplFRow = 22, tplLRow = tplSheet.getLastRow();
var tplRowsNum = tplLRow - tplFRow + 1;
var tplFCol = 1, tplLCol = 16;
var tplColsNum = tplLCol - tplFCol + 1;
var rangeData = tplSheet.getRange(22, 1, tplRowsNum, tplColsNum).getValues();
var colIndexes = [0, 3, 10, 12, 15];
var fData = filterByIndexes(rangeData, colIndexes);
var target = "POHistory";
var targetSheet = app.getActiveSpreadsheet().getSheetByName(target);
var tgtRow = targetSheet.getLastRow() + 1;
var tgtRowsNum = fData.length - tgtRow + 1;
var tgtCol = 1;
var tgtColsNum = fData[0].length - 1 + 1;
targetSheet.getRange(tgtRow, tgtCol, tgtRowsNum,
tgtColsNum).setValues(fData);
}
function filterByIndexes(twoDArr, indexArr) {
var fData = [];
twoDArr = twoDArr.transpose();
for(var i=0; i<indexArr.length; i++) {
fData.push(twoDArr[indexArr[i]]);
}
return fData.transpose();
}
Array.prototype.transpose = function() {
var a = this,
w = a.length ? a.length : 0,
h = a[0] instanceof Array ? a[0].length : 0;
if (h === 0 || w === 0) {return [];}
var i, j, t = [];
for (i = 0; i < h; i++) {
t[i] = [];
for (j = 0; j < w; j++) {
t[i][j] = a[j][i];
}
}
return t;
}
Basically, similar code runs twice. I could be criticized for doing this, but perhaps it is convenient for you this way.

How to make swap(random) positions between 3 objects by AS3?

//array
var boxs: Array = new Array
boxs[0] = [b1.x = 307.95 , b1.y = 202]
boxs[1] = [b2.x = 233.95 , b2.y = 202]
boxs[2] = [b3.x = 159.95 , b3.y = 202]
//varable
var oldg:Number = 0
//random number
oldg = Number(Math.floor(Math.random()*boxs.length))
Naive approach:
public function Main()
{
const array:Array = [1,2,3,4,5,6,7];
trace(array);
// 1,2,3,4,5,6,7
swapTwoRandomElements(array);
trace(array);
// 1,2,3,6,5,4,7
}
private function swapTwoRandomElements(input:Array):void
{
const indices:Array = [];
for (var i:int = 0; i < input.length; i++)
{
indices.push(i);
}
const indexFirst:int = indices[int(Math.random() * indices.length)];
indices.splice(indexFirst, 1);
const indexSecond:int = indices[int(Math.random() * indices.length)];
indices.splice(indexSecond, 1);
const tmp:* = input[indexFirst];
input[indexFirst] = input[indexSecond];
input[indexSecond] = tmp;
}

Spawning a random number of movieclips - function doesn't work?

I am trying to figure out how to spawn a random number of cells, but every time I run the program, I always end up with one cell only.
How come the number of cells spawned is always 1 when it can go up to 50? (since I made the p variable a random number between 1 and 50).
var myCell:Cell = new Cell();
var minLimit:uint = 1;
var maxLimit:uint = 50;
var range:uint = maxLimit - minLimit;
var p:Number = Math.ceil(Math.random()*range) + minLimit;
for (p; p < maxLimit; p += 1)
{
addChild(myCell);
myCell.x = xp
myCell.y = xp
myCell.scaleX = 6
myCell.scaleY = 6
var xminLimit:uint = 100;
var xmaxLimit:uint = 400;
var xrange:uint = xmaxLimit - xminLimit;
var xp:Number = Math.ceil(Math.random()*xrange) + xminLimit;
}
You need to move the instance creation code (var myCell:Cell = new Cell();) inside the loop to create maxLimit number of instance instead you are creating only one instance outside the loop.
Try this,
var minLimit:uint = 1;
var maxLimit:uint = 50;
var range:uint = maxLimit - minLimit;
var p:Number = Math.ceil(Math.random()*range) + minLimit;
for (p; p < maxLimit; p += 1)
{
var myCell:Cell = new Cell();
var xminLimit:uint = 100;
var xmaxLimit:uint = 400;
var xrange:uint = xmaxLimit - xminLimit;
var xp:Number = Math.ceil(Math.random()*xrange) + xminLimit;
addChild(myCell);
myCell.x = xp
myCell.y = xp
myCell.scaleX = 6
myCell.scaleY = 6
}

Laplace image filter

I took the example of Laplace from "Making image filters with Canvas", but I can not understand the use of Math.min() function in the following lines. Can anyone explain to me how the Laplace?
var weights = [-1,-1,-1,
-1, 8,-1,
-1,-1,-1];
var opaque = true;
var side = Math.round(Math.sqrt(weights.length));
var halfSide = Math.floor(side/2);
var imgd = context.getImageData(0, 0, canvas.width, canvas.height);
var src = imgd.data;
var sw = canvas.width;
var sh = canvas.height;
var w = sw;
var h = sh;
var output = contextNew.createImageData(w, h);
var dst = output.data;
var alphaFac = opaque ? 1 : 0;
for (var y=0; y<h; y++) {
for (var x=0; x<w; x++) {
var sy = y;
var sx = x;
var dstOff = (y*w+x)*4;
var r=0, g=0, b=0, a=0;
for (var cy=0; cy<side; cy++) {
for (var cx=0; cx<side; cx++) {
var scy = Math.min(sh-1, Math.max(0, sy + cy - halfSide));
var scx = Math.min(sw-1, Math.max(0, sx + cx - halfSide));
var srcOff = (scy*sw+scx)*4;
var wt = weights[cy*side+cx];
r += src[srcOff] * wt;
g += src[srcOff+1] * wt;
b += src[srcOff+2] * wt;
a += src[srcOff+3] * wt;
}
}
dst[dstOff] = r;
dst[dstOff+1] = g;
dst[dstOff+2] = b;
dst[dstOff+3] = a + alphaFac*(255-a);
}
}
its algorithm is something like
for y = 0 to imageHeight
for x = 0 to imageWidth
sum = 0
for i = -h to h
for j = -w to w
sum = sum + k(j, i) * f(x – j, y – i)
end for j
end for i
g(x, y) = sum end for x end for y

Syntax error 1084 whatever i do

I am trying to make a tool for a game...
Pushing a button gives some results after calculations. The Code is not finished yet but it does not have to give errors. Here is the code:
import flash.events.MouseEvent;
//-----------------------variables------------------------
var iPPP1:String;
var iPPP2:String;
var iPPP3:String;
var iPPP4:String;
var iPPP5:String;
var iPPP6:String;
var iPPP7:String;
var iCntbonus:String;
var iRawPrice:String;
var iAverSal:String;
var iTax:String;
var iNoC7:String;
var iNoC6:String;
var iNoC5:String;
var iNoC4:String;
var iNoC3:String;
var iNoC2:String;
var iNoC1:String;
var iEm7:String;
var iEm6:String;
var iEm5:String;
var iEm4:String;
var iEm3:String;
var iEm2:String;
var iEm1:String;
var iRaw5:String;
var iRaw4:String;
var iRaw3:String;
var iRaw2:String;
var iRaw1:String;
var apotelesma:Number;
var bonus:Number;
var i1:Number;
var i2:Number;
var i3:Number;
var i4:Number;
var i5:Number;
var i6:Number;
var i7:Number;
//------------------------restricts------------------------
PPP1.restrict = "0-9\\.";
PPP2.restrict = "0-9\\.";
PPP3.restrict = "0-9\\.";
PPP4.restrict = "0-9\\.";
PPP5.restrict = "0-9\\.";
PPP6.restrict = "0-9\\.";
PPP7.restrict = "0-9\\.";
Cntbonus.restrict = "0-5";
RawPrice.restrict = "0-9\\.";
AverSal.restrict = "0-9\\.";
Tax.restrict = "0-9";
NoC7.restrict = "0-9";
NoC6.restrict = "0-9";
NoC5.restrict = "0-9";
NoC4.restrict = "0-9";
NoC3.restrict = "0-9";
NoC2.restrict = "0-9";
NoC1.restrict = "0-9";
Em7.restrict = "0-9";
Em6.restrict = "0-9";
Em5.restrict = "0-9";
Em4.restrict = "0-9";
Em3.restrict = "0-9";
Em2.restrict = "0-9";
Em1.restrict = "0-9";
Raw5.restrict = "0-9";
Raw4.restrict = "0-9";
Raw3.restrict = "0-9";
Raw2.restrict = "0-9";
Raw1.restrict = "0-9";
//-------------------------------borders----------------------------
PPP1.border = true;
PPP2.border = true;
PPP3.border = true;
PPP4.border = true;
PPP5.border = true;
PPP6.border = true;
PPP7.border = true;
Cntbonus.border = true;
RawPrice.border = true;
AverSal.border = true;
Tax.border = true;
NoC7.border = true;
NoC6.border = true;
NoC5.border = true;
NoC4.border = true;
NoC3.border = true;
NoC2.border = true;
NoC1.border = true;
Em7.border = true;
Em6.border = true;
Em5.border = true;
Em4.border = true;
Em3.border = true;
Em2.border = true;
Em1.border = true;
Raw5.border = true;
Raw4.border = true;
Raw3.border = true;
Raw2.border = true;
Raw1.border = true;
//--------------------------calculations-------------------------------
calc_btn.addEventListener(MouseEvent.CLICK, Calco);
function Calco(event:MouseEvent):void;
{
iPPP1 = PPP1.text;
iPPP2 = PPP2.text;
iPPP3 = PPP3.text;
iPPP4 = PPP4.text;
iPPP5 = PPP5.text;
iPPP6 = PPP6.text;
iPPP7 = PPP7.text;
iCntbonus = Cntbonus.text;
iRawPrice = RawPrice.text;
iAverSal = AverSal.text;
iTax = Tax.text;
iNoC7 = NoC7.text;
iNoC6 = NoC6.text;
iNoC5 = NoC5.text;
iNoC4 = NoC4.text;
iNoC3 = NoC3.text;
iNoC2 = NoC2.text;
iNoC1 = NoC1.text;
iEm7 = Em7.text;
iEm6 = Em6.text;
iEm5 = Em5.text;
iEm4 = Em4.text;
iEm3 = Em3.text;
iEm2 = Em2.text;
iEm1 = Em1.text;
iRaw5 = Raw5.text;
iRaw4 = Raw4.text;
iRaw3 = Raw3.text;
iRaw2 = Raw2.text;
iRaw1 = Raw1.text;
i1 = (parseInt(iEm1) + parseInt(iNoC1)) * 10 * bonus;
i2 = (parseInt(iEm2) + parseInt(iNoC2)) * 10 * bonus;
i3 = (parseInt(iEm3) + parseInt(iNoC3)) * 10 * bonus;
i4 = (parseInt(iEm4) + parseInt(iNoC4)) * 10 * bonus;
i5 = (parseInt(iEm5) + parseInt(iNoC5)) * 10 * bonus;
i6 = (parseInt(iEm6) + parseInt(iNoC6)) * 10 * bonus;
i7 = (parseInt(iEm7) + parseInt(iNoC7)) * 10 * bonus;
if (parseInt(iCntbonus) == 0) {
bonus = 1;
} else if (parseInt(iCntbonus) == 1) {
bonus = 1,2;
} else if (parseInt(iCntbonus) == 2) {
bonus = 1,4;
} else if (parseInt(iCntbonus) == 3) {
bonus = 1,6;
} else if (parseInt(iCntbonus) == 4) {
bonus = 1,8;
} else {
bonus = 2;
}
// υπολογισμός εσόδων
apotelesma = (Number(iRawPrice)*bonus*parseInt(iRaw1)*35)+(Number(iRawPrice)*bonus*parseInt(iRaw2)*70)+(Number(iRawPrice)*bonus*parseInt(iRaw3)*125)+(Number(iRawPrice)*bonus*parseInt(iRaw4)*175)+(Number(iRawPrice)*bonus*parseInt(iRaw5)*250)
apotelesma = apotelesma + (i1 * Number(iPPP1)) - (i1 * (parseInt(iTax) / 100) + (i2 * Number(iPPP2)) - (i2 * (parseInt(iTax) / 100) + (i3 * Number(iPPP3)) - (i3 * (parseInt(iTax) / 100) + (i4 * Number(iPPP4)) - (i4 * (parseInt(iTax) / 100) + (i5 * Number(iPPP5)) - (i5 * (parseInt(iTax) / 100) + (i6 * Number(iPPP6)) - (i6 * (parseInt(iTax) / 100) + (i7 * Number(iPPP7)) - (i7 * (parseInt(iTax) / 100)
apotelesma.toString()
}
I have problem with the last 3 lines...
You have some very long calculations, and are missing atleast 5 closing parenetheses. I pasted the 2nd to the last line (the one that starts with apotelesma = apotelesma) into a text editor and counted the numbers of opening/closing parentheses.
The calculation is so long, it's not immediately clear where they should be inserted. I would break down the calculations so that they are more readable. Anyone maintaining this code after you will benefit from the clarity.
Either break the long calculations up into many smaller ones, or just add line breaks in the code so it's clear what you're trying to do, like this:
apotelesma = apotelesma +
(i1 * Number(iPPP1)) -
(i1 * (parseInt(iTax) / 100) + // NOTE: you seem to be missing a closing paren here
(i2 * Number(iPPP2)) -
(i2 * (parseInt(iTax) / 100) + // and here... (and so on)
...