Gradient masking flash - actionscript-3

i want to put gradient masking effect in my 20 images.
var arr:Array = ["m1.jpg","m2.jpg","m3.jpg","m4.jpg","m5.jpg"];
for(var i=0; i<20; i++){
duplicateMovieClip(ho, "newImg_mc"+i , this.getNextHighestDepth());
if(i < 5){
this["newImg_mc"+i]._x = 0;
this["newImg_mc"+i]._y = 110*i;
this["newImg_mc"+i].loadMovie(arr[i]);
}
if(i >= 5 and i < 10){
this["newImg_mc"+i]._x = 110;
this["newImg_mc"+i]._y = 110*(i-5);
this["newImg_mc"+i].loadMovie(arr[i-5]);
}
if(i >= 10 and i < 15){
this["newImg_mc"+i]._x = 220;
this["newImg_mc"+i]._y = 110*(i-10);
this["newImg_mc"+i].loadMovie(arr[i-10]);
}
if(i >= 15 and i < 20){
this["newImg_mc"+i]._x = 330;
this["newImg_mc"+i]._y = 110*(i-15);
this["newImg_mc"+i].loadMovie(arr[i-15]);
}
}

you need to set the blendMode of the mask and the masked object to BlendMode.LAYER.

Related

Auto reply Gmail excluding some address and object

I would like to no autoreply to some email objects (es: no_reply) and some email address.
I've tried with this code but it doesn't work. What is wrong with it?
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var exclude = ['noreply','no_reply','assistenza'];
var exclude_obj = ['Email ricevuta','Messaggio ricevuto','test'];
var wkend = [6,0]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var wkendMessage = "Ciao";
var wkdayMessage = "Ciao ciao";
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
if (wkend.indexOf(day) > -1 || (day == 5 && hour < 18)) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('subject:"xxx" is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
if(!exclude.includes(threads[i].getMessages()[0].getFrom().split("#")[0])
&& !exclude_obj.includes(threads[i].getMessages()[0].getFrom()[0])
){
threads[i].reply(wkendMessage);
}
}
}
else if ((hour > 11 && hour < 19) || (hour < 0 && hour > 11) ) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
if(!exclude.includes(threads[i].getMessages()[0].getFrom().split("#")[0])
&& !exclude_obj.includes(threads[i].getMessages()[0].getFrom()[0])
){
threads[i].reply(wkdayMessage);
}
}
}
}
function doGet() {
return ContentService.createTextOutput("");
}

Compiling time takes too long

