For e.g.
function showIt():void {
something.visible = true;
}
function init():void {
time1 = flash.utils.getTimer();
showIt();
time2 = flash.utils.getTimer();
}
<mx:st id="something" visible="false"/>
<mx:Button click="init()"/>
In the above code, I want to measure the time taken to display st on screen.
Is it enough to compute time2 - time1?
Or should I put an event handler on render?
Or some other way?
You should try out Grant Skinner's AS3 Performance Test Harness.
Here's a simple demo of it in action (from his blog):
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
performancetests.GraphicsTests (5 iterations)
Testing different approaches for drawing.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
tare [3] 2 0.40
drawPath 242 48.40
drawPathShort 171 34.20
fullPath 182 36.40
reference 127 25.40
shortReference 129 25.80
withGraphics 1154 230.80
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
In the download he has a class called "RenderTest.as", which he describes with:
Represents a render test, which times how long it takes to draw a specified DisplayObject to a BitmapData instance.
I use it all the time, it's great.
Hope that helps,
Lance
you can draw it into a BitmapData to force rendering and measure the time required.
greetz
back2dos
Using the Profiler will probably be more interesting to compare such operations.
time2 - time1 will just give you the time required to set the visible property of the UIComponent to true - which might be just a couple of lines of code. The real rendering happens at regular intervals when the UIComponent fires enterFrame event. I don't know of any method to measure the time taken to render one particular component, and I don't think you can do that.
One idea that comes to mind is to listen for ENTER_FRAME and calculate the time difference between two consecutive events (or even better: take average over, say, 100 frames) to get an estimate of the time taken for rendering the whole stage. Now repeat the experiment after removing the particular component from stage. The difference between the two timings will give you an idea of the time taken to render your component.
Related
I would like to display a table which have several thousand rows with complex formatting (color, font, border, etc. done on the ASP.Net Core server).
Initially, I generated an html copy of all the data (stored in a SQL Server database), but realised it wasn't optimal since the generated html data accounted for more than 50MB.
No, I only generate about 200 rows; 100 visible and 50 hidden above and below (cache). I would like to freely scroll the tablen, but when there are only 25 hidden rows above or below, fetch new rows from the controller which are then prepend or append to the table. Basically, I want to give enough room so I can can populate the table when I'm scrolling through the "hidden" (cache) rows.
Everything seems to work well, but I believe I need to use a web-worker to run the function in a background thread which add new rows to the table independently of the table being scrolled.
Below is a excerpt of the code :
I use a debunce function to only catch the lastest position of the mouse scroll.
The scroll function basically only checks whether there are enough hidden rows (cache) above or below the table. If it reaches the threshold, it either prepends (scroll upwards) or appends (scroll downwards) rows obtained from the controller.
The main issue is that I can't scroll the table when the new rows are being fetch as the page freezes. It only takes about 1 to 2 seconds to populate to new (scrollable) rows but it isn't smooth.
Could anyone help me improve the code? (general ideas) I also read that there are already existing libraries but can't really get my head around them..
$('#fields-table > tbody').on('wheel', _.debounce(async function (event) {
await scroll(); // Probably change it to a web-worker or promise?
}
async function scroll() {
var threshold = 200; // Corresponds to approximatively 50 rows (above and below).
var above = $('#fields-table').scrollTop();
var below = $('#fields-table > tbody').height() - $('#fields-table').height() - above;
// Gets the scroll delta based on the table heights.
var delta = 0
if (above < threshold) delta = above - threshold; // Scrolls upwards.
if (below < threshold) delta = threshold - below; // Scrolls downwards.
await addCacheRows(delta); // Prepends (delta < 0) or appends (delta > 0) or appends rows obtained via the fetch API.
}
Your problem is unlikely to resolve with a web worker. Without seeing more code I cannot tell for sure, but I suspect your code to generate new rows is not sufficiently efficient. Remember:
Use DocumentFragment to create the HTML, do not immediately append it to the main DOM tree row by row. Appending elements to a document triggers some recalculations.
Unless this is a LOT of data or requires lots of work serverside, you can immediately start preloading next/previous rows. Keep the promise object and only await it once you need them, that's the simplest way to go around it
Use passive scroll event listener - Firefox even shows a console warning whenever you do not do that
There is no way generating 200 rows of table data should take seconds. Since you use JQuery anyway (really, in 2022?), note that there are plugins for this. I don't remember what I used, but it worked perfect and scrolled smooth with much more data than what you have.
Thank you for your help. I realise it won't be as straightforward as I initally thought (I made some tests with WPF virtualization as well).
Regarding the time it takes to generate the extra rows, I believe it mostly comes from the server. Sure, I can probably load new rows independently of the threshold.
I've never heard about DocumentFragment, but that something I should definitely consider.
I need an algorithm to tell a sprite to end as soon as the text finishes appearing, basically I need to make a cutscene which describes the beginning of a story within the game, but since I'm using gamemaker, I don't know how to do it, can someone help me?
For cutscenes and automated image sequences you usually have some sort of variables, that handle the states and counters for displaying sprite's sub-images.
But firstly I like to use mainly two main time-related variables in my controller object usually named sys (counter and counterTime):
c = 0; // and for stepEvent: c += 1; // so it goes +1 per step
ct = 0; // and for stepEvent: ct+= 1 / room_speed; // so it goes +1 per second
During the cutscene you might want to stop everything else that moves:
is_cutscene = false; // objects might not be able to move when this is true
// you still have to implement that by yourself
// player can't move if is_cutscene, nothing happens!!
(except cutscene buttons etc...)
So now when the player gets to a 'cutscene'y object and triggers some cutscene_1 = true eg. you can have the image/text/sound/animation object come to life/create/active... That object might have in the create event:
duration = 6; // 6 seconds the scene lasts
start_time = sys.ct // and in Step: if sys.ct > (start_time + duration)
// then -> cutscene advance/destroy
Ofcourse - this is super simple and now you could only say implement:
walk close to a pop-up object
show an image for 6 seconds
it dissappears
And it might not be big trouble to implement it... BUT THIS may also be the foundation for more advanced multi-step sequence and cuts.
THE GOAL I WANT TO ACHEIVE:
Control AE timelines using ONE EXPRESSION LAYER (much like using Actionscript) to trigger frequently used comps such as blinking, walking, flying etc... for cartoon animation.
I want animate a the blinking of a cartoon character. (and other actions, explained below) Rather than "re posting" the comp or key frames movements every time I want a blink or a particular action, I want to create a script where I can trigger the Blink comp to play. Is this possible? (Sidenote: A random blink through entire movie would be nice) but I still want to know how to do this for the reasons below.
Ideally: I would like to create an "Expressions layer" in the main comp to TRIGGER other comps to play. At certain points I would like to add triggers to call frequently used comps that contain actions like.. Blinking, Walking, Flying, Look Left and Right etc...
IT WOULD BE AMAZING IF somehow we could trigger other comps to begin, repeat, stop, maybe reverse, and do this all from one Main Comp using an expression layer.
WHY DO IT THIS WAY?
Why not just paste a comp in the spot you want it to play every time you want such action? Well in after effects if you wanted a "blink comp" to play 40 times in two minutes you would have to create 40 layers, or pate the key frames on that comp 40 times. Wouldn't it be awesome to trigger or call it from one one layer when you wanted it from one expressions layer?
We do something like this in Flash using Actionscript all the time. It would be awesome if there was a method out there to achieve this effect. This would be an OUTSTANDING tutorial and I believe it would be very popular if someone did it. It could be used for a MULTITUDE of amazing effects and could save a ton of time for everyone. Heck, help me figure this out and perhaps I will make a tutorial.
Thank you all ye "overflowing Stackers" who contribute! :)
I found the answer and that is...
IT'S NOT POSSIBLE.
After Effects expressions can not control other timelines. Unfortunately you have to put an expression on each layer you want to affect.
The next best solution, and to achieve something close to what I was asking can be found on this link: motionscript.com/design-guide/marker-sync.html
We can only hope that Adobe will someday give the power to expressions like they did with action-script.
HOPEFULLY SOON! Anyone reading this who works for Adobe please plead our case. Thanks
Part 1: Reference other layers in pre-Comps
Simply replace "thisComp" with "comp("ComName")"
To reference Effect-Controllers between compositions, follow the below formula:
comp("ComName").layer("LayerWithExpression").effect("EffectControlerName")("EffectControllerType")
More In-depth Answer: Adobe's Docs - Skip to the Layer Sub-objects part
As I understand the Adobe documentation, only Layers can be accessed,
not footage. What this means is that you will need to create your
expression link utilizing a pre-Comp. Footage can not access this so
that also means no nulls, adjustment layers, etc.
As an added bonus, if you use the essential graphics panel, you can put all the controllers in one pre-comp, but have the controls available no matter which comp you are in. Just select it in the Essential-Graphics dropdown.
Part 2: Start/End based on other layers within pre-comps:
Regarding the next part where you want the expressions to activate based on other compositions, I recommend using the in-out Point expression.
inPoint | Return type: Number. Returns the In point of the layer, in seconds.
outPoint | Return type: Number. Returns the Out point of the layer, in seconds.
If you utilize the start time overrides you can pull this from:
startTime | Return type: Number. Returns the start time of the layer, in seconds.
Alternate Option:
I would recommend avoiding this as the keyframes are basically referenced as an index, so things can get messed up if you add one ahead of a keyframe you were already using - def incorporate some error handling.
Refer to the Key attributes and methods (expression reference) Here
Part 3: Interpolation & Time Reversal
You can time reverse the layer in the rightclick->time, otherwise this is all interpolation expressions like loop out etc - you can loopOut("FOO") a pre-comp if you not only cut it correctly, but also enable time remapping.
then use this to loop those keyframes;
try{ timeStart = thisProperty.key(1).time; duration = thisProperty.key(thisProperty.numKeys).time-timeStart; pingPong =
false; //change to true value if you want to loop animationn back &
forth quant=Math.floor((time-timeStart)/duration);
if(quant<0) quant = 0
if(quant%2 == 1 && pingPong == true){
t = 2*timeStart+ (quant+1)*duration - time;
}
else{
t = time-quant*duration;
}
}
catch(err){
t = time;
}
thisProperty.valueAtTime(t)
guys!
I'm developing an online auction with time limit.
The ending time period is only for one opened auction.
After logging into the site I show the time left for the open auction. The time is calculated in this way:
EndDateTime = Date and Time of end of auction;
DateTime.Now() = current Date and Time
timeLeft= (EndDateTime - DateTime.Now()).Seconds().
In javascript, I update the time left by:
timeLeft=timeLeft-1
The problem is that when I login from different browsers at the same time the browsers show a different count down.
Help me, please!
I guess there will always be differences of a few seconds because of the server processing time and the time needed to download the page.
The best way would be to actually send the end time to the browser and calculate the time remaining in javascript. That way the times should be the same (on the same machine of course).
Roman,
I had a little look at eBay (they know a thing or two about this stuff :)) and noticed that once the item is inside the last 90 seconds, a GET request gets fired every 2 seconds to update the variables in the javascript via a json response. you can look at this inside firebug/fiddler to see what it does.
here is an example of the json it pulls down:
{
"ViewItemLiteResponse":{
"Item":[
{
"IsRefreshPage":false,
"ViewerItemRelation":"NONE",
"EndDate":{
"Time":"12:38:48 BST",
"Date":"01 Oct, 2010"
},
"LastModifiedDate":1285932821000,
"CurrentPrice":{
"CleanAmount":"23.00",
"Amount":23,
"MoneyStandard":"£23.00",
"CurrencyCode":"GBP"
},
"IsEnded":false,
"AccessedDate":1285933031000,
"BidCount":4,
"MinimumToBid":{
"CleanAmount":"24.00",
"Amount":24,
"MoneyStandard":"£24.00",
"CurrencyCode":"GBP"
},
"TimeLeft":{
"SecondsLeft":37,
"MinutesLeft":1,
"HoursLeft":0,
"DaysLeft":0
},
"Id":160485015499,
"IsFinalized":false,
"ViewerItemRelationId":0,
"IsAutoRefreshEnabled":true
}
]
}
}
You could do something similar inside your code.
[edit] - on further looking at the eBay code, altho it only runs the intensive GET requests in the last 90 seconds, the same json as above is added when the page is initially loaded as well. Then, at 3 mins or so, the GET request is run every 10 seconds. therefore i assume the same javascript is run against that structure whether it be >90 seconds or not.
This may be a problem with javascript loading at different speeds,
or the setInterval will trigger at slightly different times depending on the loop
i would look into those two
Problem:
I am using Peter Blum's Professional validation controls (http://www.peterblum.com/DES/MoreValidators.aspx) throughout my project and have come across a validation that should be done on the client side rather than going back to the server. The screen needs to send two dates(month/year) to the server, one for start date and one for end date. The dates are only month/year using Peter's MonthYearTextBox (http://www.peterblum.com/DES/DemoMoreDAT.aspx#MYTB). The two dates must not be more than 3 months apart (please note I did not say 90 days apart).
Here is the end goal:
A user comes to the screen to run a report. They are prompted for a start date (Month/Year) and an end date. These dates get sent to the server so that the report can be generated for the items within this date range. The user can only run this report for any 3 month period.
What I've Done:
I started off by using the DifferenceValidator from Peter's Validation And More package. In doing so, I set the difference that I expected to be 90 days, however soon realized that 7/2009 - 10/2009 is a 3 month difference (which is allowed) however it is a 92 day difference (which is outside the validator's range).
Question:
Is there any way that I can override the evaluation function in a client side function so that I may compare the month portion of the dates that are being evaluated?
Thank you,
Scott Blue
Yes there is. Here's a Javascript example:
function ValidateDateRange(cond)
{
var p = DES_GetById(cond.IDToEval).value; // Get the value of the control you're evaluating
if (p == undefined || p.length == 0) return 1;
// Perform custom validation here
// return 1 if valid, or return 0 if invalid
}
And you have to specify CustomEvalFunctionName="ValidateDateRange" in order for this to work.
I believe the CustomEvalFunctionName is supported in all of the different Peter Blum Validation controls.