speed for Player vs Browser

  • ihtus
  • Born
  • Born
  • ihtus
  • Posts: 4

Post 3+ Months Ago

Hallo
I am using getTimer() function, and when I "ctrl+enter" - player works fine!
But when i open swf file through any browser, or just hit "ctrl+f12" - the aplication works much more slower
This happenes for flash 8, and MX

example - http://ihtus.xmgfree.com/pendulum.swf
but if i run it through player - it works faster, i mean it must work as in player

You can download the SWF and see the difference

any ideas?
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

works fine for me , do u have a another example , i dont have anything to compare it with though ...

Prolly Yer cpu cant afford the calculation , depending on how u wrote your code ...

Ice , Ny idea ?
  • ihtus
  • Born
  • Born
  • ihtus
  • Posts: 4

Post 3+ Months Ago

classified:

i have two cases of code:

1.
Code: [ Select ]
function f1 (y,z)
{
    return -9.8/1.5*Math.sin(y) ;
}
function f2(y,z)
{
    return z;
}

import flash.display.BitmapData;

var myBitmapData:BitmapData = new BitmapData(640, 480, true, 0xCCFFFFFF);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

var t=0, h=0.01, y=0.8*Math.PI, z=0, i=0;
var k11=0, k12=0; k13=0, k14=0, k21=0, k22=0, k23=0, k24=0;

//BUTTON

on (release) {
    presstime=getTimer();

_root.onEnterFrame=function() {
    time=getTimer()-presstime;
    
k11=h*f1(y,z);
k12=h*f1(y+h/2,z+k11/2);
k13=h*f1(y+h/2,z+k12/2);
k14=h*f1(y+h,z+k23);
z=z+(k11+2*k12+2*k13+k14)/6;

k21=h*f2(y,z);
k22=h*f2(y+h/2,z+k21/2);
k23=h*f2(y+h/2,z+k22/2);
k24=h*f2(y+h,z+k23);
y=y+(k21+2*k22+2*k23+k24)/6;


myBitmapData.setPixel(Math.round(y*50+200),time/500, 0x000000);

res1._rotation=90-180*y/Math.PI;
text1.text='fi= '+res1._rotation;

    }
}
  1. function f1 (y,z)
  2. {
  3.     return -9.8/1.5*Math.sin(y) ;
  4. }
  5. function f2(y,z)
  6. {
  7.     return z;
  8. }
  9. import flash.display.BitmapData;
  10. var myBitmapData:BitmapData = new BitmapData(640, 480, true, 0xCCFFFFFF);
  11. var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
  12. mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
  13. var t=0, h=0.01, y=0.8*Math.PI, z=0, i=0;
  14. var k11=0, k12=0; k13=0, k14=0, k21=0, k22=0, k23=0, k24=0;
  15. //BUTTON
  16. on (release) {
  17.     presstime=getTimer();
  18. _root.onEnterFrame=function() {
  19.     time=getTimer()-presstime;
  20.     
  21. k11=h*f1(y,z);
  22. k12=h*f1(y+h/2,z+k11/2);
  23. k13=h*f1(y+h/2,z+k12/2);
  24. k14=h*f1(y+h,z+k23);
  25. z=z+(k11+2*k12+2*k13+k14)/6;
  26. k21=h*f2(y,z);
  27. k22=h*f2(y+h/2,z+k21/2);
  28. k23=h*f2(y+h/2,z+k22/2);
  29. k24=h*f2(y+h,z+k23);
  30. y=y+(k21+2*k22+2*k23+k24)/6;
  31. myBitmapData.setPixel(Math.round(y*50+200),time/500, 0x000000);
  32. res1._rotation=90-180*y/Math.PI;
  33. text1.text='fi= '+res1._rotation;
  34.     }
  35. }

source code - http://ihtus.xmgfree.com/flash_sources/pendulum/1.fla
swf - http://ihtus.xmgfree.com/flash_sources/pendulum/1.swf

when i ctrl+enter it - works great!
but if I ctrl+f12 (or open swf through a broswer) - the pendulum oscilates slower!
WHY?

2.
Code: [ Select ]
function f1 (y,z)
{
    return -9.8/1.5*Math.sin(y) ;
}
function f2(y,z)
{
    return z;
}

import flash.display.BitmapData;

var myBitmapData:BitmapData = new BitmapData(640, 480, true, 0xCCFFFFFF);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