Here is my code:
function dataValidation()
{
var ss1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("2019년 출결 정보");
var ss2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("원생 정보");
var array = [];
for (var c = 0; c <= 1000; c++)
{
array[c] = [];
}
var count = 0;
var lastRow1;
var data1 = ss1.getRange("C:C").getValues();
for (var k = data1.length-1; k >= 0; k--)
{
if (data1[k][0] != null && data1[k][0] != '')
{
lastRow1 = k+1;
break;
}
}
var lastRow2;
var data2 = ss2.getRange("A:A").getValues();
for (var n = data2.length-1; n >=0; n--)
{
if (data2[n][0] != null && data2[n][0] != '')
{
lastRow2 = n+1;
break;
}
}
for (var i = 2; i <= lastRow1; i++)
{
for (var j = 2; j <= lastRow2; j++)
{
if (ss1.getRange(i, 3).getDisplayValue() == ss2.getRange(j, 1).getDisplayValue())
{
array[i-1][count] = ss2.getRange(j, 2).getDisplayValue();
count++;
}
}
var rule = SpreadsheetApp.newDataValidation().requireValueInList(array[i-1], true).setAllowInvalid(false).build();
ss1.getRange(i, 4).setDataValidation(rule);
count = 0;
}
}
I am so concerned because the compile speed takes too long... It takes about a minute to fully execute :(
Execution hint suggests to change from line 71:
for (var i = 2; i <= lastRow1; i++)
{
for (var j = 2; j <= lastRow2; j++)
{
if (ss1.getRange(i, 3).getDisplayValue() == ss2.getRange(j, 1).getDisplayValue())
{
array[i-1][count] = ss2.getRange(j, 2).getDisplayValue();
count++;
}
}
Personally I think this is because of nested loops but I don't have any clever ideas to replace this loops, nor I have much knowledge about google apps script.
What else I can do to decrease compile time?

Random hexidecimal color generator in AS3

I wanted to create the ability to have "random" (pseudo-random) colors generated and came up with this code intended to create all and any color.
I'm very new to programming and wanted to see if anyone on S.O. had any comments or criticisms, the code works great. Only problem is the colors occasionally being too similar making it difficult to differentiate bewteen them.
I know this is likely a very brute force fashion of coding but its what I thought of.
Hexidecimal generator
public class colorGenerator
{
public var color:int;
private var randomnumber:Number;
private var first:String = "";
public function colorGenerator():void
{
var colorstring:String = "0x";
var transfer:String = "0x";
for ( var i:uint = 0; i < 6; i++)
{
randomhex();
colorstring += first;
}
transfer = colorstring;
color = int(transfer);
}
public function randomhex():void
{
randomnumber = Math.random();
if ( -1 < randomnumber < ((.99 / 16) * 1))
first = "0";
else if ( ((.99/16)*1) < randomnumber < ((.99/16)*2))
first = "1";
else if ( ((.99/16)*2)< randomnumber < ((.99/16)*3))
first = "2";
else if ( ((.99/16)*3)< randomnumber < ((.99/16)*4))
first = "3";
else if ( ((.99/16)*4)< randomnumber < ((.99/16)*5))
first = "4";
else if ( ((.99/16)*5)< randomnumber < ((.99/16)*6))
first = "5";
else if ( ((.99/16)*6)< randomnumber < ((.99/16)*7))
first = "6";
else if ( ((.99/16)*7)< randomnumber < ((.99/16)*8))
first = "7";
else if ( ((.99/16)*8)< randomnumber < ((.99/16)*9))
first = "8";
else if ( ((.99/16)*9)< randomnumber < ((.99/16)*10))
first = "9";
else if ( ((.99/16)*10)< randomnumber < ((.99/16)*11))
first = "A";
else if ( ((.99/16)*11)< randomnumber < ((.99/16)*12))
first = "B";
else if ( ((.99/16)*12)< randomnumber < ((.99/16)*13))
first = "C";
else if ( ((.99/16)*13)< randomnumber < ((.99/16)*14))
first = "D";
else if ( ((.99/16)*14)< randomnumber < ((.99/16)*15))
first = "E";
else if ( ((.99/16)*15)< randomnumber < 2)
first = "F";
}
}
I then just assign the hexidecimal value to a variable in another class
var acolor:colorGenerator = new colorGenerator;
var COLOR:uint = acolor.color
Thanks for any comments!
This should work as well.
Math.random() * 0xFFFFFF;
Not tested but this should be more "random":
var red : int = Math.floor(Math.random()*255);
var green : int = Math.floor(Math.random()*255);
var blue : int = Math.floor(Math.random()*255);
var color : int = red << 16 | green << 8 | blue;

ActionScript 3.0 TypeError #1009 Null object? but there is no null object?

I am making a game in flash and my only problem so far is this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at farmgame227_fla::MainTimeline/onenter()[farmgame227_fla.MainTimeline::frame2:144]
The line will vary depending on how I move to the next frame. I am 99% sure a null object is not the problem, so I am stumped. I will show my entire code for frame 2 and I would appreciate it so much if anyone could lend some insight.
stop();
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,onenter);
stop();
//starting positions for sheep
sheep1.y = 330
sheep1.x = 350
sheep2.y = 360
sheep2.x = 380
sheep3.y = 300
sheep3.x = 450
sheep4.y = 330
sheep4.x = 350
gold.y = 150
gold.x = 800
goat.y = 620
goat.x = 800
var myscore = 0;
function onenter(e:Event)
{
//hand follows mouse cursor
hand.x = mouseX;
hand.y = mouseY;
//sheep velocity
sheep1.x = sheep1.x + 1;
sheep1.y = sheep1.y - 1;
sheep2.x = sheep2.x - 1;
sheep2.y = sheep2.y - 1;
sheep3.x = sheep3.x + 1;
sheep3.y = sheep3.y + 1;
sheep4.x = sheep4.x - 3;
sheep4.y = sheep4.y + 3;
//sheep1's boundaries
if (sheep1.y < 0 || sheep1.y > 775 || sheep1.x < 0 || sheep1.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//sheep2's boundaries
if (sheep2.y < 0 || sheep2.y > 775 || sheep2.x < 0 || sheep2.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//sheep3's boundaries
if (sheep3.y < 0 || sheep3.y > 775 || sheep3.x < 0 || sheep3.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//sheep4's boundaries
if(sheep4==null)
{
trace("4 it's null");
}
if (sheep4.y < 0 || sheep4.y > 775 || sheep4.x < 0 || sheep4.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//hand hitting sheep, sending them back
if(sheep1==null)
{
trace("1 is null");
}
if(hand==null)
{
trace("hand is null");
}
if(fence==null)
{
trace("fence is null");
}
if (hand.hitTestObject (sheep1))
{
sheep1.y = 330;
sheep1.x = 350;
myscore = myscore + 1;
}
if (hand.hitTestObject (sheep2))
{
sheep2.y = 360;
sheep2.x = 380;
myscore = myscore + 1;
}
if (hand.hitTestObject (sheep3))
{
sheep3.y = 300;
sheep3.x = 450;
myscore = myscore + 1;
}
if (hand.hitTestObject (sheep4))
{
sheep4.y = 330;
sheep4.x = 350;
myscore = myscore + 1;
}
if (hand.hitTestObject (gold))
{
gold.x = 2500;
gold.y = 610;
gold.x = gold.x - 9;
myscore = myscore + 5;
}
if (hand.hitTestObject (goat))
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//hand touching fence, results in game over
if (hand.hitTestObject (fence))
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
score.text = myscore;
//changing sheep speed based on score
//score 40 and 55 should be next
if (myscore >= 12)
{
sheep2.x = sheep2.x - 2;
sheep2.y = sheep2.y - 2;
}
if (myscore >= 24)
{
sheep3.x = sheep3.x + 2;
sheep3.y = sheep3.y + 2;
}
if (myscore >= 30)
{
sheep1.x = sheep1.x + 3;
sheep1.y = sheep1.y - 3;
}
//initiating and controlling gold and goat
if (myscore > 17)
{
gold.x = gold.x - 8;
}
if (gold.x < -9)
{
gold.x = 2000;
gold.y = 610;
gold.x = gold.x - 9;
}
if (myscore > 8)
{
goat.x = goat.x - 3;
}
if (goat.x < -9)
{
goat.x = 1600;
goat.y = 150;
goat.x = goat.x - 4;
}
}
You should shift all the checks in onenter upwards, prior to assigning anything to either sheep or other objects. Then you will likely find that one of the objects is null. The #1009 error means that some object reference that's placed right before a "." qualifier is null, and you can't get properties out of nothing.
Also, try placing return right after any call of nextFrame(), because when you perform nextframe, the previous frame's vars are invalidated, thus you can't refer to say hand because there's no more hand, it's destroyed along with the whole previous frame.

AS3 | Devide to float number

Is there any way to devide by 10 and to check if the result is a float number?
My vars is:
var X:int=40;
var Y:Number=0;
//I want to Y get 4,
//but when X is 45, Y get 0
if( X%10 == 0 )
Y = X/10;
else
Y = 0;
Try this:
var X:int = 45;
var Y:Number = (X / 10).toString().indexOf(".") == -1 ? X / 10 : 0;
Longer form:
var X:int = 45;
var Y:Number = 0;
var Z:String = (X / 10).toString();
if (Z.indexOf(".") == -1) {
Y = X / 10;
} else {
Y = 0;
}