circlecube

RSS comments
LinkedIn Twitter delicious fb last.fm

Posts Tagged ‘experiment’

This deals with some issues I’m having with the seekbar of a player. The seekbar is the area that displays the video time as a bar that shows your current position/percentage of the video, it can also display the loaded portion of the video among other things as well. Including the video players I’ve made, most player code seems to use bytesLoded / bytesTotal to calculate the amount loaded and display in the loadbar (or whatever you call it), this load bar relates to the filesize as it reads the bytes loaded out of the total. In this same scrub bar area, I like to display the current video time in the playbar as the currentTime / totalTime, notice that this relates to the time and not the file size.
seekbars
Since video is usually a variable bit rate, the loadbar (size) and the playbar (time) are not representing the same data of the video. Let’s consider an extreme example case video that consists of a first half containing live action with lots of colors and motion while the second half is a still image black and white slideshow. Understandably the first half of the video will be larger in file size than the second half, even though they each represent the same duration or half of a video… So the first half of the loadbar (size) would not correctly represent the first half of the playbar (time). So the user who watching the video load to the half point, and scrubbing to halfway through the video by clicking the load bar will see errors… The player will not be able to play the halfway (time) yet because that time is not yet loaded, even though the file is halfway loaded (size). So if we allow scrubbing through the video by clicking on the loadbar, there is a good chance that the user experience suffers because the loadbar (size) and playbar (time) are not interchangeable
Calculating display bar actionscript code:

1
2
3
4
//bar is display bar mc
//bar.bg.width is used as a constant to scale the percentage to the full bar width
bar.sizebar.width = (ns.bytesLoaded / ns.bytesTotal) * bar.bg.width;
bar.timebar.width = (ns.time / duration) * bar.bg.width;

Scrub on click actionscript code:

1
2
3
//calculate from percentage of bar width to time for seeking to
jumpSeekTo = (bar.mouseX / bar.bg.width) * duration;
ns.seek(jumpSeekTo);

A possible simple solution I’ve thought of is to just display a loading graphic if they click a time which has not yet loaded, but that seems counter intuitive and backwards, since the load bar would display that time as having being loaded.

I have not seen anything in documentation or anywhere online that suggests any other way to display the amount loaded which would represent the amount of TIME loaded rather than SIZE. Is there a way to know what time has loaded in the video and display that in the loadbar rather than display the percent of kb loaded?

Can anyone see something I am missing?

P.S. I already tried a couple forums to no avail: Actionscript.org forum post and gotoandlearn forum post.

  • del.icio.us
  • Digg
  • email
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Mixx
  • Print
  • PDF
  • StumbleUpon
  • Technorati
  • Twitter
  • RSS
1 May 2009

Flash Video Issue: loadbar (size) vs playbar (time) usability

Author: Evan Mullins | Filed under: other, review

fullscreen_tut png
One of the best features of the flash player if you’re doing video is the fullscreen functionality. It has been a question I’ve heard repeatedly. There are limits to what you can do in fullscreen. Such as minimal keyboard support while in fullscreen. But it is perfect for a video player! Who doesn’t want to see a video expanded to full screen mode?

There are a couple things to consider when coding fullscreen into your flash. Remember the hard coded “Press Esc to exit full screen mode.” that Adobe has placed into the flash player. This is untouchable by developers, and the function returns to normal stage display state. So we call the function to go fullscreen, but the exit fullscreen has already been written for us. This can pose a problem though, when we need the player to do something when we exit fullscreen, that is when we want it to do something more than the generic black box function adobe includes.

Steps

  1. specify stage properties
  2. full screen button and listeners
  3. stage fullscreenEvent listener
  4. (functions for each)
  5. allowfullscreen = true

Example

Get Adobe Flash player

1. Stage properties exist that allow us to specify what type of fullscreen we want.  We can have the swf scale to fit the fullscreen area (StageScaleMode.SHOW_ALL), not scale at all (StageScaleMode.NO_SCALE), skew to fit fullscreen (StageScaleMode.EXACT_FIT), and scale to fill fullscreen area (Stage.ScaleMode.NO_BORDER).  We may also edit the alignment of the stage in the fullscreen area; in this example I’m using TOP, but refer to documentation for more options

2. Adobe has placed restrictions on when a swf can enter fullscreen, and has deemed that it must result from a user interaction, a mouse click or keystroke. So create your buttons (or keyListeners). I prefer to have one button to enter fullscreen and another to exit, and have them both call the same function to toggle fullscreen. It gives a clearer communication to the user. I then control the visibility of these buttons depending on the current display state of the stage.

