Game assets not loading in Kongregate - actionscript-3

I just created my first game, and am having some problems. I uploaded to Kongregate(but didn't publish yet), and in the preview the external files(music and three pictures) don't load. The rest of the game works fine.
If I try to change it so there is a zip with the assets in it and change the directory in the code, it falls apart.
I'm using FlashDevelop, so everything is programatic. I noticed the swf is only a few kb large, so is there anyway to compile the assets into the swf file and load them that way, or do I need to do something else?
Please help, and thanks in advance.

Ok, let me explain then. Lets assume you have your main module game.swf that loads some image asset.jpg from the same folder. You test it locally, it works just fine. You put game.html, game.swf and asset.jpg on your site http://niamke.com/ and it still works. Then you publish your game as http://kongregate.com/games/niamke/myniamkegame/ and it suddenly stops loading asset.jpg.
Why
HTTP requests from Flash Player are handled via browser. So the browser gets a request for "asset.jpg" from Flash Plugin instance. There could be all kinds of content (including several Flash Apps) from several different domains within one page, so browser does not bother to figure the correct address out, and plainly tries to load in relatively to the topmost HTML document, basically http://kongregate.com/games/niamke/myniamkegame/asset.jpg which is not there.
How to avoid it
You should create a small piece of code that figures the correct URLs for the files you load. As soon as your content attached to Stage, any display object can access the loaderInfo object which contains the absolute SWF URL.
Usage
Files.parseURL(loaderInfo.url);
var aLoader:Loader = new Loader;
var aRequest:URLRequest = new URLRequest(Files.baseUrl + "asset.jpg");
Loader.load(aRequest);
Implementation
package
{
public class Files
{
// Long live Bill Gates and Windows and backslashes.
static public function figureSlash(value:String):String
{
var aSplit:Array = value.split("/");
var oSplit:Array = value.split("\\");
return (aSplit.length >= oSplit.length)? "/": "\\";
}
static public var baseUrl:String;
static public var systemSlash:String;
// Supposed to dissect the SWF url in order to
// process relative resource file urls properly.
static public function parseURL(value:String):void
{
// Figure correct slash.
systemSlash = figureSlash(value);
// Split SWF URL into Array and remove SWF name.
var aSplit:Array = value.split(systemSlash);
aSplit[aSplit.length - 1] = "";
// Obtain the SWF root folder.
baseUrl = aSplit.join(systemSlash);
}
}
}

A comment brought me to the conclusion below:
"I just linked the URLRequest to where the files were hosted online."

Related

Using the standard gamePad code, not finding sound files even though the path name is correct?

Using the standard gamePad code, not finding sound files even though the path name is correct?
I have definitely researched this question. For sure, I have found code on SO claiming to solve this dilemma, but this published code doesn't.
I am successfully finding the sound file using Preview under BBEdit's "Markup" Menu. But, the oh-oh surfaces when running my game on my commercial Server.
I am even successful when using keypress code is activated -- local on my Mac and on the Server.
The failure is when I am using the external Server to run my gamePad code to find the sound file when all my source code is loaded onto my Server. In this case, the sound does not play.
FILE HIERARCHY
games folder
Game_1 folder
game1.html
Game_Support folder
audio folder
js folder
HTML
<body onload="doBodyOnLoad()">
JS:
function doBodyOnLoad() {
$(document).ready(function() {
// ... //
}); // $(document).ready
} // doBodyOnload
function setupKeypresses() {
$(document).keydown(function(evt) {
let code = evt.keyCode || evt.which;
// for example:
if (code === "R")
{
movePaddleRight(); // this will call ouch() below
}
});
} // setupKeypresses
function PlaySound(id, src) {
let theSound = new Audio();
theSound.src = src;
theSound.play();
} // PlaySound
function ouch() {
updateScore(--thisScore);
// even the absolute path doesn't work ?
// var theSnd = "http://lovesongforever.com/games/Game_1/Game_1_Support/audio/explosion.mp3";
var theSnd = "Game_1_Support/audio/explosion.mp3";
PlaySound("audioPlaceHolder", theSnd);
// fade either the whole Board (okay), or just the Paddle (not! so much)
doFade("#gameBoard"); // doFade("#gameBoard > #gamePaddle") [not ready for Prime Time]
} // ouch
Thanks bunches for your patience with me!
This is because you're trying to autoplay an Audio element without user interaction to initiate the audio.
Firefox expresses a blocked play() call to JavaScript by rejecting the promise returned by HTMLMediaElement.play() with a NotAllowedError. All major browsers which block autoplay express a blocked play via this mechanism. In general, the advice for web authors when calling HTMLMediaElement.play(), is to not assume that calls to play() will always succeed, and to always handle the promise returned by play() being rejected.
https://hacks.mozilla.org/2019/02/firefox-66-to-block-automatically-playing-audible-video-and-audio/
I think it will work if you click or tap on the page first. Gamepad button presses may work for this too depending on the implementation.

display only a specific content in AS3 code using webStage View

I'd like to display, in my app, only a part of a web page.
On this website, I'd like to display, in my app, only the div id "MovieCart".
What should I write in my as3 code in order to do so ?
For now, I have this line :
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
But, of course, it's displaying the fullwebpage.
EDIT
So, I've tried this :
webView.addEventListener(Event.COMPLETE,onComplete);
var res : String = ExternalInterface.call("function(){return document.getElementById('movieCart').outerHTML}");
var urlOfMovie: URLRequest = new URLRequest("http://www.cinecity.nc/Cinecity/Film/40567");
var loaderMovie:URLLoader = new URLLoader();
loaderMovie.load(urlOfMovie);
webView.loadString(res);
But, as it's an AIR app, ExternalInterface.call can't be call. Any idea ?
Here is one easy way you can accomplish this:
//First, load the full page as you're currently doing:
webView.addEventListener(Event.COMPLETE, webLoadComplete); //listen for when the load is finished
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
//runs when the load finishes
function webLoadComplete(e:Event):void {
webView.removeEventListener(Event.COMPLETE, webLoadComplete); //stop listening
//second, invoke the following Javascript on the page which assigns the `MovieCart` element as the html for the whole document body
webView.loadURL("javascript:document.body.innerHTML = document.getElementById("MovieCart").outerHTML");
}
Disclaimer:
Keep in mind that scrapping content from websites is generally frowned upon and you may be infringing on peoples work/copyrights by doing so.

How to auto load URL through SWF banner in the background?

I am new here just signed up and I did not find information on how to classify this topic on specific section.
I am using adobe flash professional to create a small banner to auto load one of my own URL for analytics. Is this possible? I found one solution on another user's topic which was (AS 3):
var req:URLRequest("http://your_request");
var loader:URLLoader = new URLLoader ();
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(req);
private function onLoadComplete(ev:Event):void
{
var result:String = ev.target.data;
}
But this doesn't seem to work. How can I test that the full webpage is loaded 'invisibly' in the background? If "http://your_request" has cookies for example, I can check if the cookies were created, but I do not know if with this method I'll load the cookies to check if this is working at the first place.
There is no way to get http-cookies natively. But you can do this with a js-helper-function and an ExternalInterface.call. See this answer: How do I access cookies within Flash?

Recording using Flex/Flash

I know that we can not record/Access anything out of flash player, because of it's security sandbox.
Instead We can record the video while streaming it to server.
like
netStream.publish("YourFileName.flv","record");
But in recorde file, I will get only a video file Published by webcam to server and i want to record entire session.
Is there any way to record it locally, or Can i record the window ??
p.s. : I am not trying to access anything outside of flash player.
Thanks in advance...
ok, so you can record the entire contents of the swf like this:
first, create a container object (anything that extends DisplayObject which implements IBitmapDrawable) then place everything that you want to capture (video view and everything else in your "session") then using an ENTER_FRAME event or Timer (preferable to control capture fps), draw the container to a BitmapData using BitmapData.draw(container). Pass that BitmapData to the FLV encode library found here using it's addFrame() method (docs and examples come with that library... super easy) and that's it! When you are done, you will have an flv video containing a frame by frame "screen capture" of what was going on in your swf! Just make sure EVERYTHING is in the container! That lib also accepts captured audio too if you want.
private function startCapturing():void{
flvEncoder.start(); // see the libs docs and examples
var timer:Timer = new Timer(1000/15); //capture at 15 fps
timer.addEventListener(TimerEvent.Timer, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void{
var screenCap:BitmapData = new BitmapData(container.width, container.height);
screenCap.draw(container);
flvEncoder.addFrame(screenCap); // see the libs docs and examples
}

AS3 POST png to PHP

Have read many similar but no solutions: I'm trying to do something (that i think is) really simple,
Take a photo from gallery or camera - and POST this to a URL. No saving / returning to application. The PNG is just used by the webpage in display and user moves onward.
public function postPicture():void {
PNGEncoder2.level = CompressionLevel.FAST;
var encoder : PNGEncoder2 = PNGEncoder2.encodeAsync(_bitmapData);
encoder.targetFPS = 12;
encoder.addEventListener(Event.COMPLETE, function (e):void {
var png : ByteArray = encoder.png;
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("https://myurl.com/mypage");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = png;
navigateToURL(jpgURLRequest, "_blank");
});
}
Also to note, we're getting some odd characters on the end of the URL: C9%90NG
Hunch is that I'm decoding and then not encoding properly before sending i.e. these characters some part of raw image info.
When I test from chrome POST extension with another image, server side stuff works fine so guessing a problem with AS3.
basically its working when I use chrome to browse > my.png and POST it at the page. Am I missing something with the AS3 png encoder? i.e. how to turn that bmpdata into a 'file' rather than an array of bytes.
thankyou
You need to use multipart upload. It's a common situation with a well defined standards for that. You can implement it by yourself but it will take some time and efforts.
What I've used before is the Multipart URLLoader Class provided by Eugene Zatepyakin, one the best Flash guru's out there :)
It's some kind of old but does the job extremely well. You can add variables, files, whatever content you want to your loader and simply submit it. There are examples with the php side of the thing so you can understand what's going on.