One of the parameters is invalid as3 - actionscript-3

How To Fix One of the parameters is invalid as3?
First click bitnmap to show maps = OK
Maps + closebtnmap => show ,btn maps => hide
click closebtnmap to hide maps = OK
Second click btnmap to show maps = ERORR
CODE:
import flash.media.StageWebView;
import flash.events.MouseEvent;
import flash.events.Event;
var _webView:StageWebView = new StageWebView();
btnmap.addEventListener(MouseEvent.MOUSE_UP, addWebView);
function addWebView(e:MouseEvent):void
{
_webView.viewPort = new Rectangle(0, 170, 480,510);
_webView.stage = this.stage;
_webView.loadURL("https://goo.gl/maps/b6lMB");
btnclosemap.visible =true;
btnclosemap.addEventListener(MouseEvent.CLICK, closeWebView);
}
function closeWebView(e:MouseEvent):void
{
_webView.stage = null;
_webView.dispose();
btnclosemap.visible =false;
}
ERROR :
ArgumentError: Error #2004: One of the parameters is invalid.
at flash.media::StageWebView/set viewPort()
at sanggaluri_fla::plokasi_27/addWebView()[sanggaluri_fla.plokasi_27::frame1:29]

Your issue is likely because in the closeWebView method, you dispose the StageWebView called _webView.
So now, when you click a second time and addWebView runs, you try to set it's viewport, but the web view has been disposed and so it throws the error.
To make it work, create a new StageWebView inside your addWebView method.
So:
var _webView:StageWebView; //don't instantiate it here
btnmap.addEventListener(MouseEvent.MOUSE_UP, addWebView);
btnclosemap.addEventListener(MouseEvent.CLICK, closeWebView);
function addWebView(e:MouseEvent):void
{
if(!_webView){
_webView = new StageWebView(); //Create a new one here if it doesn't exist / is null
}
_webView.viewPort = new Rectangle(0, 170, 480,510);
_webView.stage = this.stage;
_webView.loadURL("https://goo.gl/maps/b6lMB");
btnclosemap.visible =true;
}
function closeWebView(e:MouseEvent):void
{
_webView.stage = null;
_webView.dispose();
_webView = null; //make it null so you know it's been disposed
btnclosemap.visible =false;
}

Related

Adobe Animate CC to PHP

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

Why is my action script event not firing?

Presently, I am attempting to add the ability to capture all the slides of a presentation to images and save them to disk. It works now where the first page is capture, then I want an async event to fire when the second page has loaded to capture that page, and so on. Here is where I have added an event listener, though I'm not sure if I should be using stage or this:
import flash.events.Event;
private var jpgEncoder:JPGEncoder;
// ...
private function init():void{
// ...
// Add async event to capture second page after loading
stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
// ...
}
private function onPrintButtonClicked():void {
// screen capture code
jpgEncoder = new JPGEncoder(90);
// Page 1 capture
bitmapData1 = new BitmapData(stage.width, stage.height);
bitmapData1.draw(stage, new Matrix());
// move to next page
var curPage:Page = PresentationModel.getInstance().getCurrentPage();
if (curPage != null) {
LOGGER.debug("Go to next page. Current page [{0}]", [curPage.id]);
pageCount++;
dispatchEvent(new GoToNextPageCommand(curPage.id));
} else {
LOGGER.debug("Go to next page. CanNOT find current page.");
}
}
private function onLoadComplete(e:Event)
{
// Get page 2 capture
bitmapData2 = new BitmapData(stage.width, stage.height);
bitmapData2.draw(stage, new Matrix());
// Copy two pages to one bitmap
var rect1:Rectangle = new Rectangle(0, 0, stage.width, stage.height);
var pt1:Point = new Point(0, 0);
bitmapData3 = new BitmapData(stage.width, stage.height * 2);
bitmapData3.copyPixels(bitmapData1, rect1, pt1)
var rect2:Rectangle = new Rectangle(0, 0, stage.width, stage.height);
var pt2:Point = new Point(0, stage.height);
bitmapData3.copyPixels(bitmapData2, rect2, pt2)
// Convert to image
var img:ByteArray = jpgEncoder.encode(bitmapData3);
var file:FileReference = new FileReference();
file.save(img, "capture1.jpg");
}
Does anyone have any ideas as to why the OnLoadComplete function is never called? FYI, here is the full source code: https://github.com/john1726/bigbluebutton/blob/master/bigbluebutton-client/src/org/bigbluebutton/main/views/MainToolbar.mxml
TIA
Please note that I've found that the stage was still null in the init() method so an exception was being thrown:
stage.loaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
Also, after resolving that stage error I found that I have been receiving this error using this tool: https://github.com/capilkey/Vizzy-Flash-Tracer
Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.
So the solution is either to re-work the UI so that there is a button press to prepare the files and a second button press to actually save the image or setup them mouseup and mousedown events to call different functions:
s:Button mouseDown="prepare_PDF()" mouseUp="save_PDF()"
Source: Flex's FileReference.save() can only be called in a user event handler -- how can I get around this?
Thank you!

