A few days ago, I used code to help my friends do something.
Because we haven't done flash coding for a long time. Therefore, we seldom care about the new flash 8
Calss. However, I have heard that this feature is available. I want to find a tutorial or code from the Internet
. However, it is found that there is no similar situation in China. You can only try your best.
Start:
Step 1: create a video component in the library. Select the video type (Subject
).
Step 2: drag the video element to the scene and resize it to the desired size. And named "my_video"
Step 3: paste the following content in the timeline
Code.
VaR my_video: video;
MySQL _ video. _ x = 100;
My_video. _ y = 40;
VaR my_cam: Camera = camera. Get ();
My_cam.setmode (180,140, 10, true );
My_video.attachvideo (my_cam );
Shutter. onrelease = function (){
Mybitmap = new flash. display. bitmapdata (180,240, true, 0 );
Mybitmap. Draw (my_video );
VaR tempobj = _ root. createemptymovieclip ("photo", 100 );
Tempobj. _ x = 300;
Tempobj. _ y = 40;
Tempobj. attachbitmap (mybitmap, 1, "always", true );
};
Testing
If any problem is found, only 160x120 of the image is taken. And the image is deformed.
What's wrong? @ # $ % ^ & * (2 hours are skipped here
Debug time ......)
At last, we found that adjusting the size of my_video to the scenario does not change my_video.width or my_video.height.
But changes the attributes of my_video. _ width and my_video. _ height. The size of the original video element is only 160x120. This is equivalent
My_video is deformed. Bitmapdata. Draw () does not consider deformation of source components. The official statement is:
Reference: Source movieclip
The object does not use any stage conversion for this call. This source movieclip
Objects are considered to exist in libraries or files. There is no matrix conversion, no color conversion, and no mixed mode. If you want to use the Transform
You can use its transform object to transfer various transformation attributes.
I didn't pay attention to the solution he provided. I want
Draw () does not consider the deformation of the source element, it can only find a way to deformation on the output photo element. So we have this code.
VaR my_video: video;
MySQL _ video. _ x = 100;
My_video. _ y = 40;
VaR my_cam: Camera = camera. Get ();
My_cam.setmode (180,140, 10, true );
My_video.attachvideo (my_cam );
Shutter. onrelease = function (){
Mybitmap = new flash. display. bitmapdata (160,120, true, 0 );
Mybitmap. Draw (my_video );
VaR tempobj = _ root. createemptymovieclip ("photo", 100 );
Tempobj. _ x = 300;
Tempobj. _ y = 40;
Tempobj. _ width = 180;
Tempobj. _ Height = 240;
Tempobj. attachbitmap (mybitmap, 1, "always", true );
};
This photo is the desired size, and the image is not deformed. However, the image is not clearly displayed by the camera.
Think about it. That is, of course, draw ()
Regardless of the Source Element deformation, my_video is used as draw of 160x120.
Can I change my_video.width and
Does the my_video.height attribute change the size of my_video instead of deformation my_video? No !!! My_video.width and
The my_video.height attribute is read-only.
Solution:
Step 1: use the video editing software to create a 180x240-sized 1-core White mov
Video files.
Step 2: Use Macromedia Flash 8 video encoder to convert mov video files to FLV
Video files.
Step 3: create a video element in the library and select "embedded" as the type (synchronized with the timeline ).
Step 4: drag the video element to the scene and name it "my_video"
Testing
The properties of my_video.width and my_video.height are 180x120. Aha
Step 5: paste the following content in the timeline
Code.
VaR my_video: video;
My_video.clear ()
MySQL _ video. _ x = 100;
My_video. _ y = 40;
VaR my_cam: Camera = camera. Get ();
My_cam.setmode (180,140, 10, true );
My_video.attachvideo (my_cam );
Shutter. onrelease = function (){
Mybitmap = new flash. display. bitmapdata (160,120, true, 0 );
Mybitmap. Draw (my_video );
VaR tempobj = _ root. createemptymovieclip ("photo", 100 );
Tempobj. _ x = 300;
Tempobj. _ y = 40;
Tempobj. _ width = 180;
Tempobj. _ Height = 240;
Tempobj. attachbitmap (mybitmap, 1, "always", true );
};
Now all the problems have been solved.