3. Another listener to watch the stage dispaly state. stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreenChange); This will fire every time the stage display state changes. We need this because as I mentioned earlier, when entering fullscreen we use our own function, but the ‘hit esc to exit fullscreen’ functionality is built into the flash player, we can’t update our stage layout or button visibility without watching to catch when the display state is changed. Using this method we can update our stage layout any and every time.

4. Of course flesh out the fullscreenToggle function to include anything else you need.

5. Lastly, for a SWF file embedded in an HTML page, the HTML code to embed Flash Player must include a ‘param’ tag and ‘embed’ attribute with the name ‘allowFullScreen’ and value ‘true’, like this:

<object>
    ...
    <param name="allowFullScreen" value="true" />
    <embed ... allowfullscreen="true" />
</object>

The allowFullScreen tag enables full-screen mode in the player. If you do everything else right and don’t include this in your embed codes, fullscreen will not work. The default value is false if this attribute is omitted. Note the viewer must at least have Flash Player version 9,0,28,0 installed to use full-screen mode. Also note that  the simple (ctrl + enter) testing your movie in flash will not allow fullscreen either, you must use the debug tester (ctrl + shift + enter) … or go open the published swf in flash player.

Actionscript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
stage.scaleMode = StageScaleMode.SHOW_ALL;
stage.align = StageAlign.TOP;

var stageDisplayAdjustCounter:uint = 0;

fsb.addEventListener(MouseEvent.CLICK, fullscreenToggle);
ssb.addEventListener(MouseEvent.CLICK, fullscreenToggle);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreenChange);

fsb.buttonMode = true;
ssb.buttonMode = true;

//fullscreen buttons need this to adjust the stage display state.
//pressing escape to exit fullscreen bypasses this function
function fullscreenToggle(e:MouseEvent = null):void {
status.appendText(stageDisplayAdjustCounter+". fullscreenToggle from "+stage.displayState+"\n");
//normal mode, enter fullscreen mode
if (stage.displayState == StageDisplayState.NORMAL){
//set stage display state
stage.displayState = StageDisplayState.FULL_SCREEN;
}
//fullscreen mode, enter normal mode
else if (stage.displayState == StageDisplayState.FULL_SCREEN){
//set stage display state
stage.displayState = StageDisplayState.NORMAL;
}
//here we subtract 1 from the counter because it has already incremented (in onFullscreenChange) when we set the display state above

status.appendText((stageDisplayAdjustCounter-1)+". fullscreenToggle to "+stage.displayState+"\n");
status.scrollV = status.maxScrollV;

}

//this function is called every and anytime the stage display state is adjusted
//either by pressing our buttons or
function onFullscreenChange(e:FullScreenEvent = null):void {
status.appendText(stageDisplayAdjustCounter+". onFullscreenChange\n");
status.scrollV = status.maxScrollV;
if (stage.displayState == StageDisplayState.FULL_SCREEN) {
fsb.visible = false;
ssb.visible = true;
}
else {
fsb.visible = true;
ssb.visible = false;
}

stageDisplayAdjustCounter++;
}

onFullscreenChange();

Source

Download fullscreen_tut.fla file

  • del.icio.us
  • Digg
  • email
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Mixx
  • Print
  • PDF
  • StumbleUpon
  • Technorati
  • Twitter
  • RSS
23 Mar 2009

How to use fullscreen in AS3 | Stage Display State Tutorial

Author: Evan Mullins | Filed under: tutorial

If you didn’t know, Grant Skinner has introduced an interesting competition called tweetcoding!

Mixing as3 with the 140 character limit of tweeting he calls for the community to tweet visually interesting source code.

I’ve played a bit with it and tweeted my first #tweetcoding entry! See more tweetcoding here

1
g.clear(),o[++i]={x:mouseX,y:mouseY,c:r()*0xFFFFFF};for each(k in o)k.c*=.9,g.beginFill(k.c),ls(i,k.c),g.drawCircle(k.x,k.y,1),g.endFill();

Want to see my entry? Here it is!

tweetcode_circlecube_a png

  • del.icio.us
  • Digg
  • email
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Mixx
  • Print
  • PDF
  • StumbleUpon
  • Technorati
  • Twitter
  • RSS
27 Feb 2009

#tweetcoding

Author: Evan Mullins | Filed under: portfolio

I have had feedback that certain random movements I program are a bit “jumpy”. Such as my old brownian movement tutorial and I really noticed it in my last tutorial, the parallax 3d depth effect tutorial. I’ve been thinking about it and looking around at some code and now have this updated brownian movement example! Updated for as3 as well as making it less jumpy.