var t=0, h=0.01, y=0.8*Math.PI, z=0, i=0;
var k11=0, k12=0; k13=0, k14=0, k21=0, k22=0, k23=0, k24=0;

pendul=function() {
    time=getTimer()-presstime;
    
k11=h*f1(y,z);
k12=h*f1(y+h/2,z+k11/2);
k13=h*f1(y+h/2,z+k12/2);
k14=h*f1(y+h,z+k23);
z=z+(k11+2*k12+2*k13+k14)/6;

k21=h*f2(y,z);
k22=h*f2(y+h/2,z+k21/2);
k23=h*f2(y+h/2,z+k22/2);
k24=h*f2(y+h,z+k23);
y=y+(k21+2*k22+2*k23+k24)/6;


myBitmapData.setPixel(Math.round(y*50+200),time/500, 0x000000);

res1._rotation=90-180*y/Math.PI;
text1.text='time= '+time/1000;

    }

//BUTTON

on (release) {
    
        presstime=getTimer();
        
setInterval(pendul,1);

}
  1. function f1 (y,z)
  2. {
  3.     return -9.8/1.5*Math.sin(y) ;
  4. }
  5. function f2(y,z)
  6. {
  7.     return z;
  8. }
  9. import flash.display.BitmapData;
  10. var myBitmapData:BitmapData = new BitmapData(640, 480, true, 0xCCFFFFFF);
  11. var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
  12. mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
  13. var t=0, h=0.01, y=0.8*Math.PI, z=0, i=0;
  14. var k11=0, k12=0; k13=0, k14=0, k21=0, k22=0, k23=0, k24=0;
  15. pendul=function() {
  16.     time=getTimer()-presstime;
  17.     
  18. k11=h*f1(y,z);
  19. k12=h*f1(y+h/2,z+k11/2);
  20. k13=h*f1(y+h/2,z+k12/2);
  21. k14=h*f1(y+h,z+k23);
  22. z=z+(k11+2*k12+2*k13+k14)/6;
  23. k21=h*f2(y,z);
  24. k22=h*f2(y+h/2,z+k21/2);
  25. k23=h*f2(y+h/2,z+k22/2);
  26. k24=h*f2(y+h,z+k23);
  27. y=y+(k21+2*k22+2*k23+k24)/6;
  28. myBitmapData.setPixel(Math.round(y*50+200),time/500, 0x000000);
  29. res1._rotation=90-180*y/Math.PI;
  30. text1.text='time= '+time/1000;
  31.     }
  32. //BUTTON
  33. on (release) {
  34.     
  35.         presstime=getTimer();
  36.         
  37. setInterval(pendul,1);
  38. }

source code - http://ihtus.xmgfree.com/flash_sources/pendulum/2.fla
swf - http://ihtus.xmgfree.com/flash_sources/pendulum/2.swf

and the same problem:
when i ctrl+enter it - works great!
but if I ctrl+f12 (or open swf through a broswer) - the pendulum oscilates slower!
WHY?

So i realy need the application to work through broswer (player plugin) as it works in flashplayer!

Accidentely (for 2'nd code case) i hitted several times the button - and the pendulum started to oscilate faster and faster.
And I made some changes in button code
Code: [ Select ]
on (release) {
    
        presstime=getTimer();
        
setInterval(pendul,1);
setInterval(pendul,1);
setInterval(pendul,1);
setInterval(pendul,1);
}
  1. on (release) {
  2.     
  3.         presstime=getTimer();
  4.         
  5. setInterval(pendul,1);
  6. setInterval(pendul,1);
  7. setInterval(pendul,1);
  8. setInterval(pendul,1);
  9. }

I hit once and it oscilates faster then it did.

So my big questions are:
1) why can't broswer (ie, opera, firefox) just play the swf as flashplayer plays it?
2) why when i put multi setInterval functions - it began oscilates faster in the browser, and also in flashplayer - but here much more faster!
3) how can i make the speed of oscilations to be the same for browser player plugin, and for flashplayer?
Is multi setInterval functions - the only way to make broswer play the movie as it should be?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

uhmm, not sure why in browser works slower, but probably in this case there`s something related with the frame rate. If it's too high, then dont expect to work at that frame rate, and maybe cause of the browser, the actual framerate decrease even more. You can try to set the resolution to low, that will speed up a little the application.
and unfortunately i dont have 8 ball yet, so i cant help you with other tests.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.