fl.transitions.Tween not found on ActionScript Mobile project - actionscript-3

I'm developing an ActionScript mobile project for Android.
When I add the following import, compiler says that is not found.
import fl.transitions.Tween;
How can I use Tween with mobile projects?
package{
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.Strong;
public class spriteButton extends Sprite
{
private var alphaOver:Tween;
private var alphaLabelOver:Tween;
private var alphaLabel:Tween;
public function spriteButton(newLabel:String)
{
myLabel.text = newLabel;
myLabelOver.text = newLabel;
myLabelOver.alpha = 0;
buttonMode = true;
mouseChildren = false;
addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut);
addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
}
By the way, I'm very new on ActionScript 3.0 development.
I get this errors:
The import fl could not be found.
The import Tween could not be found.
Description Resource Path Location Type
1172: Definition fl.transitions:Tween could not be found. spriteButton.as /Test01/src line 4 Flex Problem

if you are new to AS3, then use this library: http://www.greensock.com/tweenmax/ for tweenning objects.

Related

actionscript 3 - error #1009 Cannot access a property or method of a null object reference

I've only recently started using as so sorry for this
as its probably pretty simple. Im basically trying to spawn an AI unit but am getting the error 1009, here is the full error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at code::Init()[D:\FlashGame\code\Init.as:21]
Im trying to use a function from another class which is in another file. Here is the first file.
package code
{
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.MouseEvent;
import flash.text.TextField;
import code.functions.AIManager;
public class Init extends MovieClip
{
private var _AI:AIManager;
private var _player:MovieClip;
public function Init()
{
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
_AI.createAI();
}
public function enterFrameHandler(event:Event):void
{}
}
}
And the second file..
package code.functions
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.DisplayObjectContainer;
public class AIManager extends MovieClip
{
private var _ai:MovieClip;
public function AIManager()
{
createAI();
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
public function createAI():void
{
_ai = new AI();
_ai.x = stage.stageWidth / 2;
_ai.y = stage.stageHeight / 2;
stage.addChild(_ai);
}
You need to create an instance of a class before you can use it's methods. The exception to that is static methods. In your case you just need to use new AIManager
_AI = new AIManager();
_AI.createAI();

Converting ActionScript 3 FLA’s to HTML5 canvas FLA’s in Flash cs6

Hi there,
i have doubt about converting .fla files to html5 canvas. i am developing the project by using Action script version 3 but now i want that project on html5 canvas for the browser compatibility and other issues to be solved..
Anyone help me to solve the issue
I am trying Swiffy Extension and CreateJS tools. But the code was not linking properly because am using action script and also i don't know how to linking files from one to another.. please anyone help me to solve the issues.
Example .FLA code:
package com.privacy_pirates.game {
//import all the Flash libraries we will need
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.utils.Timer;
import flash.utils.*;
public class Main extends MovieClip{
//all the onjects that are on the stage that will need to be called
public var content_mc:MovieClip;
public var introLoader:Loader;
public var tutotrialLoader:Loader;
public var preloader_mc:Preloader;
public var btn_play:MovieClip;
public function Main() {
// constructor code
//when the class is added to the stage
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
public function addedToStage(e:Event):void{
//trace("added to stage is executing");
removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
//the swf that will be loaded
introLoader = new Loader();
//when it's ready, perform the function loadComplete
introLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
//make the preloader
introLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
//the file that will be loaded
introLoader.load(new URLRequest("Animation.swf"));
}
private function loadComplete(e:Event):void{
//trace("load is complete");
//add the file to the stage
addChild(introLoader);
}
//the progress bar at the bottom of the screen
private function loadProgress(e:ProgressEvent):void{
var percent:Number = e.bytesLoaded / e.bytesTotal;
preloader_mc.setPercent(percent);
}
}
}

Flash workers - sample application not working

I'm trying to get the hang of the AS3 workers, but there must be some elusive bit of understanding that just escapes me.
I've build a fairly simple PoC to see how it should work, but with no luck. When I run the "master" SWF, it seems to load the worker SWF fine and goes through everything without a hitch, except there's no response from the bloody worker.
I'm using Flash Builder 4.6 with FlexSDK 4.9.1, the PoC projects are built as ActionScript projects.
The worker file:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.system.MessageChannel;
import flash.system.Worker;
public class WorkerPOC extends Sprite
{
private var wToM:MessageChannel;
private var mToW:MessageChannel;
public function WorkerPOC()
{
wToM = Worker.current.getSharedProperty("wToM") as MessageChannel;
mToW = Worker.current.getSharedProperty("mToW") as MessageChannel;
trace(mToW.receive());
wToM.send("Ready");
}
}
}
The master file:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.system.MessageChannel;
import flash.system.Worker;
import flash.system.WorkerDomain;
import flash.utils.ByteArray;
public class WorkerMaster extends Sprite
{
private var workerLoader:URLLoader;
private var workerData:ByteArray;
private var worker:Worker;
private var wToM:MessageChannel;
private var mToW:MessageChannel;
public function WorkerMaster()
{
workerLoader = new URLLoader();
workerLoader.dataFormat = URLLoaderDataFormat.BINARY;
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function onAdded(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
workerLoader.addEventListener(Event.COMPLETE, onHasWorker);
workerLoader.load(new URLRequest("workers/WorkerPOC.swf"));
}
private function onHasWorker(event:Event):void
{
workerData = workerLoader.data as ByteArray;
workerData.shareable = true;
worker = WorkerDomain.current.createWorker(workerData);
wToM = worker.createMessageChannel(Worker.current);
wToM.addEventListener(Event.CHANNEL_MESSAGE, onMessage);
wToM.addEventListener(Event.CHANNEL_STATE, onState);
mToW = Worker.current.createMessageChannel(worker);
worker.setSharedProperty("wToM",wToM);
worker.setSharedProperty("mToW",mToW);
worker.start();
mToW.send(123);
}
private function onState(event:Event):void
{
trace("Channel state: ", wToM.state);
}
private function onMessage(event:Event):void
{
trace(wToM.receive());
}
}
}
I've been working with workers as well. I had them working for a while then everything kinda just stopped, in the same way yours is not working.
Looks like the messagechannel is not sending the messages properly in debug in 11.7.
Not sure why it is happening, but try running your code without the debugger attached when the worker is created. When I do that it works fine...
Sounds strange, but have you applied
-swf-verion=XXX // XXX must be > 17
as a compiler argument? I am asking this, because I had a very similar problem :)
Workers in Apache Flex 4.7

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;

ActionScript play audio

I am just trying to make a simple .swf file that plays a piece of audio when it loads. This compiles but when I bring it up into the browser nothing happens. I could only find sprite based tutorials so I took a stab that you can extend Sound the same way as you would extend Sprite. The final version is going to be headless and called my Java Script to play audio on Events.
package {
import flash.media.Sound;
import flash.net.URLRequest;
public class typeRight extends Sound {
public function HelloWorld( ) {
load(new URLRequest('./sound.mp3'));
play();
}
}
}
I am NOT working in Flash so please no GUI advice ; )
Rather than subclassing the Sound class, create a document class like this that contains a Sound class in it:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
public class SoundPlayer extends Sprite
{
protected var _sound : Sound;
protected var _channel : SoundChannel;
public function SoundPlayer()
{
_sound = new Sound();
_sound.addEventListener(Event.COMPLETE, soundLoadCompleteHandler);
_sound.addEventListener(IOErrorEvent.IO_ERROR, loadError);
_sound.load(new URLRequest("./sound.mp3"));
}
protected function soundLoadCompleteHandler(evt : Event) : void
{
// Use the _channel object to control sound properties such as pan and volume.
_channel = _sound.play();
}
protected function loadError(evt : IOErrorEvent) : void
{
trace ("ERROR :: " + evt);
// You could try recovering from the error here.
}
}
}