How to merge 2 flv files with alpha channel? - actionscript-3

I am a new face in flash community. May I have some suggestion from you guys?
I have 2 flv files, one is a video with alpha channel (I want to show it on the top), and the recorded file from camera on mobile device (maybe on iOS device). How should I do, If I want to merge these files together by programatically?
Thanks.

I'm not sure, if I understand correctly, but I think you want to show 2 video at same position.
It's pretty easy. You should start a new project, and import the two videos:
var myVideo:Video = new Video();
addChild(myVideo);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
myVideo.attachNetStream(ns);
ns.play("http://www.example.com/file.flv");
var myVideo2:Video = new Video();
addChild(myVideo2);
var nc2:NetConnection = new NetConnection();
nc2.connect(null);
var ns2:NetStream = new NetStream(nc2);
myVideo2.attachNetStream(ns2);
ns2.play("http://www.example.com/file2.flv");
Than you should set the alpha (opacity) to 0.5 (or anything in a 0-1 range) of the video, so it will be semi-transparent:
myVideo2.alpha = 0.5;
The child you added last with addChild() will be on top of the displaylist, so you should set the alpha of that one. (you can also set both's alpha to any value).
Hope it helped.

Related

AS3 SoundChannel/Sound HZ Limit for importing

I have wav files that are at 1411kbs bit rate and varying frequencies. After I import them into the library and give them unique classes based on their frequency and other information (that is why I use getDefinitionByName below).
All of my wav files play fine in AS3 that are under 6000hz and 8000hz, however those tones don't play properly. However, they do play properly when clicking the Play icon when in Flash Adobe Animate.
I have stripped my code down to the bare essentials to see where the problem lies and still not working properly.
My question is, is there a problem with my code or does AS3/Flash have a limit on the frequency it can play?
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
btn.addEventListener(MouseEvent.CLICK, function(){
var sound_class = "L6000_0";
var soundTX:SoundTransform = myChannel.soundTransform;
soundTX.leftToLeft = 1;
soundTX.leftToRight = 0;
soundTX.volume = 1;
soundTX.rightToRight = 0;
soundTX.rightToLeft = 0;
var sclass:Class = getDefinitionByName(sound_class) as Class;
var mySound:Sound = new sclass;
myChannel.stop();
myChannel = mySound.play();
myChannel.soundTransform = soundTX;
});
It is not the scripting problem, I think. By default Flash exports sounds at very low bitrate and quality. Go to each sound properties to set the export settings or, alternately, in File > Publish Settings screen there's an option about exporting sounds.

Flash .fla embed banner add

I need to create a Flash web banner. The .swf file size needs to be >40k so I made a .fla video and tried to stream it into the file however I'm getting no luck.
I can't find anything on the internet so I thought I'd ask here.
Im using Flash CC AS3
When I run the file through the
https://flashval-temp.appspot.com/validator/
the .swf uploads but the .fla doesn't play at all.
The code I was using was:
var vid:Video;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
ns.client = customClient;
ns.play("300x250.flv");
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
function asyncErrorHandler(event:AsyncErrorEvent):void
{
trace(event.text);
}
function metaDataHandler(infoObject:Object):void {
vid.width = infoObject.width;
vid.height = infoObject.height;
}
It seems to work fine offline, the files are in the same directory too.
Without knowing the full environment it's hard to tell you what's wrong, but you may want to check these:
(1) upload your video file to a server and grab the full url to the file, then update your code with it:
ns.play("http://www.YOUR_DOMAIN.com/300x250.flv");
(2) add the following as3:
Security.allowDomain("*");
(3) If that still doesn t work, look into crossdomain.xml at the root of your server hosting the video.
But (1) is likely to be the issue.

How to import picture in flash with transaprent background

How do I make transparent background to imported image in flash, because now i imported it and image has white box around it.
code for adding images to stage
var imageBD = (Math.floor(Math.random()*2))? new Trees() : new Rocks;
var bitmap:Bitmap = new Bitmap();
var BD:BitmapData = new BitmapData(imageBD.width, imageBD.height);
BD.draw(imageBD);
bitmap.bitmapData = BD;
bitmap.width = mRadius * 2 * mToPx;
bitmap.height = mRadius * 2 * mToPx;
bitmap.x = pxStartX;
bitmap.y = pxStartY;
this.addChild(bitmap);
obstacleImages.push(bitmap)
Since i'm mew i cannot post images so i'm giving you a link to image:http://prntscr.com/pugdl
You need to specifically tell the BitmapData (docs) object to be transparent.
In your case, replace this line:
var BD:BitmapData = new BitmapData(imageBD.width, imageBD.height);
...with this:
var BD:BitmapData = new BitmapData(imageBD.width, imageBD.height, true, 0x00000000);
Make sure the image itself has transparency. General file types for these kinds of images are PNG or GIF.
You shouldn't have to do anything for Flash to find the transparency.

Flex PNGEncoder lose transparent quality

I've got problem with transparent using PNGEncoder class. When I encode BitmapData to png and use it as source of my Image, it looks terrible. I attach example. There are two images - first colorful and above him white with alpha gradient.
Image before save
Image after save
I've used some other libraries like AsPngEncoder, but it didn't help. It's code I use:
var bd:BitmapData = new BitmapData(container.width, container.height, true, 0xffffff);
bd.draw(container);
var pngenc:PNGEncoder = new PNGEncoder();
var pngByteArray:ByteArray = pngenc.encode(bd);
container.source = pngByteArray;
var fl:File = File.applicationStorageDirectory.resolvePath("./images/file.png");
var fs:FileStream = new FileStream();
fs.open(fl, FileMode.WRITE);
fs.writeBytes(pngByteArray);
fs.close();
Try to use new Flash Player 11.3 feature
http://help.adobe.com/en_US/as3/dev/WS4768145595f94108-17913eb4136eaab51c7-8000.html

Weird NetStream problem when using function

This code causes my f4v file to stop playing prematurely. Time changes but roughly 8-10 seconds in.
loadSong();
function loadSong()
{
if(!songPlaying)
{
songPlaying = true;
var customClient:Object = new Object();
customClient.onCuePoint = cuePointHandler;
customClient.onMetaData = metaDataHandler;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = customClient;
ns.play("song.f4v");
}
trace("HERE");
}
function cuePointHandler(infoObject:Object):void{
trace(infoObject.name);
}
function metaDataHandler(infoObject:Object):void {
trace("metaData");
}
This code let's the f4v play till the end. WTF!? It seems that when I call it via a function it causes the issue. FYI the code is stored in the first frame of the main timeline, and the F4v is audio only. Any help would be appreciated.
if(!songPlaying)
{
songPlaying = true;
var customClient:Object = new Object();
customClient.onCuePoint = cuePointHandler;
customClient.onMetaData = metaDataHandler;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = customClient;
ns.play("song.f4v");
}
What is happening, when you declare your NetConection and NetStream inside the function, is that the scope for that variable is local to that function. That means that nothing else is referencing the NetConnection you created and thus the garbage collector sweeps it up during its next run (that's why you are seeing the variable time).
When you declare it in just an if statement the variables are in the scope of the movie and that holds a reference to them and thus aren't garbage collected.
I don't know what the architecture is for the rest of your code, but if you want to use functions to hold your code, try putting a declaration for the var nc:NetConnection = new NetConnection(); just before the loadSong(); statement.
Architecturally, you might want to refactor your code out of the frame, but it might really not be worth it, if it is just couple of lines of code. Just depends on your project.
For more information about garbage collection, check out Understanding garbage collection in Flash Player 9 (It's says Flash Player 9, but this is applicable to 10 as well).