1180: Call to a possibly undefined method loaderInfo action script error - actionscript-3

I am a newbie in flash. I want to test passing variables to swf file using flashvars, then I had been creating a action script file with name "test_adver.as". I use this file in the fla file as class document. This is the code of "test_adver.as":
package src{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import flash.text.TextField;
public class test_adver extends MovieClip {
public function test_adver() {
try {
var param:Object=loaderInfo(this.root.loaderInfo).parameters;
} catch (error:Error) {
trace("Loading failed");
}
}
}
}
But when I run the code, the output displays "1180: Call to a possibly undefined method loaderInfo action script error". I try debug an hours but cannot fix this issue. help me. Please! Sorry my English is not good.

It should be a lot more simple. You are trying to request loaderInfo property, but for this you don't even need type casting.
var param:Object=this.root.loaderInfo.parameters;

You did everything right except the below
var param:Object = LoaderInfo(this.root.loaderInfo).parameters;
Yes, there should be caps "L". It is enough to import LoaderInfo class for flashvars.

Related

Actionscript3 setting time delay

trying to make a time delay before redirection to a specific web page , I got many errors during the compiling process , sorry new to actionscript :
package
{
import flash.display.*;
import flash.net.*;
import flash.system.*;
import flash.utils.*;
import flash.events.*;
public class test extends flash.display.Sprite
{
public function test()
{
super();
flash.net.navigateToURL(new flash.net.URLRequest("http://youpassed-theexam.com/congrats"), "_self");
return;
}
}
setInterval(test,5000);
}
A couple of issues with your code:
Constructors of classes are immediately called once the class is
instantiated. You should create a separate method and call that with
a delay from within your constructor.
setInterval would fire repeatedly after every set interval. You
should rather use setTimeout.
Classes should have a Sentence caps naming convention, so Test and not test. Just a best practice. Nothing wrong syntactically.
Constructors do not return anything so we do not need the return statement.
Once you have imported a class, you do not need to write the full name of the class to access it's methods.
Try to avoid * based import statements. It does tend to import a lot more classes than just the required class. Again, just a best practice.
So your code should look something like this below:
package
{
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.utils.setInterval;
import flash.utils.setTimeout;
public class Test extends flash.display.Sprite
{
public function Test()
{
super();
setTimeout(gotoURL, 5000);
}
protected function gotoURL():void
{
navigateToURL(new URLRequest("http://youpassed-theexam.com/congrats"), "_self");
}
}
}
Hope this helps. Cheers.

AS3 can't find the load method on a Loader

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

AS3 Error Call to a possibly undefined method for Underline Function

i have a problem with AS3.
I want to call Underline() method (movie clip class) in my code but there is error.
Here is the error:
1180: Call to a possibly undefined method Underline.
Here is the code:
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.filesystem.*;
import flash.data.*;
import flash.errors.*;
import flash.utils.Timer;
var underline:MovieClip = new Underline();
underline.x = tempText.x + tempText.width / 3;
underline.y = tempText.y + tempText.height / 2 + 5;
textContainer.addChild(underline);
This code works on AS2 but doesn't work on AS3
What is the solution?? Please help, this problem drive me crazy"
As GoldRoger said, Underline here is a class, and must inherit the MovieClip class (extend). Also, when you are creating a new class, there must be a constructor function with the EXACT same name as the class.
For example:
public class Underline extends MovieClip
{
public function Underline()
{
//constructor code, initialize here
}
}

Casting a loaded SWF as an interface