as3brownian thumb pngFirst I’ll explain what I’ve found to be the reason of the jumpiness. And then explain and show what can be done to make this movement be more smooth.

So to examine the old jumpy code. Jump back to the first version post here. I think my technique was well thought out here, but the application was poor. It was recalculating the velocities every single frame and then incrementing the coordinate positions by the newly calculated velocities… This is where the jumpiness comes in. Even though the random value was named velocity, it didn’t actually affect the dot’s velocity, it was just a variable that stored the random value used to move the current x/y coordinates.
To help the animation be more smooth, the velocity needs to be more smooth. The velocity, rather than calculating it fresh each frame, should be randomly modified each frame. And then the new velocity will calculate the new ‘random’ position. Another addition is to introduce another force to dampen the velocity over time, so things don’t get too crazy…

Steps:

  1. Modify velocity randomly
  2. With velocity and current position, calculate a new position
  3. Dampen the velocity

Example:

Here I have a velocity for the x coordinate as well as the y. I’m also experimenting with a z velocity. This adjusts the alpha and scale for depth perception. It doesn’t actually edit the depth or layer the dot shows up on the stage however… keyword here: experimenting. :)

Get Adobe Flash player

Actionscript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//number of balls
var numBalls:uint = 50;
var defaultBallSize:uint = 30;

//init
makeDots();

function makeDots():void {
    //create desired number of balls
    for (var ballNum:uint=0; ballNum<numBalls; ballNum++){
        var c1:Number = randomColor();
        var c2:Number = randomColor();
       
        //create ball
        var thisBall:MovieClip = new MovieClip();
        thisBall.graphics.beginFill(c1, .9);
        thisBall.graphics.lineStyle(defaultBallSize/3, c2, .9);
        thisBall.graphics.drawCircle(defaultBallSize, defaultBallSize, defaultBallSize);
        thisBall.graphics.endFill();
       
        addChild(thisBall);
       
        //coordinates
        thisBall.x = Math.random() * stage.stageWidth;
        thisBall.y = Math.random() * stage.stageHeight;
        //percieved depth
        thisBall.ballNum = ballNum;
        thisBall.depth = ballNum/numBalls;
        thisBall.scaleY = thisBall.scaleX = thisBall.alpha = ballNum/numBalls;
        //velocity
        thisBall.vx = 0;
        thisBall.vy = 0;
        thisBall.vz = 0;
       
        //ball animation
        thisBall.addEventListener(Event.ENTER_FRAME, animateBall);
    }
}

var dampen:Number = 0.95;
var maxScale:Number = 1.3;
var minScale:Number = .3;
var maxAlpha:Number = 1.3;
var minAlpha:Number = .3;
function animateBall(e:Event):void{
    var thisBall:Object = e.target;
    //apply randomness to velocity
    thisBall.vx += Math.random() * 0.2 - 0.1;
    thisBall.vy += Math.random() * 0.2 - 0.1;
    thisBall.vz += Math.random() * 0.002 - 0.001;
   
    thisBall.x += thisBall.vx;
    thisBall.y += thisBall.vy;
    thisBall.scaleX = thisBall.scaleY += thisBall.vz;
    thisBall.alpha += thisBall.vz;
    thisBall.vx *= dampen;
    thisBall.vy *= dampen;
    thisBall.vz *= dampen;
   
    if(thisBall.x > stage.stageWidth) {
        thisBall.x = 0 - thisBall.width;
    }
    else if(thisBall.x < 0 - thisBall.width) {
        thisBall.x = stage.stageWidth;
    }
    if(thisBall.y > stage.stageHeight) {
        thisBall.y = 0 - thisBall.height;
    }
    else if(thisBall.y < 0 - thisBall.height) {
        thisBall.y = stage.stageHeight;
    }
   
    if (thisBall.scaleX > maxScale){
        thisBall.scaleX = thisBall.scaleY = maxScale;
    }
    else if (thisBall.scaleX < minScale){
        thisBall.scaleX = thisBall.scaleY = minScale;
    }
    if (thisBall.alpha > maxAlpha){
        thisBall.alpha = maxAlpha;
    }
    else if (thisBall.alpha < minAlpha){
        thisBall.alpha = minAlpha;
    }
}

function randomColor():Number{
    return Math.floor(Math.random() * 16777215);
}

Source:

as3random_brownian_movement.fla

  • del.icio.us
  • Digg
  • email
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Mixx
  • Print
  • PDF
  • StumbleUpon
  • Technorati
  • Twitter
  • RSS
10 Feb 2009

