Actionscript 3

I have been now with this issue (well not an alternativa issue but of my own mind).

How to get the view in Alternativa3d resized without resizing the object. Actually the objects aren’t resized it is the field of view (fov) that modified when the width and the height of the view is setted.

There are a lot of explanations to read and really good indications, but not exactly the solution to my problem, although a really good tips. This post explains really good how fov works and wich relation you have to mantain with the distance to get the scale 1:1. It helps when you have an object at point (0,0,0) and a no moving camera. The formula is:

D / F = tan(FOV/2)

Where F (Focal length), D (is the half diagonal of the view), FOV (field of view).


(I am using the same image as in the forum post of Alternativa3d it really helped me a lot si I hope nobody gets offended by this….)

That means, to have the correct scale of the object the focal length would be the position of the camera z, having the viewing object in position (0,0,0). So the adjustment to the camera when the view gets resized should be:

FOV = 2 * arctan(D/ F)


private function setFieldOfView():void{

var halfDiag:Number = Math.sqrt(view.width * view.width + view.height * view.height) / 2;

var dist:Number = Math.abs(camera.z);

camera.fov = 2 * Math.atan2( halfDiag, dist);


And that should always be setted when the view is resized. This works fine until you have scene where you move around with the camera. With this if you move the camera the relation to the objects scale is correct, until the view is resized. That is because this function is forcing the field of view, to see the object in scale 1:1. So, although you have moved the camera and the user would expect to see the object bigger/smaller it is in almost the same size.

Realized this the first thing that came in mi mind is that I should be changing not the fov but the focal length of the camera, well Alternativa doesn’t give this option.

So, when you change a camera’s FOV or view’s dimensions, the focal length is recalculated to match the previous expression

And of course changing z position of the camera to accomplish the 1:1 was not an option because I wanted to have the camera traveling around the scene. So there had to be something I didn’t really understand…

Due to focal length’s change objects on a screen change their scale accordingly. So, all you have to do to prevent objects’ scale changing is to keep value of the expression D / tan(FOV/2) constant, i.e. when you change FOV, adjust view size and vice versa.

How could I mantain the focal length constant in relation to the FOV and the view size if I couldn’t change the focal length of the camera? For me the focal length was kind of a distance between the object the camera was looking at and the camera. And actually it is in kind of a way. Although it is a relation not a fisical distance. So the post already said it Mantain the value of the expression D / tan(FOV/2) constant in other words mantain the focal length constant. So know I just put a constant as focal length:

private function setFocalLength() : void {
var halfDiagonal:Number = Math.sqrt(view.width * view.width + view.height * view.height) / 2;
camera.fov =2 * Math.atan2(halfDiagonal,FOCAL_LENGTH_1_1);

So, the position of the camera in front of each object, to see the object in scale 1:1 should be in a distance from it of FOCAL_LENGTH_1_1.

This project was about recording a few seconds of work and reproducing it. We decided to do that with Red5
Streaming (biggest reason was that it is for free…). A few hours before the final final final (but this is the most final) deadline we saw that we could not have two flashplayers opened streaming voice at once. Debugging we found the Netstream.Publish.BadName that caused that nothing could be recorded, a silent killer!!!
Reading about Netstream publish at livedocs:

“Don’t use this method to let a client play a stream that has already been published and recorded”

ok and what should I do?? reading a few lines below:

“When you record a stream using Flash Media Server, the server creates a file and stores it in a subdirectory in the application’s directory on the server. Each stream is stored in a directory whose name matches the application instance name passed to NetConnection.connect(). The server creates these directories automatically; you don’t have to create one for each application instance. For example, the following code shows how you would connect to a specific instance of an application stored in a directory named lectureSeries in your application’s directory. A file named lecture.flv is stored in a subdirectory named /yourAppsFolder/lectureSeries/streams/Monday: “

Ok then, the solution to the problem was not in the netstream, it was at the netconnection! That ment we had to connect to the red5 server but forcing it to record to a unique folder so that each publishing of the netstream pointent to a unique “publishing name”. For that we decitedt to create a folder with the getTimer();

_randomFolder = String(getTimer());
randomFolder, true);

works perfectly the only disadvantage is that on the server there are a lot of created folders….

At work with already a few days deadlining….. The artdirector comes and says… just a little bug….
“When you upload the foto and you resize… see?? The photo seems to be sticking at its position”

HUhh!!?? The mask was not able to move with its container when it was repositioned by resizing.

The mask was not applied as it before the round trip with the server. (User uploads photo and flash loads it in again). So the mask was a decorative overlay before, and just at the moment where the bitmap was received the mask was set as actually mask. The problem was that the mask had applied a Filter (concretely a DropShadowFilter, not sure if that made any difference) but somehow this filter blocked the repositioning of it. So just pulling the filters off before setting the bitmap was enough!

No need to tell how stupid I felt……. 🙂