I'm trying to load in a remote SWF and access it's methods and properties, using an interface. (There's a similar question here that got as far as "that's weird!" but didn't resolve it: Loading swf and using it through interface)
My remote SWF looks like this:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.system.Security;
import IMultiplayer;
[SWF(width="238", height="60", frameRate="60", backgroundColor="#FFFFFF")]
public class Main extends Sprite implements IMultiplayer
{
public function init(e:Event):void
{
}
public function TEST():void
{
trace("TEST()");
}
}
}
I then have an interface that looks like this:
package
{
import flash.events.*;
import flash.display.*;
public interface IMultiplayer
{
function init(e:Event):void;
function TEST():void;
}
}
And finally, I've got a loader class that pulls down the SWF and tries to cast it as the same interface that the remote SWF implements. EDIT - apologies for length, was asked to post the full source:
package uk.co.MyDomain
{
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.TimerEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.system.SecurityDomain;
import flash.utils.Timer;
import uk.co.MyDomain.*;
import utils.Console;
public class MultiplayerLoader extends Sprite
{
private var ld:Loader;
private var _environment:String;
public var _mpInstance:IMultiplayer;
private const SANDBOX_SWF:String = "http://static.sandbox.dev.MyDomain.co.uk/smartfoxtest/dev/swf/MP.swf";
public function MultiplayerLoader(environment:String)
{
_environment = environment;
}
public function loadMultiplayer():void
{
ld = new Loader();
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
ld.contentLoaderInfo.addEventListener(Event.COMPLETE, multiplayerLoaded);
ld.contentLoaderInfo.addEventListener(ErrorEvent.ERROR, onLoadError);
ld.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOLoadError);
ld.contentLoaderInfo.addEventListener(IOErrorEvent.DISK_ERROR, onDiskError);
ld.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onNetworkError);
ld.contentLoaderInfo.addEventListener(IOErrorEvent.VERIFY_ERROR, onVerifyError);
if(Security.sandboxType == Security.REMOTE)
{
trace('[MP Loader] Loading with context');
ld.load(new URLRequest(SANDBOX_SWF), context);
}
else
{
trace('[MP Loader] Loading with NO context');
ld.load(new URLRequest(SANDBOX_SWF));
}
}
private function onIOLoadError(e:IOErrorEvent):void
{
notifyFailure('IOLoadError');
}
private function onDiskError(e:IOErrorEvent):void
{
notifyFailure('IOLoadError');
}
private function onNetworkError(e:IOErrorEvent):void
{
notifyFailure('IOLoadError');
}
private function onVerifyError(e:IOErrorEvent):void
{
notifyFailure('IOLoadError');
}
private function onLoadError(e:ErrorEvent):void
{
notifyFailure('IOLoadError');
}
private function multiplayerLoaded(e:Event):void
{
var tester:IMultiplayer = e.currentTarget.content as IMultiplayer;
Console.log('Loaded: ' + tester);
dispatchEvent(new MultiplayerEvent(MultiplayerEvent.SWF_LOAD_SUCCESS));
}
private function notifyFailure(reason:String):void
{
var failEvent:MultiplayerEvent = new MultiplayerEvent(MultiplayerEvent.SWF_LOAD_FAILURE);
failEvent.params = {'reason':reason}
dispatchEvent(failEvent);
}
}
}
Now, if I DON'T cast it to use the interface, I can trace it out successfully and call functions (so e.target.content.TEST() will fire). However, as soon as I cast it to the interface, it fails.
Any ideas?
EDIT
OK, I'm getting the same issue with a custom event class that's shared between both applications. Flash errors, saying it cannot convert from one class to the other - even though they're identical they're in different projects, and so I imagine different namespaces. I assumed that loading into the same applicationDomain would fix this, but it hasn't. Is there any other way I can get around this without resorting to a common library/SWC or similar?
I think this might be an issue of the application domain. The loaded SWF resides in its own application domain so it does not share the exact same interface. Try to load the swf into the »current application domain«, using the applicationDomainproperty of the Loader's LoaderInfo Object.
look here
good luck…
EDIT::
it has to be done in the loaders load method
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
var loader:Loader = new Loader();
loader.load(new URLRequest("myButtons.swf"), context);
from here
EDIT 2::
Once I ran into an even more strange error, it was caused by the fact that i created an interface, compiled the »to load files« and »file that loaded«, changed the interface through adding a method and forgot to compile the »to load files« (there were a lot). Perhaps happened something like this…
EDIT 3::
If I remember right than one has to wait for the Event.INIT event of loaded swf's, first after this event the constructor of the loaded swf ran.
EDIT 4::
found this, perhaps you need to do:
var YourInterfaceClass:Class = ApplicationDomain.currentDomain.getDefinition( "YourInterface" ) as Class;
var myInstance:YourINterface = event.target.content as YourInterface;

Link to URL in AS3

I have a URL link at the end of a Flash 5.5 file that does not work. I have the following code in AS3. I do not get an error message when I save the SWF.
import flash.events.*;
import flash.display.*;
//import flash.ui.Keyboard;
var weblinkURL:String = "http://www.optiosolutions.com";
weblink_btn.addEventListener(MouseEvent.CLICK, webLink);
function webLink(e:Event):void {
var request:URLRequest = new URLRequest(weblinkURL);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
I pasted your code in a new Flash project, and this works as it should! Nothing seems to be wrong... So I would advice you to look at your other code...
You are sure that the button id weblink_btn is the correct button id of the button you suppose it to be?
One small tip:
import flash.events.*;
import flash.display.*;
It's not really needed to import with a *, since you are working on a KeyFrame, these imports can be forgotten.
In general you should never import with *, but only the classes that are needed.