Error Responce When Pinging A Website In Adobe Animate - actionscript-3

i am trying to ping a website in Adobe Animate and i'm not sure where I have mixed up. The current code I have is below- Any help is appreciated <3
What is is meant to do: ping a website on the click of a button with the instance name HotelA
(I have already got the crossdomain xml file)
Thank You
-Regards, A.
HotelA.addEventListener(MouseEvent.CLICK, doThePing);
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(HTTPStatusEvent.HTTP_STATUS, ldrStatus);
var url:String = "www.google.com.au";
function doThePing():void
{
ldr.load(new URLRequest(url));
}
function ldrStatus(evt:*):void
{
if(evt.status == 200)
{
doRedirect();
}
else
{
// there is an internet connection but the server returns something else (probably something is wrong with the server)
doFailedRedirect();
}
}
function doRedirect():void
{
gotoAndStop(1);
}
function doFailedRedirect():void
{
gotoAndStop(7);
}
The Error In "Output" I Am Seeing Is:
ArgumentError: Error #1063: Argument count mismatch on AssignTask_Working_fla::MainTimeline/doThePing(). Expected 0, got 1.

Add an input variable four your event listener function:
...
function doThePing(event:MouseEvent):void
{
ldr.load(new URLRequest(url));
}
...

Related

How to stop the song from playing in Action Script 3

I am trying to stop the song from playing when user clicks on a button, this is my code :
var mySound:MainSound = new MainSound();
var cmyChannel :SoundChannel;
animation_play.addEventListener(MouseEvent.CLICK, playSound);
function playSound(event:Event) {
mySound.play();
}
animation_stop.addEventListener(MouseEvent.CLICK, stopSound);
function stopSound(event:Event) {
mySound.stop();
}
animation_play.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);
function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
gotoAndPlay(2);
}
when i click on the animation_play object it works perfectly fine, it does as how it should be by playing the sound and starting the animation from the specified frame. however if i click on animation_stop object i get an error
TypeError: Error #1006: stop is not a function.
Anyone know how to go about fixing this ?
You need to set the mySound.play() to the cmyChannel object. Then call stop on cmyChannel. Here is the code:
var mySound:MainSound = new MainSound();
var cmyChannel :SoundChannel;
animation_play.addEventListener(MouseEvent.CLICK, playSound);
function playSound(event:Event) {
cmyChannel = mySound.play();
}
animation_stop.addEventListener(MouseEvent.CLICK, stopSound);
function stopSound(event:Event) {
cmyChannel.stop();
}
animation_play.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_3);
function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
{
gotoAndPlay(2);
}
To stop your sound, you have to use a SoundChannel object like this, for example :
function playSound(event:Event): void
{
cmyChannel = mySound.play();
}
and
function stopSound(event:Event): void
{
cmyChannel.stop();
}
Hope that can help.

cannot convert flash.display::Stage#2a2cdf99 to flash.display.MovieClip?

