I am an freelance animator in flash with very limited knowledge in AS3. I make animation videos in swf format and sell it for money. Most of the time, my clients give me a small script and ask for a sample based on the script without any watermark or logo embeded. I have to oblige in order to win the chance of getting the work. Most of the time, the client does not respond after they get the sample and I think that they are getting their work done for free.
I want to embed a script in AS3 in such a way that the video will play for only a pre-defined number of days( eg 3 days ) or till a particular date.
Please help
you have to put your animation in one MovieClip.
I named it 'animation', then set your expire date, I commented where to set
function getDaysBetweenDates(date1:Date, date2:Date) : int {
var oneDay:Number = 1000 * 60 * 60 * 24;
var date1Milliseconds:Number = date1.getTime();
var date2Milliseconds:Number = date2.getTime();
var differenceMilliseconds:Number = date1Milliseconds - date2Milliseconds;
return Math.round(differenceMilliseconds/oneDay);
}
var year : int = 2014; //here you put the year, month and the day when you want to expire
var month : int = 12;
var day : int = 28;
var daysRemaining = getDaysBetweenDates(new Date(year, month-1, day+1), new Date());
timeTXT.text = daysRemaining.toString(); //you can create dinamyc text and show to your client how much time he has befor the animation expire
if(daysRemaining <= 0) {
animation.visible = false; //here we make animation movieclip invisible if is expired
}
try it!
Hope this help!
Related
I'm trying to write a userscript for a friend. The Website I'm writing it for (app.patientaccess.com) tells you what doctors appointments you have, (among other things). However, in order to write my userscript, I need to know how the app handle appointments for the following year.
At the moment, the only way to know is to wait until the end of the year when my friend starts making appointments for the following year. Since it's an Angular app, I'd rather, if possible, point it to a fabricated JSON file of my creation when the app requests that particular data. In that file I can give it some data for this year and next year and then I can see what happens with appointments made for the following year.
I'm hoping this can be done with an addon for Chrome or Firefox or perhaps some kind of free/open source software.
Thanks in advance.
I came up with a function that will accurately guess there year, given the day name, date and month, if it's within a couple of years either side of the current year.
function calculateYear(dayName, dayOfMonth, monthNum, returnDateObj) {
monthNum -= 1;
maxIterations = 3;
var startYear = (new Date()).getFullYear();
var dateObj = new Date(startYear, monthNum, dayOfMonth);
for (var i = 0; i < maxIterations; i++) {
dateObj.setYear(startYear + (1 * i));
if (dayName == daysOfTheWeek[dateObj.getDay()]) {
return (returnDateObj) ? dateObj : dateObj.getFullYear();
}
dateObj.setYear(startYear - (i + 1));
if (dayName == daysOfTheWeek[dateObj.getDay()]) {
return (returnDateObj) ? dateObj : dateObj.getFullYear();
}
}
return 'No Match';
}
It works a treat, as you can see here.
I'm trying to make a countdown timer, where I could easily set the endDate variable in html...
I can send strings to AS3 with flashvars="endDate=123", but how do I make it to be date (for example christmas)? - I need it to be date because then in AS3 I have something like endDate - todayDate = timeRemaining
Just pass date to flash vars using formats specified here and parse that string in AS3 using Date.parse() method.
In this example you get a countdown in days to Xmas.
var dateFromFlashVar : String = "2013/12/25 15:30:20 GMT+0300";
trace( new Date( new Date( Date.parse( dateFromFlashVar ) ).time - new Date().time ).getDate().toString() );
to transfrom a unix_timestamp date to as3 Date, you can do:
// unixTimeStamp is in seconds so we multiply by 1000 because flash Date take miliseconds
var date:Date = new Date( unixTimeStamp*1000 );
to get back unix timestamp of a date you can do:
// divide by 1000 to get seconds instead of miliseconds
var timeStamp:int = date.time / 1000;
i hope this is what you where searching for
I made an invetory in AS3 which allows me to put items on slots in a closet, or in slots in the inventory. It completely works, but there is one problem.
In the game you are supposed to be able to buy new items and add them to the closet. I want this to be saved so that it is available the next time you play.
To do this, I want to save an Array to a SharedObject, then create the items dynamically from the array.
Right now I'm using the old fashioned hard coding for each object;
Itemwrench = new WrenchItem();
Itemwrench.x = par.toolCloset.kast_1.slotTC1.x + 400;
Itemwrench.y = par.toolCloset.kast_1.slotTC1.y + 245;
Itemwrench.gotoAndStop(2);
Itemwrench.name = "slotTC1";
Itemwrench.TC = 1;
NotinventoryParentTC.addChild(Itemwrench);
However, to add them dynamically I'd have to use getChildByName before it is added to the stage, which is not possible.
If possible could you show me how to do this correctly?
The information you need:
-The items are all stored in a closet with slots(Instances in the closet movieclip).
-The items need to get the name slotTC + the integer in a for loop.
-The name of the items change according to the slot number they are assigned when you take them out of the closet or put them back into the closet.
for(var i:int = 0; i < itemsInTC.length - itemsInTC.indexOf(e.currentTarget.name) - 1; i++)
{
nextSlotTC = "slotTC" + (itemsInTC.indexOf(e.currentTarget.name) +2 +i);
trace("Next Slot: " + nextSlotTC);
TempStrTC = "slotTC" + (itemsInTC.indexOf(e.currentTarget.name) +1 +i).toString();
trace("temp string: " + TempStrTC);
NotinventoryParentTC.getChildByName(nextSlotTC).x =
par.toolCloset.kast_1.getChildByName(TempStrTC).x + 400;
NotinventoryParentTC.getChildByName(nextSlotTC).y =
par.toolCloset.kast_1.getChildByName(TempStrTC).y + 245;
if(Boolean(NotinventoryParentTC.getChildByName(nextSlotTC)))
{
NotinventoryParentTC.getChildByName(nextSlotTC).name = TempStrTC;
}
}
This way I assign a new name and place them in the slot with the new name they received.
So now my question:
How do make it so that you can save the items to a shared object so that they are in the closet the next time you play the game.
Sorry for the long question.
Thanks in advance,
Milan.
You cannot directly store a DisplayObject in a SharedObject, as it contains memory links which will not be valid if you load such an object. A comon way to work around this is to store a significant data portion of that object. For example, you devise a following structure:
class SlotStructure {
public var slotID:int;
public var itemID:int;
public var itemName:String;
public var itemParameters:Array; // stuff simple types here
}
Then, for each of your items in inventory, you generate a SlotStructure object describing a particular inventory object. For your wrench it could look like this:
var ss:SlotStructure=new SlotStructure();
ss.slotID=1;
ss.itemID=getID(item); // assuming a function that returns a type of an item
ss.itemName=item.name;
ss.itemParameters=new Array();
for (var param:String in item) ss.itemParameters.push({name:param,value:item[param]});
Then you store an array of these into your SharedObject. To retrieve an inventory from a SharedObject you do:
public static const
registerClassAlias("SlotStructure",SlotStructure); // to be able to typecast from SO
for (var i:int=0;i<slots.length;i++) {
var ss:SlotStructure=slots[i];
var item:Item=new getClassFromID(ss.itemID)(); // a function that returns class
// say 1 - wrench, 2 - short sword, 3 - long sword, etc, one type=one ID
for each (var o:Object in ss.itemParameters)
item[o.name]=o.value;
placeIntoSlot(item,ss.slotID); // this does manipulation with x&y and display
}
A function getClassByID() might look like this:
private static const CLASSES:Array=
[StoneItem,WrenchItem,ShortswordItem,LongswordItem,...];
// manually stuff all your items in this!
public function getClassByID(id:int):Class {
return CLASSES[id];
}
The entire solution can be tailored to particular task, for example, in my game I have gems, that differ by location, type, size and score, so I store just these values and then I create new gems, set location, type, size and score with one function that sets all the other relevant parameters of that gem to align with stored info, and call it after making a gem with new Gem(). Your items might too be only worthy of a class name and ID in the class table, so store these with slot numbers and create objects that will have all their properties already set.
Perhaps a stupid question, but i really dont know the answer :(
lets say i have a date object, how can i change its AM date to PM, or vice verca?
Thanks
seems like you can
var currentTime = new Date();
var hours:uint = currentTime.getHours();
then you can say, if hours is greater than or equal to 12, then subtract by 12, otherwise, add 12 to it, for example, by
public static const millisecondsPerHour:int = 1000 * 60 * 60;
var reversedAMPM = new Date(currentTime.getTime() + (12 * millisecondsPerHour));
Although Jian's version should work, here's an alternative.
Assuming var date:Date is initialized, you may literally change it:
date.hours += (date.hours > 12) ? -12:12;
Is there any ActionScript class which represents "durations of time", similar to the TimeDelta class in Python?
Edit: Thanks for the responses. I should clarify a bit, though: I want be able to ask questions like "how many weeks are between date0 and date1" or "let x represent "one day". What is date2 + x?"
I know I can do all this by representing dates as timestamps... But I'm hoping to find something nicer.
I posted a full AS3 port of the .NET TimeSpan class on this question, which sounds exactly like what you need.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
You can use time() in the Date class to get unix era milliseconds and use that for time delta.
If you subtract two dates:
var dateDiff = date1 - date2;
dateDiff will hold the number of milliseconds between the two dates. You can then convert from milliseconds to whatever useful number you like.
I don't think there is a class which measures change in time in Actionscript 3. According to this blog post on Adventures in Actionscript, timing is very inaccurate in the Flash player on the web. That post is pretty informative and has a class called SuperTimer that might help you. You might want to keep this inaccuracy in mind if using solutions posed by Justin Niessner and toastie.