Random Movement | Brownian revisited for as3

Author: Evan Mullins | Filed under: tutorial

parallax_thumbI’ve had quite a few questions about how to make depth in flash. Earlier (like, 2 years ago) I put up an experiment file to give some interactive depth to some sketchbook sketches, see Floating Sketches. I’ve finally gotten around to translating that into as3. It’s still the same basic idea, Create layers of levels, and have each one respond to the mouse a little differently. The ‘closer’ depths will move faster while the farther away depths will be slower. A simple technique called Parallax.

  1. Seperate the scene into layers
  2. Place the layers in the correct depth
  3. Make closer layers react fast and farther layers slower

Example

Get Adobe Flash player

parallax_thumb

Actionscript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//define number of layer.
var numLayers:uint = 15;
//number of items in a layer
var numBallsPerLayer:uint = 100;
var defaultBallSize:uint = 25;

var stageWidth3d:uint = 800;
var stageHeight3d:uint = 800;

var layers:Array = new Array();
//init
makeMatrix();
//3d created by layers and placing objects on each layer - the layer has it's own distance, simulated by movement and alpha

function makeMatrix():void {
    //walk through desired number of layers
    for (var layerNum:uint=0; layerNum<numLayers; layerNum++){
        //make layer object to add balls to
        var thisLayer:MovieClip = new MovieClip();
        addChild(thisLayer);
        layers.push(thisLayer);
        //create desired number of balls per layer
        for (var ballNum:uint=0; ballNum<numBallsPerLayer; ballNum++){
            //trace("layer: "+layerNum +"; ball: "+ballNum);
            var c1:Number = randomColor();
            var c2:Number = randomColor();
           
            //create ball
            var thisBall:MovieClip = new MovieClip();
            thisBall.graphics.beginFill(c1, .9);
            thisBall.graphics.lineStyle(defaultBallSize/3, c2, .9);
            thisBall.graphics.drawCircle(defaultBallSize, defaultBallSize, defaultBallSize);
            thisBall.graphics.endFill();
           
            //apply filter to ball
            var myGradientGlowFilter = new GradientGlowFilter(0,
                                                  0,
                                                  [c1, c2, c1],
                                                  [0, .9, 1],
                                                  [0, 63, 255],
                                                  20,
                                                  20,
                                                  .9,
                                                  BitmapFilterQuality.HIGH,
                                                  BitmapFilterType.OUTER,
                                                  false);
            var myBlurFilter = new BlurFilter((numLayers-layerNum)/numLayers*5, (numLayers-layerNum)/numLayers*5, 1);
            var filtersArray:Array = new Array(myGradientGlowFilter, myBlurFilter);
            thisBall.filters = filtersArray;
           
            thisLayer.addChild(thisBall);

            //coordinates
            thisBall.x = Math.random() * stageWidth3d * layerNum;
            thisBall.y = Math.random() * stageHeight3d * layerNum;
            //size
            thisBall.scaleY = thisBall.scaleX = layerNum/numLayers * (Math.random() + 1);
           
            //ball animation
            thisBall.layer = layerNum;
            thisBall.addEventListener(Event.ENTER_FRAME, animateBall);
        }
       
        //layer depth/alpha
        thisLayer.alpha = layerNum/numLayers;
       
    }
    //listeners to animate from mouse movement
    addEventListener(Event.ENTER_FRAME, positionLayer);

}

var easingStrength:Number = 10;

function positionLayer(e:Event):void{
    for (var layerNum:uint=0; layerNum<numLayers; layerNum++){
        //move layers according to mouse poosition
        var xv:Number = (stage.stageWidth-layers[layerNum].width)/stage.stageWidth;
        layers[layerNum].x -= (layers[layerNum].x - xv * mouseX) / easingStrength;
        var yv:Number = (stage.stageHeight-layers[layerNum].height)/stage.stageHeight;
        layers[layerNum].y -= (layers[layerNum].y - yv * mouseY) / easingStrength;
    }
}

function animateBall(e:Event):void{
    e.target.x += (Math.random() - .5) * 2 * e.target.layer/numLayers;
    e.target.y += (Math.random() - .5) * 2 * e.target.layer/numLayers;
}

function randomColor():Number{
    return Math.floor(Math.random() * 16777215);
}

Source

depth.fla

  • del.icio.us
  • Digg
  • email
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Mixx
  • Print
  • PDF
  • StumbleUpon
  • Technorati
  • Twitter
  • RSS
30 Jan 2009

Dynamic 3d space | Floating Sketches Tutorial

Author: Evan Mullins | Filed under: tutorial