AS3 Video Playback with FLVPlayback - actionscript-3

I am using the code below to load some data from an .xml file.
I am preloading all data (Audio Paths, Video Paths including a video from xml.
When everything is loaded complete i am loading the video in Frame 2 on FLVPlayback 2.5 with this code:
videoPlayer.source = videofile;
The problem is that the video shows a white screen for 3-4 seconds and then starts play.
At some other pc's it plays normaly when the loading ends.
My Code:
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
stop();
//******************************************************
// XML Loader
//******************************************************
var myLoader:URLLoader = new URLLoader();
//myLoader.load(new URLRequest("myxml.php"));
myLoader.load(new URLRequest("myxml.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void{
var myXml:XML = new XML(e.target.data);
parseXML(myXml);
}
//******************************************************
// Extract XML value and fill up variables
//******************************************************
var thename:XML;
var soundpath:XML;
var theage:XML;
var theplace:XML;
var everyday:XML;
var youwill:XML;
var pic1:XML;
var pic2:XML;
var pic3:XML;
var videofile:XML;
var assetsList:Array;
//-----------------------------
var sound:Sound;
var soundChannel:SoundChannel;
//-----------------------------
function parseXML(xml:XML):void{
thename = xml.paths.thename[0];
soundpath = xml.paths.soundpath[0];
theage = xml.paths.theage[0];
theplace = xml.paths.theplace[0];
everyday = xml.paths.everyday[0];
youwill = xml.paths.youwill[0];
pic1 = xml.paths.pic1[0];
pic2 = xml.paths.pic2[0];
pic3 = xml.paths.pic3[0];
videofile = xml.paths.videofile[0];
txtThename.text = thename;
txtSoundpath.text = soundpath;
txtTheage.text = theage;
txtTheplace.text = theplace;
txtEveryday.text = everyday;
txtYouwill.text = youwill;
txtPic1.text = pic1;
txtPic2.text = pic2;
txtPic3.text = pic3;
txtVideofile.text = videofile;
assetsList = [soundpath,theage,theplace,everyday,youwill,pic1,pic2,pic3,videofile];
preloadAssets();
}
//******************************************************
// preloaded assets
//******************************************************
var assetsLoader:URLLoader
var assetsCtr:Number=0;
function preloadAssets():void{
assetsLoader = new URLLoader ();
var urlRequest:URLRequest = new URLRequest(assetsList[assetsCtr]);
assetsLoader.load(urlRequest);
assetsLoader.addEventListener(Event.COMPLETE, assetLoadedHanlder);
assetsLoader.addEventListener(ProgressEvent.PROGRESS, assetProgressHandler);
}
function assetProgressHandler(evt:ProgressEvent):void{
var bl:uint = evt.bytesLoaded;
var bt:uint = evt.bytesTotal;
var perEachAssets = 1/assetsList.length;
var assetsBlLoaded = ((bl / bt)*perEachAssets)+((assetsCtr)/assetsList.length*100)/100;
var _percentLoaded = Math.floor(assetsBlLoaded*100);
progBar.setProgress(_percentLoaded,100)
//trace("_percentLoaded:",_percentLoaded)
}
function assetLoadedHanlder(evt:Event):void{
assetsCtr+=1;
if(assetsCtr<assetsList.length){
//trace("preloading:"+assetsList[assetsCtr])
var urlRequest:URLRequest = new URLRequest(assetsList[assetsCtr]);
assetsLoader.load(urlRequest);
}else{
//trace("done!")
assetsLoader.removeEventListener(Event.COMPLETE, assetLoadedHanlder);
assetsLoader.removeEventListener(ProgressEvent.PROGRESS, assetProgressHandler);
gotoAndStop(2);
}
}

Rather than adding the component directly to the stage you might want to try creating and adding it with ActionScript.
By doing this you can instantiate the FLVPlayback instance before you need to show it, rather than having to wait until you hit frame 2 on your timeline.
I can't guarantee it will fix your problem but it's worth a go.
var _videoFLV:FLVPlayback;
_videoFLV = new FLVPlayback();
_videoFLV.fullScreenTakeOver = false;
_videoFLV.autoPlay = false;
_videoFLV.autoRewind = true;
_videoFLV.isLive = false;
_videoFLV.skin = null;
_videoFLV.bufferTime = .1;
_videoFLV.width = 320;
_videoFLV.height = 240;
_videoFLV.source = videofile;
_videoFLV.stop();
_videoFLV.x = 240;
_videoFLV.y = 240;
addChild(_videoFLV);

Related

Add movieclips within another movieclip

I am having trouble embedding a child object to a movieClip with code using AS3 and I am not sure what I am doing wrong.
I am trying to create a new movieclip with code and add it to the stage. I am then trying to embed dynamically created objects inside that movieclip. When I trace the objects it shows that they are on the stage and not embedded into the movieclip. I looked through the forums but I didn't find an answer. Below is a watered down version of the code I have. Any help is appreciated.
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Sprite;
import flash.text.*;
import flash.net.URLRequest;
import flash.display.Loader;
var btnAImage:Loader = new Loader();
var image:URLRequest = new URLRequest("btn_A.png");
public function TextWithImage()
{
var TextField1:TextField = new TextField;
var myText1:String = "TEXT FIELD 1";
var BtnMovieClip:MovieClip = new MovieClip();
var btnPadding = 5;
addChild(BtnMovieClip); //add new MC to stage
btnAImage.load(image);
BtnMovieClip.addChild(btnAImage); // no error gets thrown. I am trying to add the btnAImage inside of my BtnMovieClip.
btnAImage.x = btnPadding; //I am able to reference the btnAImage without referencing the BtnMovieClip object.
btnAImage.y = btnPadding;
var screenW = stage.stageWidth;
TextField1.height = 40;
TextField1.width = 250;
var textPadding = 5;
var TextField1_fontFormat:TextFormat = new TextFormat ;
TextField1_fontFormat.size = 40;
TextField1_fontFormat.font = "TestFont";
TextField1.defaultTextFormat = TextField1_fontFormat;
BtnMovieClip.addChild(TextField1); // no error gets thrown. I am trying to add the text field inside of my BtnMovieClip.
TextField1.text = myText1;
TextField1.x = (btnAImage.width + textPadding);
TextField1.y = textPadding;
}
I wasn't preloading my image so here's how I fixed it. Thank you to Organis for the help!!!
public var btnAImage:Loader;
private function Question8_Answer()
{
trace("Question8_Answer() was called");
btnAImage = new Loader();
btnAImage.load(new URLRequest("btn_A.png"));
btnAImage.contentLoaderInfo.addEventListener(Event.COMPLETE, TextWithImage);
}
public function TextWithImage()
{
var TextField1:TextField = new TextField;
var myText1:String = "TEXT FIELD 1";
var BtnContainer:Sprite = new Sprite();
var btnPadding = 5;
addChild(BtnMovieClip);
BtnMovieClip.addChild(btnAImage);
btnAImage.x = btnPadding;
btnAImage.y = btnPadding;
var screenW = stage.stageWidth;
TextField1.height = 40;
TextField1.width = 250;
var textPadding = 5;
var TextField1_fontFormat:TextFormat = new TextFormat ;
TextField1_fontFormat.size = 40;
TextField1_fontFormat.font = "TestFont";
TextField1.defaultTextFormat = TextField1_fontFormat;
BtnMovieClip.addChild(TextField1); // no error gets thrown. I am trying to add the text field inside of my BtnMovieClip.
TextField1.text = myText1;
TextField1.x = (btnAImage.width + textPadding);
TextField1.y = textPadding;
BtnContainer.width = 300;
}

ActionScript 3.0 web scraper works in flash, but not browser

so I have this issue. I recently made a flash webscraper to grab a video source link. It works in flash, however when I test in the browser I only get a blank canvas... It does not work. I have no idea as to what the problem is... I just started learning actionscript today, so I'm far from the greatest at it.
import flash.net.*
import flash.events.*;
import flash.display.*;
var theUrl = "http://www.sockshare.com/file/384F14398D224634";
firstStep();
function firstStep() {
var urlReq: URLRequest = new URLRequest(theUrl);
urlReq.method = URLRequestMethod.POST;
var loader: URLLoader = new URLLoader(urlReq);
loader.addEventListener(Event.COMPLETE, onSuccess);
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(urlReq);
function onSuccess(e: Event): void {
var theContents1: String = String(loader.data);
var pattern1: RegExp = /<input type="hidden" value="(?P<innertext>.*?)" name="hash">/;
var result1 = pattern1.exec(theContents1);
goToSecond(result1.innertext);
}
}
function goToSecond(hash: String) {
var urlReq2: URLRequest = new URLRequest(theUrl);
urlReq2.method = URLRequestMethod.POST;
var urlVars2: URLVariables = new URLVariables();
urlVars2.hash = hash;
urlVars2.confirm = 'Continue+as+Free+User';
urlReq2.data = urlVars2;
var loader2: URLLoader = new URLLoader(urlReq2);
loader2.addEventListener(Event.COMPLETE, onSuccess2);
loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
loader2.load(urlReq2);
function onSuccess2(e: Event): void {
var theContents2: String = String(loader2.data);
var pattern: RegExp = /playlist%3A%20%27%2F(?P<innertext>.*?)%27%2C%0D%0A%09plugins/;
var result = pattern.exec(theContents2);
var linkp1: String = "http://www.sockshare.com/" + unescape(result.innertext);
finalStep(linkp1);
}
}
function finalStep(finalUrl: String) {
var urlReq3: URLRequest = new URLRequest(finalUrl);
urlReq3.method = URLRequestMethod.POST;
var loader3: URLLoader = new URLLoader(urlReq3);
loader3.addEventListener(Event.COMPLETE, onSuccess3);
loader3.dataFormat = URLLoaderDataFormat.TEXT;
loader3.load(urlReq3);
function onSuccess3(e: Event): void {
var theContents3: String = String(loader3.data);
var pattern2: RegExp = /<media:content url="(?P<innertext>.*?)" type="/;
var result2 = pattern2.exec(theContents3);
var finalLink: String = result2.innertext;
trace(finalLink);
mainText.text = finalLink;
}
}
It's sandbox problem, read here, if you'll publish as standalone (ex: Air) project it would work

RSS gallery as3

Here is my case - I have 10 movie clips on the view and in every movie clip I need to have a loaded picture that RSS. I've managed to get the first one loaded but I need the other 9 as well. Any ideas?
import com.adobe.xml.syndication.generic.FeedFactory;
import com.adobe.xml.syndication.generic.IFeed;
import com.adobe.xml.syndication.generic.IItem;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var rss:XML;
var rss_url:URLRequest = new URLRequest("http://btvnews.bg/lbin/rss.php?section_id=16105?pic_size=300x158");
var rssLoader:URLLoader = new URLLoader(rss_url);
rssLoader.addEventListener(Event.COMPLETE, rssLoaded);
var rssCount;
var rssCounter = 0;
var l = new Loader();
var loaderContext:LoaderContext;
loaderContext= new LoaderContext();
loaderContext.securityDomain=SecurityDomain.currentDomain;
loaderContext.checkPolicyFile = true;
Security.loadPolicyFile('http://img.bg.sof.cmestatic.com/crossdomain.xml');
function rssLoaded(e:Event):void
{
rss = XML(rssLoader.data);
var curImage = rss.channel.item[0].enclosure. # url;
l.load(new URLRequest(curImage));
l.contentLoaderInfo.addEventListener(Event.COMPLETE,doneIt);
function doneIt(e:Event)
{
var bit:Bitmap = e.target.content;
if (bit != null)
{
bit.smoothing = true;
}
}
placer.addChild(l);
After your rss load as you have loaded one images put a for loop for the item
for(var i=0; i < rss.channel.item.length;i++)
{
var img = rss.channel.item[i].enclosure. # url;
//rest of the code to load the image and adding to stage
}

How to make a volume slider that uses channels

I am trying to make a volume slider that uses channels.
I am not sure how to do this.
Here is my code:
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.media.Sound;
// Enter Frame Event
var sliderValue:uint = mySlider.sliderKnob.x;
addEventListener(Event.ENTER_FRAME, frame);
function frame(event):void {
sliderValue = mySlider.sliderKnob.x ;
status_txt.text = "Volume: "+sliderValue;
var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
var volumeLevel = channel.soundTransform;
var req:URLRequest = new URLRequest("Background.mp3")
snd.load(req);
channel = snd.play();
var newLevel:Number = mySlider.sliderKnob.x / 100;
volumeLevel.volume = newLevel;
channel.soundTransform = volumeLevel;
}
You are instantiating and loading the sound on every single frame. And you need to make a new SoundTransform instance! I take it that the slider itself is working!
var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
var volumeLevel:SoundTransform = new SoundTransform();
snd.load(new URLRequest("Background.mp3"));
channel = snd.play();
addEventListener(Event.ENTER_FRAME, frame);
function frame(event):void {
sliderValue = mySlider.sliderKnob.x ;
status_txt.text = "Volume: "+sliderValue;
var newLevel:Number = sliderValue / 100;
volumeLevel.volume = newLevel;
channel.soundTransform = volumeLevel;
}

Actionscript 3 - DataGridColumn and having a specific column automatically sorted

I am using the DataGrid component in Flash, that is loaded with data via a external XML file. I have a column, A (Serial), which once loaded, I'd like for the information to be sorted Ascendingly, automatically. Does anyone have any idea on how to do this?
Here is my code:
import fl.controls.DataGrid;
import fl.data.DataProvider;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.controls.ScrollPolicy;
import fl.events.DataGridEvent;
var dp:DataProvider;
var A:DataGridColumn = new DataGridColumn("Serial");
A.headerText = "Serial No.";
A.width = 100;
A.resizable = false;
var B:DataGridColumn = new DataGridColumn("Mold");
B.headerText = "Mold No.";
B.width = 150;
B.resizable = false;
var C:DataGridColumn = new DataGridColumn("Type");
C.headerText = "Grid Type: ";
C.width = 350;
C.resizable = false;
var myDataGrid:DataGrid = new DataGrid();
myDataGrid.addColumn(A);
myDataGrid.addColumn(B);
myDataGrid.addColumn(C);
myDataGrid.verticalScrollPolicy = ScrollPolicy.ON;
myDataGrid.setSize(600, 800);
myDataGrid.move(0, 0);
myDataGrid.addEventListener(DataGridEvent.HEADER_RELEASE, headerReleaseHandler);
addChild(myDataGrid);
var url:String = "xml/TEST.xml";
var req:URLRequest = new URLRequest(url);
var uLdr:URLLoader = new URLLoader();
uLdr.addEventListener(Event.COMPLETE, completeHandler);
uLdr.load(req);
function completeHandler(event:Event):void {
var ldr:URLLoader = event.currentTarget as URLLoader;
var xmlDP:XML = new XML(ldr.data);
dp = new DataProvider(xmlDP);
myDataGrid.dataProvider = dp;
}
function headerReleaseHandler(event:DataGridEvent):void {
var dg:DataGrid = event.currentTarget as DataGrid;
trace("column: " + String(event.dataField));
trace("descending: " + String(dg.sortDescending));
}
Thanx
Try the sortItemsOn() method on the DataGrid.
See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/SelectableList.html#sortItemsOn() for an example how to use it.