action script 3.0 import fla with xml - actionscript-3

i want import fla movie from xml. i can't make it. Thank for help.
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.engine.TabAlignment;
import flash.net.URLRequest;
import flash.media.Sound;
//i create timer for sound.
var tmr:Timer=new Timer(1000,1);
tmr.addEventListener(TimerEvent.TIMER, sesiBaslat);
function sesiBaslat(evt:TimerEvent){
var yol:URLRequest=new URLRequest("../../../sound/aaa/1/1/1.mp3");
var ses:Sound=new Sound();
ses.load(yol);
ses.play();
}
tmr.start();
//i was use this code in old times
/*var vid:Video = new Video(1600, 910);
flvPlaceHolder.addChild(vid);
addChild(flvPlaceHolder);
flvPlaceHolder.x = stage.stageWidth/2-vid.width/2;
flvPlaceHolder.y = stage.stageHeight/2-vid.height/2;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play("fla/683-bak.flv");
*/
//now i want to write this format now,because i want to make it dynamic
var veriler:XML;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, XMLokundu);
loader.load(new URLRequest("../../../xml/aaa/1/1/1.xml"));
function XMLokundu(e:Event):void{
veriler= new XML(e.target.data);
var loader1:Loader = new Loader();
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader1.load(new URLRequest(veriler.animasyonlar.animasyon[1].yolu));
//This blog was made a import sound,image etc. but doesnt work from fla
function imageLoaded(e:Event):void {
var flvPlaceHolder:MovieClip = new MovieClip();
var vid:Video = new Video();
e.target.content.smoothing = true;
addChild(loader1);
loader1.x = veriler.animasyonlar.animasyon[1].xkor;
loader1.y = veriler.animasyonlar.animasyon[1].ykor;
loader1.width = veriler.animasyonlar.animasyon[1].width;
loader1.height = veriler.animasyonlar.animasyon[1].height;
}
}
/*
//XML FİLE
//This is my xml file
<animasyonlar>
<animasyon>
<first>sound/16/1153.mp3</first>
<ikincises>sound/16/1154.mp3</ikincises>
<ucuncuses>sound/16/1151.mp3</ucuncuses>
<dorduncuses>sound/16/1152.mp3</dorduncuses>
<yolu>../../../../bbb/7/fla/683-look.flv</yolu> 1.fla way
<xkor>800</xkor> 2.x value
<ykor>100</ykor> 3.y value
<width>50%</width>
<height>50%</height>
</animasyon>
</animsyonlar>

Your XML is not formatted properly because your closing tag is missing the 2nd "a".
<animasyonlar>
...
</animsyonlar>

Related

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;
}

AS3 Video Playback with FLVPlayback

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);

Convert AS 3.0 into AS 2.0 for JSON Encode & Decode

I have written an AS 3.0 code for JSON Encode and Decode, but I need the below code written in AS 2.0. I know AS 3.0 but don't know AS 2.
Here is the code:
stop();
var getFBId:String = ExternalInterface.call("getFBIdFromJS");
var getFBName:String = ExternalInterface.call("getFBNameFromJS");
import com.adobe.serialization.json.JSON;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
playerInformation.visible = true;
var loginObj:Object = new Object();
var fbId:String = new String();
var Id:String = new String();
var varUid:String = new String();
var ImageUrl:String = new String();
var CreditBalance:String = new String();
//var PointBalance:String = new String();
var CoinBalance:String = new String();
var IsDailyBonus:String = new String();
var DailyBonusAmount:int = new int();
var fbvarsLoader:URLLoader = new URLLoader();
var fbvarsReq:URLRequest = new URLRequest("fbvars.php");
var fbvarsVariables:URLVariables = new URLVariables();
fbvarsLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
fbvarsReq.method = URLRequestMethod.POST;
fbvarsReq.data = fbvarsVariables;
fbvarsLoader.load(fbvarsReq);
fbvarsLoader.addEventListener(Event.COMPLETE, receiveLoad);
function receiveLoad(evt:Event):void
{
fbId = getFBId;
varUid = getFBName;
ImageUrl = "https://graph.facebook.com/" + getFBId + "/picture";
trace (getFBId);
trace (getFBName);
trace (ImageUrl);
loginObj.FacebookId = fbId;
loginObj.UserName = varUid;
loginObj.PlatformId = 1;
loginReq.data = JSON.encode(loginObj);
loginLoader.load(loginReq);
trace("login ENCODE: " + JSON.encode(loginObj));
FBlogindata.text = JSON.encode(loginObj);
}
//--------------- FB Vars (E)
var serverURL:String = "http://serverURL";
var playerPicLoader:Loader = new Loader();
//--------------------------------
var loginReq: URLRequest = new URLRequest();
loginReq.method = URLRequestMethod.POST;
loginReq.url =
"http://serverURL";
var loginLoader:URLLoader = new URLLoader();
loginLoader.addEventListener(Event.COMPLETE, onComplete_login);
function onComplete_login(e_login:Event)
{
var loginReturn:Object=JSON.decode(e_login.target.data,true);
trace("login DECODE: " + e_login.target.data);
logindata.text = e_login.target.data;
if (loginReturn.Player.Status == "Valid")
{
Id = String(loginReturn.Player.Id);
CreditBalance = String(loginReturn.Player.CreditBalance);
var playerPic:URLRequest = new URLRequest(ImageUrl);
playerPicLoader.load(playerPic);
playerInformation.mcPlayerThumbHolder.addChild(playerPicLoader);
playerInformation.txtPlayerName.text = varUid;
playerInformation.txtPlayerCredit.text = CreditBalance;
playerInformation.visible = true;
UIDShow.text = Id;
FBIDShow.text = fbId;
if (this.parent.parent != null){
trace (CreditBalance);
MovieClip(this.parent.parent).credit = CreditBalance;
}
}
}
Can any one write the above code in AS 2.0?
Here is implementation of AS2 JSON parser. There are two static methods stringify() - to encode into JSON and parse() to decode. So you don't have to write your own implementation. For other stuff you should probably sit and learn some things about AS2 or find someone who still remember AS2 :)

Flash AS3 copyPixels from BitmapData into jpeg screenshot

I have code to create a live screenshot of the stage in my swf.
After that it saves as a jpeg. All good.
Only, I don't need the whole stage, I only need a cutout:
x,y: 357,341
widt,height: 319,483
My code looks like this..
Where and how do I insert the copypixels function?
(I'm a Flash novice, so go easy on me :-)
function mouseReleaseSave(event:MouseEvent):void {
import com.adobe.images.JPGEncoder;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequestHeader;
import flash.net.URLRequest;
var jpgSource:BitmapData = new BitmapData(this.stage.stageWidth, this.stage.stageHeight);
jpgSource.draw(this.stage);
var jpgEncoder:JPGEncoder = new JPGEncoder(70);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
//set the request's header,method and data
var header:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
var loader:URLLoader = new URLLoader();
//sends jpg bytes to saveJPG.php script
var myRequest:URLRequest = new URLRequest("saveJPG.php");
myRequest.requestHeaders.push(header);
myRequest.method = URLRequestMethod.POST;
myRequest.data = jpgStream;
loader.load(myRequest);
//fire complete event;
loader.addEventListener(Event.COMPLETE,saved);
function saved(e:Event){
//trace the image file name
trace(loader.data);
}
}
This should help:
var subArea:Rectangle = new Rectangle(0,0, 319,483 );
var newBmp:Bitmap = new BitmapData( 319,483 );
var cutoutBmp:Bitmap = new Bitmap( newBmp, PixelSnapping.ALWAYS, true );
cutoutBmp.bitmapData.draw( jpgSource, new Matrix(1, 0, 0, 1, -357, -341) , null, null, subArea, true );

How to post JSON data using Actionscript 3.0?

I have to work with webservices in Actionscript. I found the following code that allows me to use JSON URLs that implement only the GET method. However, it doesn't work for POST methods (doesn't even enter the "onComplete" method). I searched the net and was unable to find any answers. How can i "POST" JSON data using Actionscript 3.0?
package
{
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
import com.adobe.serialization.json.JSON;
public class DataGrab extends Sprite {
public function DataGrab() {
}
public function init(resource:String):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(resource);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(request);
}
private function onComplete(e:Event):void {
var loader:URLLoader = URLLoader(e.target);
var jsonData:Object = JSON.decode(loader.data);
for (var i:String in jsonData)
{
trace(i + ": " + jsonData[i]);
}
}
}
}
You need to specify the method used with your URLRequest object. The default is GET. This could be a second argument to your init method:
public function init(resource:String,method:String = "GET"):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(resource);
request.method = method;
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(request);
}
When you call this function you can use the static GET and POST properties of URLRequestMethod rather than just passing strings for a little bit of extra safety.
I'm doing it with
import com.adobe.serialization.json.JSON;
var messages:Array = new Array ();
messages.push ({"nombreArchivo":"value"});
messages.push ({"image":"value"});
var vars: URLVariables = new URLVariables();
vars.data = JSON.encode(messages);
var req: URLRequest = new URLRequest();
req.method = URLRequestMethod.POST;
req.data = vars;
req.url = "crearIMG.php"
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleServerResponse);
loader.load(req);