I am receiving an error to suggest that my URL is not found. I am running the below simple script from Flash Builder. As I understand the application launches from bin-debug directory within the main project folder.
I have a image folder also within the main project folder yet it will not find the image. It works when I type the full directory.
The code I have is:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.URLRequest;
[SWF(width="550", height="400", backgroundColor="#FFFFFF", frameRate="60")]
public class Kitties extends Sprite
{
//Declare the variables for the background.
public var backgroundURL: URLRequest;
public var backgroundLoader: Loader;
public var background: Sprite;
public function Kitties()
{
backgroundURL = new URLRequest();
backgroundLoader = new Loader();
background = new Sprite();
backgroundURL.url = "..\\images\\background.png";
backgroundLoader.load(backgroundURL);
background.addChild(backgroundLoader);
stage.addChild(background);
}
}
}
I understand I need to add an event listener to capture this error but for now it's not necessary as i know the file exists. Has anyone experienced this before?
Thank you.
You shouldn't use backslashes in actionscript3. Normal slashes work on every OS, even on Windows.
Try this:
backgroundURL.url = "../images/background.png";
If the file exists, it should load correctly.
Related
In my recent project, I need to get a file path where the user can specify/choose the file by using Dialog Box.
This is my code in order to do just that;
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.filesystem.File;
import flash.net.FileFilter;
import xlsxreader.Worksheet;
import xlsxreader.XLSXLoader;
public class MainClass extends MovieClip
{
var fileGet: File = new File();
var excel_loader: XLSXLoader = new XLSXLoader();
public function STRIMSMainClass()
{
var import_btn: MovieClip = MovieClip(root).powerButton_mc.utilitiesButton_mc;
import_btn.addEventListener(MouseEvent.CLICK, selectExcelFile);
fileGet = File.applicationDirectory;
fileGet.addEventListener(Event.CANCEL, fileCancel);
fileGet.addEventListener(Event.SELECT, fileSelect);
excel_loader.addEventListener(Event.COMPLETE, loadingComplete);
}
function selectExcelFile(e: MouseEvent): void
{
var fileFilter = new FileFilter("Select Excel File", "*.xls;*.xlsx;*.xlsm");
fileGet.browseForOpen("Select Excel File", [fileFilter]);
}
function fileCancel(e: Event): void
{}
function fileSelect(e: Event): void
{
excel_loader.load(fileGet.nativePath);
}
function loadingComplete(e: Event): void
{}
}
}
However, the published .exe file can not be open by my computer; it just flash and automatically close itself. I test the code before publish and it work just fine.
When I try to go through the code line by line, by delete this line var fileGet: File = new File() and obviously any line that associate with it, the .exe file can be open just fine.
I need filesystem.File for to get the .nativePath of the file that need to be open, so I can not exclude var fileGet: File = new File(). This also happen in my colleague's PC.
Please help me solve this weird error that happen right now. This is my first time trying to use Adobe Animate to develop software.
I decompiled a swf file using JPEXS Free Flash Decompiler v.10.0.0 , When i decompile the swf file I only see 2 scripts:
AppLoader
$gamename-web_sec$aba37a......
In the binaryData folder, there's a thing named:
DefineBinaryData(1:gamename-web_sec$aba37a........
Here's the tree of the decompiled swf:
gamename.swf
Headers
BinaryData
DefineBinaryData(1:gamename-websec$aba37a...
Frames
Scripts
AppLoader
$gamename-web_sec$aba37a...
inside the appLoader, here's the script:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
public class AppLoader extends Sprite
{
private var content:Class;
public function AppLoader()
{
content = §gamename-web_sec$aba37a95a98fb59f905d8915dbd77871-2007405621§;
super();
var loader:Loader = new Loader();
addChild(loader);
var ba:ByteArray = new content();
var bamod:ByteArray = new ByteArray();
bamod.writeBytes(ba,1,ba.length - 1);
loader.loadBytes(bamod,new LoaderContext(false,new ApplicationDomain()));
}
}
}
$gamename-web_sec$aba37a... actionscript:
package
{
import flash.utils.ByteArray;
public class §gamename-web_sec$aba37a95a98fb59f905d8915dbd77871-2007405621§ extends ByteArray
{
public function §chitchatcity-web_sec$aba37a95a98fb59f905d8915dbd77871-2007405621§()
{
super();
}
}
}
I see that It's loading the swf game with that BinaryData. When i try to export the bin file and try to load it again using JPEXS Flash Decompiler again. This what it shows,
[2744232]
header
shapes
sprites
binaryData
DefineBinaryData (51763)
DefineBinaryData (11730)
frames
others
ErrorTag
Unknown (ID=377)
Unknown (ID=909)
Unknown (ID=544)
...
Unknown (ID=879)
ErrorTag
Unknown (ID=777)
....
scripts
frame1
DoAction
It show's so many unknown objects in others folder.
Do P-code source: (because the actionscript source is blank)
Jump loc0005
loc0005:
Do you guys have an idea how will i able to decompile the swf file? I have a permission of the owner, and he wants me to decompile it, so we can better secure the game more.
I'm trying to load an image from the internet with AS3 following this tutorial. When I try to compile the application I get the following error:
Call a possibly undefined method load through a reference with static type Loader.
my_loader.load(where, loaderContext);
^
Here is the code I'm using:
package {
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.display.Loader;
import flash.events.*;
import flash.external.ExternalInterface;
import flash.display.Sprite;
public class Loader extends Sprite {
public function Loader() {
var where:URLRequest = new URLRequest("image_from_web.png");
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
var my_loader:Loader = new Loader();
my_loader.load(where, loaderContext);
addChild(my_loader);
}
}
}
In this page compilerErrors(ErrorCode = 1061) says that this occurs when I try to call a method that does not exist.
I'm using Ubuntu 14.10 and compiling with ProjectSprout that uses the flex compiler.
Your issue is namespace clashing (ambiguous class names). The class you've posted is called Loader, yet you try to import another Loader class. AS3 doesn't know what you refer to when you reference Loader now. So it is looking for a load method on your custom Loader class (which doesn't exist).
To resolve the issue, either rename your custom class to something less ambiguous (MyImageLoader maybe, or whatever) - or use the fully qualified class path when referring to the display package Loader. eg.
var my_loader:flash.display.Loader = new flash.display.Loader();
I rarely use sounds in AS3/Flash. I am using Flash Pro CS6, but I can't seem to figure out how to access, control (play, stop, etc) sounds embedded in an external SWF loaded into the main SWF.
It's easy to control them when embedded on the main swf. However, on an externally loaded SWR, I get all kinds of errors. For this app, I really need to embed them in the external SWF.
I read several solutions, but none seem to work.
I embed the sound an mp3 file called soundSegment1.mp3 using Flash CS6 import tool and then open the actionscript properties panel on flash to select the class name: SoundSegment1. Then I edit the class code and create a file called SoundSegment1.as and it's saved right next to my document class main.as in the same directory. The code of the SoundSegment1 class looks like this:
package {
import flash.media.*;
public class SoundSegment1 extends Sound
{
public function SoundSegment1 ()
{
// no code in here
}
public function playSound()
{
var soundSegment1:Sound = new SoundSegment1();
var channel:SoundChannel = soundSegment1.play();
}
}
}
Then, in my main.as, I have done several attempts to play this sound such as:
var fileLocation:URLRequest = new URLRequest(SWFToLoad);
loader.load(fileLocation);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);
loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
function initListener(e:Event):void // I also placed this code on the completeListener and it didn't work
{
loader.content.soundSegment1.playSound(); // doesn't work.
}
I get:
Line XXX 1061: Call to a possibly undefined method playSound through a reference with static type flash.display:DisplayObject.
or, I also read that I should be able to do something like this anywhere in the Main.as file:
var theClass:Class = Class(loader.content.getDefinitionByName("SoundSegment1"));
var theSound:theClass = new theClass();
theSound.play() //doesn't work either.
I also tried on the completeListener:
var TheClass:Class = e.target.applicationDomain.getDefinition("SoundSegment1") as Class;
var theSound:TheClass = new TheClass();
theSound.play() //doesn't work either.
I get:
ReferenceError: Error #1065: Variable SoundSegment1 is not defined.
at flash.system::ApplicationDomain/getDefinition()
I am stuck and I really need to get this to work. I would be genuinely grateful for your help.
Thank you in advance for any help provided. I really need to get it to work, because I can't simply embed them in the main SWF or load them individually externally one by one.
Thanks again!
user SnickelFritz from Kirupa gave me a fabulous answer with much easier code, which can be very powerful when using multiple sounds. This is just great, because you can use only one preloader per SWF, instead of having multiple loader for each file:
code for the main.as file
http://www.kirupa.com/forum/showthread.php?305098-Playing-a-embedded-sound-in-an-external-swf
package
{
import flash.display.*;
import flash.media.*;
import flash.events.*;
import flash.net.*;
public class Main extends MovieClip
{
var swf:MovieClip;
public function Main()
{
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
l.load( new URLRequest("child.swf") );
}
private function swfLoaded(e:Event):void
{
swf = e.target.content as MovieClip;
addChild(swf);
swf.playSound();
}
}
}
Code for the loaded swf "child.as"
package
{
import flash.display.*;
import flash.media.*;
import flash.events.*;
import flash.net.*;
public class Child extends MovieClip
{
private var s:Sound1;
private var sc:SoundChannel;
public function Child()
{
s = new Sound1();
sc = new SoundChannel();
// All of the following lines are actually optional, if all your graphic elements are already inside the swf prepared in flash pro
var g:Graphics = this.graphics;
g.beginFill(0x666666);
g.drawRect(0,0,550,400);
g.endFill();
}
public function playSound():void
{
sc = s.play();
}
}
}
User "kglad.com" on the Adobe Forums also gave me a good answer:
http://forums.adobe.com/message/5681137#5681137
I'm trying to load an external and local XML file to read its data, but I don't really know how to detect when the file has been loaded, I'm just able to open the broser window,
here is what I have done
package {
import flash.display.Sprite;
import flash.events.;
import flash.net.;
import flash.net.URLRequest;
public class cargadorXML extends Sprite {
public var cuadro:Sprite = new Sprite();
public function cargadorXML() {
cuadro.graphics.beginFill(0xFF0000);
cuadro.graphics.drawRoundRect(0,0,100,100,10);
cuadro.graphics.endFill();
cuadro.addEventListener(MouseEvent.CLICK,init);
addChild(cuadro);
}
public function init(e:Event) {
var file:FileReference;
file = new FileReference();
file.browse();
file.addEventListener(Event.COMPLETE,bien);
}
public function bien(e:Event) {
trace("cargado");
}
}
}
but no "cargado" message appears, also I don't really think the Event.COMPLETE is the correct event at all xD
could some one help me here??
thanks
done, it's Event.SELECT instead of Event.COMPLETE