How to use remote SharedObject in AS3 and Red5

I wish to use remote SharedObject so I created a simple script to test out the techniques. When I ran the following code as two instances of SWF, both instances output 1, which was incorrect because the second instance was supposed to output 2.
import flash.net.SharedObject;
import flash.events.SyncEvent;
var nc:NetConnection;
var so:SharedObject;
nc = new NetConnection();
nc.client = { onBWDone: function():void{} };
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://localhost:1935/live");
var t = new TextField();
addChild(t);
function onNetStatus(event:NetStatusEvent):void{
if(event.info.code == "NetConnection.Connect.Success"){
so = SharedObject.getRemote("shObj",nc.uri);
so.connect(nc);
if (!(so.data.total > 0 && so.data.total<1000)) {// undefined
so.data.total=1;
} else so.data.total=2;
t.text=so.data.total;
}
}
Did I miss out something? Do I need to make some special settings to Flash or Red5? Do I need to create a special directory? Must I use a special event listener? Could anyone correct the code for me?
(09 Apr 2014)
When I used an event listener like the following, I got a blank screen for both instances, which was strange because I expected at least the second screen to show '2'. Can someone explain the behavior?
import flash.net.SharedObject;
import flash.events.SyncEvent;
var nc:NetConnection;
var so:SharedObject;
nc = new NetConnection();
nc.client = { onBWDone: function():void{} };
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://localhost:1935/live");
var t = new TextField();
addChild(t);
function onNetStatus(event:NetStatusEvent):void{
if(event.info.code == "NetConnection.Connect.Success"){
so = SharedObject.getRemote("shObj",nc.uri);
so.addEventListener(SyncEvent.SYNC,syncHandler);
so.connect(nc);
so.setProperty("total",2);
}
}
function syncHandler(event:SyncEvent):void{
if (so.data.total) {
t.text = so.data.total;
}
}
Basically for the use of Shared Objects, I would recommend splitting the job into three seperate parts.
Attach Event Listener and connect to the Shared Object
function onNetStatus(event:NetStatusEvent):void
{
if(event.info.code == "NetConnection.Connect.Success")
{
so = SharedObject.getRemote("shObj",nc.uri);
so.addEventListener(SyncEvent.SYNC,syncHandler); //add event listener for Shared Object
so.connect(nc);
}
}
Complete the Event Handler method to reflect changes in the value of Shared Object
/* This function is called whenever there is change in Shared Object data */
function syncHandler(event:SyncEvent):void
{
if(so.data.total) //if total field exists in the Shared Object
trace(so.data.total);
}
Change the data in Shared Object:
Use the setProperty method of Shared Object here. Invoke this method when you need to change the value (maybe at button click or on occurrence of certain Event)
/* This function writes values to the Shared Object */
function changeValue(newValue:String)
{
so.setProperty("total",newValue);
}

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!!

Error #1009: Cannot access a property or method of a null object reference

Working on this Flash AS3 application and I am keep getting this error when I try to make an imgLoader clickable.
The imgLoader is a dynamic loader which will load an image from XML file and its created using ActionScript.
This is the full error I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at apptest_fla::MainTimeline/frame1()[apptest_fla.MainTimeline::frame1:65]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
and this is the code for making the imgLoader clickable:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
anyone knows why this is happening?
EDIT
This is my entire code:
stop();
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.filters.DropShadowFilter;
var xmlLoader11:URLLoader;
var xml11:XML;
var uRequest11 = new URLRequest("my.xml");
xmlLoader11 = new URLLoader(uRequest11);
xmlLoader11.addEventListener(Event.COMPLETE, onXMLLoad11);
var imgLoader11:Loader;
var nameLoader11:Loader;
var myString11:String = 'loading';
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
}
function onImgLoaded11(e:Event) {
addChild(imgLoader11);
imgLoader11.height = 300;
imgLoader11.width = 300;
var bitmapContent11:Bitmap = Bitmap( e.target.content );
bitmapContent11.smoothing = true;
addChild( bitmapContent11 );
bitmapContent11.height = 150;
bitmapContent11.width = 150;
bitmapContent11.y = 65;
bitmapContent11.x = 85;
}
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
Does it break when this is called:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
or when this is called:
nextFrame()
In the first case, imgLoader is null. In the second case, something you're trying to acess fields or methods of right after nextFrame() is called is null.
EDIT:
Try moving this:
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
to the bottom of onXMLLoad11().
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
}