Adobe Animate CC to PHP - actionscript-3

Flash AS3 Form Components - PHP File and Adobe Animate
Symbol 'wholeForm', Layer 'Action', Frame 1, Line 81, Column 3 1120:
Access of undefined property varLoader. Symbol 'wholeForm', Layer
'Action', Frame 1, Line 81, Column 18 1120: Access of undefined
property varSend. Symbol 'wholeForm', Layer 'Action', Frame 1, Line
30, Column 27 1067: Implicit coercion of a value of type
flash.net:URLRequest to an unrelated type Class.
'wholeForm' Is an MovieClip that contains buttons and text, see the image below
Program for submiting data to php:
code :
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.events.MouseEvent;
//hide processing mc
processing_mc.visible = false;
//custom function we create to populate the comboBox
list
function addCountriesToList(): void {
countryList.addItem({
label: "Barja"
});
countryList.addItem({
label: "Baasir"
});
countryList.addItem({
label: "Jadra"
});
countryList.addItem({
label: "Jieh"
});
}
// Run function above now
addCountriesToList();
var variables: URLVariables = new URLVariables;
// Build the varSend variable
varSend: URLRequest = new URLRequest("from_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
varLoader: URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
// handler for the PHP script completion and return of status
function completeHandler(event: Event): void {
// remove processing clip
processing_mc.visible = false;
name_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
//msg_txt.maxChars=300;
kids.value = 0;
checkBox.selected = false;
// Load the response frome php here
status_txt.text = event.target.data.return_msg;
}
// Add event listener for sumbit button click
sumbit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// function ValidateAndSend
function ValidateAndSend(event: MouseEvent): void {
// validate fields
if (!name_txt.length) {
status_txt.text = "Plase enter your name";
} else if (!email_txt.length) {
status_txt.text = "Plase enter your mail";
} else if (!msg_txt.length) {
status_txt.text = "Plase enter your message";
} else {
// All is good, send the data now to PHP
processing_mc.visible = true;
// ready the variables in our form for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userCountry = countryList.value;
variables.userKids = kids.value;
variables.userGender = radioGroup.value;
variables.Newsletter = checkBox.selected;
// Send the data to PHP now
varLoader.load(varSend);
} // close else conditin for error handling
} // close validate and send function

Since there is no explanation of problem, I'm guessing you mean you have these errors?
Access of undefined property varLoader.
Access of undefined property varSend.
Implicit coercion of a value of type flash.net:URLRequest to an unrelated type Class
They speak for themselves. You did not declare the variables so they are undefined...
Declare as : var NAME : TYPE = VALUE;
Example : var myLoader : URLLoader = new URLLoader; defines a variable named myLoader.
Your Code example:
// Build the varSend variable
varSend: URLRequest = new URLRequest("from_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
Should be
// Build the varSend variable
var varSend: URLRequest = new URLRequest("from_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
So the fixes are :
code : varLoader: URLLoader = new URLLoader;
fixed : var varLoader: URLLoader = new URLLoader;
code : varSend: URLRequest = new URLRequest("from_parse.php");
fixed : var varSend: URLRequest = new URLRequest("from_parse.php");
The above var varSend (now defined) will also fix error from : varLoader.load(varSend);
PS:
It would be more helpful (to you & future readers) to make your code more readable like so:
// Build the Sending variable
var mySend: URLRequest = new URLRequest("from_parse.php");
mySend.method = URLRequestMethod.POST;
mySend.data = variables;
// Build the Loading variable
var myLoader: URLLoader = new URLLoader;
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
// Send the data to PHP now
myLoader.load(mySend);

Related

URLLoaderDataFormat.AError #1069: Property TEXT not found on String and there is no default valuerray as3

I am trying to parse some static variable that i loaded from another class into this URLloader. I can trace the array with no problem, but not sure why i can't set them as the variables for the URLVariables?
private function Contactyes(event:MouseEvent):void
{
//Here create the parser to php database for interested list
variables:URLVariables;
Sends = new URLRequest("http://localhost/Sendinterested.php");
Sends.method = URLRequestMethod.POST;
Sends.data = variables;
Loaders = new URLLoader();
Loaders.dataFormat = URLLoaderDataFormat.TEXT;
Loaders.addEventListener(Event.COMPLETE,completeHandler);
infodata= SearchVectorTest.lists;
somedata=homepage.infoss;
trace(somedata[0]);
variables.userid = somedata[0].TEXT;
variables.username = somedata[1].TEXT;
variables.useremail = somedata[3].TEXT;
variables.Listingname = infodata[1].TEXT;
variables.Listingid = infodata[0].TEXT;
Homepage.as
public class homepage extends MovieClip {
public static var infoss:Array;
public function homepage(){Mend = new URLRequest("http://localhost/myaccount_1.php");
Mend.method = URLRequestMethod.POST;
variablesss = new URLVariables();
variablesss.username = s7.statusname.text;
Mend.data = variablesss;
nLoader = new URLLoader();
nLoader.dataFormat = URLLoaderDataFormat.TEXT;
nLoader.addEventListener(Event.COMPLETE,Candler);
nLoader.load(Mend);
// handler for the PHP script completion and return of status
function Candler(event:Event):void{
var resultString :String = event.target.data;
// parse result string as json object and cast it to array
var resultArray :Array = JSON.parse( resultString ) as Array;
trace(resultArray[0]);
trace(resultArray[1]);
trace(resultArray[2]);
trace(resultArray[3]);
s7.statusname.text= resultArray[1];
infoss = new Array(resultArray[0],resultArray[1],resultArray[2],resultArray[3]);
}
Thanks for your time

Locale.loadLanguageXML() Won't work in external script

I have a script for multi-language-use working when added to the first frame of a timeline. However, when I try to adapt it to work in an external .as script, it throws a TypeError and I can't figure out why.
Here is the code that works in a timeline:
import fl.data.DataProvider;
import fl.text.TLFTextField;
import flash.text.Font;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;
//------------------
// CREATE TLFTEXTFIELD:
var field_001:TLFTextField = new TLFTextField();
field_001.x = 20;
field_001.y = 50;
field_001.width = 342
field_001.height = 54;
field_001.background = true;
addChild(field_001);
// Create text format
var format:TextLayoutFormat = new TextLayoutFormat();
format.fontFamily = "Arial";
format.fontSize = 36;
format.color = 0x666666;
// Apply the format
var textFlow:TextFlow = field_001.textFlow;
textFlow.hostFormat = format;
//------------------
// SETUP LOCALE OBJECT:
var languages:Object = new Object(); // Stores flags for loaded languages
var localeDefault:String = "ar"; // Default language
var locale:String = "ar"; // Current language selected in combobox
// Event handler for Locale object
function localeLoadedHandler(success:Boolean):void
{
if( success )
{
// Mark language as loaded and show localized string
languages[locale] = true;
field_001.text = Locale.loadStringEx("IDS_FIRSTFIELD", locale);
// field_002 is a field already on stage
field_002.text = Locale.loadStringEx("IDS_SECONDFIELD", locale);
}
}
// Load the default language...
Locale.setDefaultLang(localeDefault);
Locale.setLoadCallback(localeLoadedHandler);
trace("Locale.getDefaultLang() is: " + Locale.getDefaultLang());
Locale.loadLanguageXML(Locale.getDefaultLang());
Here is my adaptation to an external script and set up as the class for a standalone swf called "tempchild.swf" I want to open inside a parent swf at a later time:
package com.marsinc {
import fl.text.TLFTextField;
import flash.text.Font;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;
import flash.display.MovieClip;
import fl.lang.Locale;
public class tempchild extends MovieClip {
//------------------
// SETUP LOCALE OBJECT:
private var languages:Object; // Stores flags for loaded languages
private var localeDefault:String; // Default language
private var locale:String; // Current language selected in combobox
private var field_001:TLFTextField;
private var format:TextLayoutFormat;
public function tempchild()
{
// constructor code
languages = new Object();
localeDefault = "es";
locale = "es";
//------------------
// CREATE TLFTEXTFIELD:
field_001 = new TLFTextField();
field_001.x = 20;
field_001.y = 50;
field_001.width = 342
field_001.height = 54;
field_001.background = true;
addChild(field_001);
// Create text format
format = new TextLayoutFormat();
format.fontFamily = "Arial";
format.fontSize = 36;
format.color = 0x666666;
// Apply the format
var textFlow:TextFlow = field_001.textFlow;
textFlow.hostFormat = format;
// Load the default language...
Locale.setDefaultLang(localeDefault);
Locale.setLoadCallback(localeLoadedHandler);
trace("Locale.getDefaultLang() is: " + Locale.getDefaultLang()); // displays "es"
Locale.loadLanguageXML(Locale.getDefaultLang()); // this line returns an error
}
// Event handler for Locale object
private function localeLoadedHandler(success:Boolean):void
{
trace("running the loaded handler");
if( success )
{
// Mark language as loaded and show localized string
languages[locale] = true;
field_001.text = Locale.loadStringEx("IDS_FIRSTFIELD", locale);
//field_002.text = Locale.loadStringEx("IDS_SECONDFIELD", locale);
}
}
}
And this is the error in the output window:
TypeError: Error #1010: A term is undefined and has no properties.
at fl.lang::Locale$/loadXML()
at fl.lang::Locale$/loadLanguageXML()
at com.marsinc::tempchild()
Been digging around for an answer for a couple days now and I am stuck. Any help is greatly appreciated. Thanks!
--Kevin
You can make it .as file in one of (at least) two ways
1) copy paste all exactly as it is to .as file and do:
include "[path]filename.as"
2) change the code to be a class
- make field_001, format, textFlow, languages, localeDefault, locale as public vars
- insert all code in a function named "init"
- add the "localeLoadedHandler" as a function
- click on your stage and change in the properties panel the stage's class to the new class
Good Luck!!

Putting Urlloader in a Class

I have searched on google en different pages i found the problem but not the solution.
I have a class i made and that class is called WebServiceController:
public class WebServiceController
{
private var url:String;
private var post:Object=new Object();
private var loader:URLLoader = new URLLoader();
private var postVariable:String="";
private var getVariable:String="";
private var Geladen:Boolean=false;
public function WebServiceController()
{
}
public function postUrlData(u:String,p:Object):String
{
url=u;
post=p;
var urlReq:URLRequest = new URLRequest (url);
var i:int=0;
for(var key:String in post)
{
//trace(key +" = " + post[key]);
if(i==0)
{
// urlVars.key = post[key];
postVariable=postVariable+""+key+"="+post[key];
}
else
{
//urlVars.key = post[key];
postVariable=postVariable+"&"+key+"="+post[key];
}
i++;
}
//trace(postVariable);
var urlVars:URLVariables = new URLVariables(postVariable);
//trace(urlVars);
// Add the variables to the URLRequest
urlReq.data = urlVars;
urlReq.method = URLRequestMethod.POST;
// Add the URLRequest data to a new Loader
//loader.load(urlReq);
// Set a listener function to run when completed
loader.addEventListener(Event.COMPLETE, onLoaderComplete);
// Set the loader format to variables and post to the PHP
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlReq);
function onLoaderComplete(event:Event):void
{
return loader.data;
}
}
Now from my movieclip i call the next function but it says undefined:
var wb:WebServiceController = new WebServiceController();
trace(wb.postUrlData(url,post));
I dont know how to solve this. I tried different things but it keeps saying undefined.
The URLLoader.load call is executed asynchronously so the data has not been returned when you attempt to trace it out in the class that instantiates your WebServiceController class.
To access the data in the parent class, your best bet is probably to dispatch an event from the WebServiceController class when the data has loaded and catch it in the parent class.
WebServiceController:
public function postUrlData(u:String, p:Object):void
{
url=u;
post=p;
var urlReq:URLRequest = new URLRequest (url);
var i:int=0;
for(var key:String in post)
{
//trace(key +" = " + post[key]);
if(i==0)
{
// urlVars.key = post[key];
postVariable=postVariable+""+key+"="+post[key];
}
else
{
//urlVars.key = post[key];
postVariable=postVariable+"&"+key+"="+post[key];
}
i++;
}
//trace(postVariable);
var urlVars:URLVariables = new URLVariables(postVariable);
//trace(urlVars);
// Add the variables to the URLRequest
urlReq.data = urlVars;
urlReq.method = URLRequestMethod.POST;
// Add the URLRequest data to a new Loader
//loader.load(urlReq);
// Set a listener function to run when completed
loader.addEventListener(Event.COMPLETE, onLoaderComplete);
// Set the loader format to variables and post to the PHP
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlReq);
}
private function onLoaderComplete(event:Event):void
{
// We can pass the event on like this
dispatchEvent(event);
}
Parent class:
public function initWebServiceController():void
{
var wb:WebServiceController = new WebServiceController();
wb.addEventListener(Event.COMPLETE, onWebServiceControllerDataLoaded);
wb.postUrlData(url, post);
}
private function onWebServiceControllerDataLoaded(event:Event):void
{
// The event target is the URLLoader instance. We can
// access the loaded data via its data property
trace(URLLoader(event.target).data);
}

Imdb api with flash - as3 - flex

I am trying to use the imdb API, in this case: http://imdbapi.org/
I need to search for a movie by name and get a json, then load an image with the poster obtained.
I'll be using as3 - flex to generate an Air package.
I tried this example, but can't seem to get it right.
import flash.net.*;
var url:String = "http://imdbapi.org/";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.GET;
var variables:URLVariables = new URLVariables();
variables.name = "Pulp fiction";
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(request);
function onComplete (event:Event):void {
trace(event.target.data);
}
Perhaps you could enlight me with an example of connecting to the api and retrieving that json so that I can load an image with the poster and generate my air package.
Many thanks!
The API seems to want the movie in the q param so change this
variables.name = "Pulp fiction";
to :
variables.q = "Pulp fiction";
To verify : http://imdbapi.org/?q=Pulp%20Fiction
From there getting the poster URL is just a matter of reading the correct property from the JSON string.
private function onComplete (event:Event):void {
var data:Array = JSON.parse(event.target.data);
if(data && data.length)
{
var movie:Object = data[0];
trace(movie.poster);
}
}

How to deserialize array collection in flex

I am stuck with an issue:
In which I am serializing an array collection to a file, the array collection has two type of items an Image and a class object.
It serialize successfully, but when I de-serialize it, It simply returns array collection of objects and I found my self unable to convert these objects into Images and the class object(this class is defined by myself and having three members, two images and a shape).
I am adding the code which I used:
[Bindable] var objcnvs:ClassCanvas;
protected function btnSave_clickHandler(event:MouseEvent):void
{
//for saving data serializaion
var arrAllSave:ArrayCollection = new ArrayCollection();
for(var i:int = 0;i<arrAll.length; i++)
{
try
{
var tempCon:ConnectImage = arrAll[i];
arrAllSave.addItem({item:arrAll[i], type:"ConnectImage" });
}
catch(er:Error)
{
var tempImage:Image = arrAll[i];
var objImage:ClassImage = new ClassImage(arrAll[i]);
arrAllSave.addItem({item:objImage, type:"Image" });
}
}
// First, generate your ByteArray from the VO.
var byteArray : ByteArray = new ByteArray();
byteArray.writeObject( arrAll );
// Resolve your file location.
//var file : File = File.applicationStorageDirectory.resolvePath( "testFile.ri" );
var mapName:String = txtMapTitle.text;
var file : File = File.applicationStorageDirectory.resolvePath( 'Saved Maps/'+mapName+'.imm' );
if(file.exists == true)
{
lblWarn.text = "Map already Exists. Please enter Defferent Map Title";
}
else if(mapName == "")
{
lblWarn.text = "Please enter a title for Map.";
}
else
{
var fileStream:FileStream = new FileStream();
// Save the file to the given location.
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes( byteArray );
fileStream.close();
lblWarn.text = "Map Saved successfully";
}
}
protected function btnLoadMap_clickHandler(event:MouseEvent):void
{
// Execute the file load.
var loadFileName:String = "t1";
var request : URLRequest = new URLRequest ( "app-storage:/"+"Saved Maps/"+loadFileName+".imm" );
var receptor : URLLoader = new URLLoader( request );
// Make sure our content is interpreted as a ByteArray.
receptor.dataFormat = URLLoaderDataFormat.BINARY;
receptor.addEventListener( Event.COMPLETE, fileLoadedHandler );
}
private function fileLoadedHandler ( event : Event ) : void
{
// Retrieve the event target, cast as the URLLoader we just created
var loader : URLLoader = event.target as URLLoader;
// Retrieve the loaded data. We know it's a ByteArray, so let's cast it as well.
var data : ByteArray = loader.data as ByteArray;
// Use the ByteArray.readObject method to reconstruct the object.
var obj : Object = data.readObject();
// Cast the object and assign it to our data container.
var loadArrAll:ArrayCollection = obj as ArrayCollection;
}
The last line
var loadArrAll:ArrayCollection = obj as ArrayCollection;
this is the issue. I get the array collection but it has only a list of objects no images and no my class objects (although these are there but I found no way to convert this array collection in previous form when I serialized it.)
class that needs to be serialized/deserialised needs to implement flash.utils.IExternalizable.
public function readExternal(input:IDataInput):void - here you restore object
public function writeExternal(output:IDataOutput):void - here you saving object
best regards
Zain, you have to declare your classes like that:
package com
{
[RemoteClass]
public class myClass
{
public function myClass()
{
}
}
}