So I'm creating a platform game in Actionscript 3.0, trying to call a function that spawns blocks based on an array. The code is in a 'Game' class and is directed towards a movieclip on my .fla
When it is ran I get the error:
"cannot convert flash.display::Stage#2a2cdf99 to flash.display.MovieClip."
Here's the code:
public function GameScreen(stageRef:Stage = null )
{
this.stageRef = stageRef;
btnReturn.addEventListener(MouseEvent.MOUSE_DOWN, returnMainMenu, false, 0, true);
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
this.addEventListener(Event.ENTER_FRAME, createLvl);
this.stageRef.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
this.stageRef.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
this.stageRef.addChild(blockHolder);
}
And
private function createLvl(event:Event):void
{
var lvlArray:Array = MovieClip(root)['lvlArray' +lvlCurrent];
var lvlColumns:int = Math.ceil(lvlArray.length/16);
for(var i:int = 0;i<lvlArray.length;i++){
if(lvlArray[i] == 1){
if(i/lvlColumns == int(i/lvlColumns)){
row ++;
}
var newBlock:Block = new Block();
newBlock.graphics.beginFill(0xFFFFFF);
newBlock.graphics.drawRect(0,0,50,50);
newBlock.x = (i-(row-1)*lvlColumns)*newBlock.width;
newBlock.y = (row - 1)*newBlock.height;
blockHolder.addChild(newBlock);
} else if (lvlArray[i] == 'MAIN'){
mcMain.x = (i-(row-1)*lvlColumns)*newBlock.width;
mcMain.y = (row-1)*newBlock.height;
}
}
row = 0;
}
Please help =(
Thanks!
First of all:
Turn on "permit debugging" in your publish settings. This will give you line numbers with your errors, so you can determine the exact location of your error.
Post the entire stack trace. That error by itself is not a lot to go on.
Given the error and the code you've posted, the error must be caused by your use of MovieClip(root). The root property does not always point to the main timeline in Flash, it will point to the Stage if the display object is added directly to the stage. For example:
trace(stage.addChild(new Sprite()).root) // [object Stage]
Documentation on root: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#root

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

Shared Objects Send Method()

There appears to be an error in the Adobe documentation in regards using the shared object.send(). I am trying to execute the send method to all clients.
I copied the client and server-side code from Adobe and I am unable to invoke the function.
This is my compile error in the output
Line 31 1119: Access of possibly undefined property doSomething through a reference with static type flash.net:SharedObject.
Any suggestions how i can fix this to as3 novice. Please can anyone help me?
var nc:NetConnection = new NetConnection();
nc.connect("rtmfp://localhost/submitSend");
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
function netHandler(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Sucess":
trace("Connecting...");
break;
case "NetConnection.Connect.Failed":
trace("Unable to connect up");
break;
case "NetConnection.Connect.Rejected":
trace("Whoops");
break;
}
}
var so:SharedObject = SharedObject.getRemote("mySo", nc.uri, true);
so.connect(nc);
so.doSomething = function(str) {
// Process the str object.
};
Server side:
var so = SharedObject.get("mySo", true);
so.send("doSomething", "This is a test");
As said in my previous comment, a link to the document you're refering to would be welcome to help people helping you...
Here is already some points that ought to be mentionned:
You should add your event listeners before any call to connect().
You should connect your shared object only once you received the NetConnection.Connect.Success event (by the way, you have a typo in your sample on this name)
You should set you class instance as the client of your shared object.
I'm not sure all of this will fix your issue but you can try this:
var nc:NetConnection = new NetConnection();
private function netHandler(event:NetStatusEvent):void
{
switch(event.info.code)
{
case "NetConnection.Connect.Success":
{
trace("Connecting...");
connectSharedObject();
break;
}
case "NetConnection.Connect.Failed":
{
trace("Unable to connect up");
break;
}
case "NetConnection.Connect.Rejected":
{
trace("Whoops");
break;
}
}
}
private function connectSharedObject():void
{
var so:SharedObject = SharedObject.getRemote("mySo", nc.uri, true);
so.client = this;
so.connect(nc);
}
public function doSomething(str:String):void
{
// Process the str object.
}
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
nc.connect("rtmfp://localhost/submitSend");

Error #2007: Parameter hitTestObject must be non-null

this is my code- it's working and moving to frame 3 but everything is stuck there and I
get this Error #2007
function createMC(event:Event):void
{
var hasa_mc:MovieClip= new hasa();
stage.addChild(hasa_mc);
var halfMc:int=hasa_mc.width/2;
hasa_mc.x=randomNum(70+halfMc,480-halfMc);
hasa_mc.addEventListener(Event.ENTER_FRAME, abc);
hasa_mc.addEventListener(Event.ENTER_FRAME, dropCheckHit);
function dropCheckHit(event:Event):void
{
if (hasa_mc.hitTestObject(hauta1_mc)) {
hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
event.target.parent.removeChild(event.target);
countertime++;
score_txt.text=String(countertime*10)
if (countertime==10)
{
gotoAndStop(3);
}
The error code and description refers to the line:
if (hasa_mc.hitTestObject(hauta1_mc)) {
My guess would be the movieclip hauta1_mc does not exist on frame 3 of your movie, so once you go to frame 3 and your dropCheckHit function executes the null reference error is thrown.
To resolve you can remove the enter frame listener and stop checking if the movieclip has been hit:
if (countertime==10)
{
hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
gotoAndStop(3);
}
Note: You may need to remove the other listener you have on hasa_mc as well if hasa_mc does not exist in frame 3.
thank you. from where i need to remove also ? still does not works.
when it goes to frame 3 there is new MC that hit new object
function dropCheckHit(event:Event):void {
if (hasa_mc.hitTestObject(hauta1_mc)) {
hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
event.target.parent.removeChild(event.target);
countertime++;
score_txt.text=String(countertime*10)
if (countertime==10)
{
gotoAndStop(3);
hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
}
hauta1_mc.nextFrame();}
else if (hasa_mc.y > 380)
{
xdirection = 0;
ydirection = 0;
hasa_mc.x = 190;
hasa_mc.y = 200;
hauta1_mc.x=220;
lifeCounter--; //
life_txt.text=String(lifeCounter);
trace(lifeCounter);
if (lifeCounter==0)
{
gotoAndStop(5);
}
}
}
}