If You Are Migrating From AS2
If you are migrating from AS2 to AS3 and would like to learn the differences between the language without reading long documentation here is your link. http://livedocs.adobe.com/flex/201/l...migration.html
I accidentally came by this today on Adobe's site. I wish I had this resource a few months ago instead of learning everything the hard way
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 11-13-2007, 07:45 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Migrating From MX To CS3
Dear all,
Is there any differences how the flash handles xml socket connection in MX and CS3 ? I tried to published MX file using CS3 and always got an error.
Thanks
[CS3] Migrating AS From 2 To 3
I used to be able to use this code in Flash 8 - AS2:
Code:
for (i in this) {
if (this[i] instanceof Button) {
trace(this[i]._name);
}
}
However in Flash CS3 using AS3 it does not work.
I need to use AS3 because I want control over the components I'm using.
Can anyone help me migrate this script from AS2 to AS3?
Migrating To AS 3.0?
In AS 2 I had something like this:
loadMovie(_parent.nextMovie + ".swf", "_parent.container");
I'm trying to figure out what the equivalent would be in AS 3?
The variable for nextMovie is stored in the parent clip. And, the code above is in the clip that has been loaded into a container on the stage.
Thanks in advance!
Migrating To AS3 From AS2
Hi,
I want to start coding in AS3. I am familiar to AS2 codes.
Can you please advise how do I migrate to AS3. Say I have a puzzle with all its function done in AS2. Can we literally translate the same in AS3.
Please advise
Migrating From AS2 To AS3
Hi,
I have this code in AS2:
for (i=1; i<=4; i++) {
main.nav["bttn_"+i].onRelease = function() {
for (i=1; i<=4; i++) {
otherButtons = eval("this._parent.bttn_"+i);
var f:Fuse = new Fuse();
f.easing = "easeInOutExpo";
f.duration = .5;
f.push([{target:otherButtons.letters, tint:0xE64D38, percent:100});
f.start();
}
var bttnNum = this._name.substr(-1,1);
var f:Fuse = new Fuse();
f.easing = "easeOutBounce";
f.duration = 2;
f.push({target:this.letters, tint:0x35352F, percent:100, seconds:0});
f.push([{target:main.loaderMC, visible:false, seconds:0}, {func:unloadMC, seconds:0}]);
f.push([{target:main.loaderMC, visible:true, seconds:0}, {func:loadMC, seconds:0}]);
f.start();
function unloadMC(){
main.loaderMC.unloadMovie();
}
function loadMC(){
main.loaderMC.loadMovie("SWF/ext_movie_"+bttnNum+".swf");
}
this.enabled = false;
lastClicked.enabled = true;
lastClicked = this;
}
}
That's what I have in AS3 so far:
//Navigation buttons
for (var i:uint = 1; i <= 4; i++) {
main.nav["bttn_"+i].addEventListener(MouseEvent.CLICK, onClick);
main.nav["bttn_"+i].addEventListener(MouseEvent.ROLL_OVER, onRollover);
main.nav["bttn_"+i].addEventListener(MouseEvent.ROLL_OUT, onRollout);
main.nav["bttn_"+i].buttonMode = true;
}
function onClick(e:MouseEvent):void
{
var bttnNum = parseInt(e.target.name.substring(5));
var loadMC = function()
{
loader.load(new URLRequest("SWF/ext_movie_"+bttnNum+".swf"));
}
Tweener.addTween(["here I need to reference other buttons].letters, {_color:0x35352F, time:.5, transition:"easeInOutExpo"});
}
//Nav buttons rollover
function onRollover(e:MouseEvent):void
{
Tweener.addTween([here I need to reference button that is rolled over].letters, {_color:0x35352F, time:.5, transition:"easeInOutExpo"});
}
function onRollout(e:MouseEvent):void
{
Tweener.addTween([here I need to reference button that is rolled out].letters, {_color:0x35352F, time:.5, transition:"easeInOutExpo"});
}
I suck on:
1) How to reference other buttons
2) How to reference the button that was clicked/rolled over
3) Seemingly at random external clip will not load (traces NaN)
Very very new to Action scripting to AS3 in particular.
Edited: 12/09/2008 at 10:28:10 PM by igreck
Migrating From AS1.0 To 2.0
How would I convert this statement:
Code:
MovieClip.prototype.move = function (racingTrack) {
//
}
to the AS2.0 equivalent?
Migrating From AS1.0 To 2.0
How would I convert this statement:
Code:
MovieClip.prototype.move = function (racingTrack) {
//
}
to the AS2.0 equivalent?
AS3 - Migrating To AS3
I am looking to move to AS3 because I saw really good functionalities - Video full screen, 3D stuff (Papervision)...etc.
However, I am having a hard time switching or finding substitute for what I'm using. I use OOP designs in my script and a lot of FuseKit. I have the following question
1) Is there any good online tutorials for migration?
2) Is the any AS3 book good for people like me( trying to migrate)?
3) Any good Papervision 3D tutorials?
4) I'm a fan of Fuse Kit and I know "Go" is still under beta/development. What is a good substitute that works in both AS2 and AS3?
5) Any good extensions for AS3 that I need to know?
Exactly Why And How Will I Be Migrating To AS3?
Hi there.
Right now, I'm learning the more interesting aspects of AS2, and I'm teaching the basics to my colleagues. After reading the long list of changes coming round the bend, I'm worried that I might just be wasting my peers' time.
For the record, my experiments with the DisplacementMapFilter during the past week have been the only times that I've imported any kind of class from anywhere. I'm still slightly fazed by having to work with multiple documents, though I'm sure I'll get around to OOP eventually. So I might benefit later from AS3's new, "more real" OOP feel, assuming that I can successfully make the transition so soon after learning 2.0. Is this the only benefit I'll have for my effort to relearn Actionscript?
The aforementioned list also says that some of my favorite methods, like removeMovieClip() and attachMovie(), will be replaced with something else, for some reason that apparently goes way over my head. These are essential to my current AS2 projects, and I have a feeling that, if I want to migrate them (small though they may be) to AS3, I'd have to make some drastic changes.
This is a big deal! I'd like to know how this migration is more than a nuisance to non-OOP developers and beginners. And, what resources can a person at my level use to successfully migrate without too much heartbreak?
Migrating To V2 Components
Hi all,
I've very basic problem using the v2 components, to be precise. the TextArea component..
I'm attaching a sample file, but let me explain what I'm trying to get.
I've created an object (scrollv2) that contains a TextArea compoenent (with instance name dyntext).
In the main scene, I'have a movieclips: scrolltextV2 that is instance of scrolv2.
Code for scrolltextV2:
onClipEvent (load) {
stop();
}
onClipEvent (data) {
nextFrame();
//dyntext.text=this[_root.vtext];
dyntext.text="just try with a simple assignment";
}
as you can see the code is very simple.
The main actionscript is the following:
loadvariables("testi/prova.txt",scrolltextV2);
scrolltextV2.gotoAndStop(1);
Do not care about the loading of the external text: my main problem is that, even if I assign a static text to the "dyntext" object, it is not displayed (note that while text i snot displayed, I can enter dynamic text correctly ...)
I know I've been too much confusing, but it will be very easy to have look at the code in the sample file ....
Thanks in advance
*pimar
Please I Need Some Help With OnEnterFrame, Migrating From As2 To As3
Hello everyone,
I ve been working with as2 since quite a while, but I am starting to learn as3.
Thing is that I have a client who wants me to add some "flasheff" into a banner I did some time ago. What happens is that the banner has been done using as2, but in order to use flasheff component I need to use as3. So i wanted to transform it into a as3 file, it is quite simple stuff and If someone can give me a hand on this that'll be great, thanks
here is my acual as2 code:
//solutions_mc, open* //this is the onenterframe function that will be triggered underneath with rollover and rollout buttons.
solutions_mc.onEnterFrame = function(){
if (mouse_over_solutions_mc) {
solutions_mc.nextFrame();
} else {
solutions_mc.prevFrame();
}
}
//invisible button*open
inv2_btn.onRollOver = function (){
mouse_over_solutions_mc = true;
banner_mc.gotoAndPlay("solutions");
}
inv2_btn.onRollOut = function(){
mouse_over_solutions_mc = false;
}
//closes solutions button
this is what ive done so far:
//opens solutions button
function onEnterFrame(event:Event):void {
if (mouse_over_solutions_mc) {
solutions_mc.nextFrame();
} else {
solutions_mc.prevFrame();
}
}
inv1_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
inv1_btn.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function mouseOver(e:MouseEvent):void{
mouse_over_solutions_mc = true;
banner_mc.gotoAndPlay("company");
}
function mouseOut(e:MouseEvent):void{
mouse_over_solutions_mc = false;
}
//closes solutions button
I am not getting errors in the rollover and rollout buttons, so I think there is something wrong in the onenterframe function,
I am getting this errors when published under as3
1 description: access of undefined property mouse_over_solutions_mc
source: if (mouse_over_solutions_mc) {
2 description: access of undefined property mouse_over_solutions_mc
source: mouse_over_solutions_mc = true;
3 description: access of undefined property mouse_over_solutions_mc
source: mouse_over_solutions_mc = false;
Migrating From Pc To Mac...query
Hi Folks....
Just a little query about Flash on Macs. I've just moved from pc to mac. Does anybody know if you can lock all the pallets and toolbars down like you can on a pc if you are using flash on a mac?
All these silly little floating panels getting in the way are getting on my nerves!! anybody would think that Flash is an Adobe app!
I suspect its just the way Flash is presented in OSX...but there might be a little trick to it?
Migrating Some Code
Hi everyone,
I'm trying to make a polaroid, hanging to a wire, that flips a little on roll over in AS3.
I found a script that makes it perfectly in AS2:
onClipEvent (load)
{
K = 1.000000E-001;
a = 120;
C = 3.000000E-001;
v = random(5);
}
onClipEvent (enterFrame)
{
a = -K * (this._rotation - a) - C * v;
v = v + a;
this._rotation = this._rotation + v;
}
and the button inside
on (rollOver)
{
a = a + 30;
}
I'd love to make it in AS3, but I really can't figure out how to "translate". Can someone help me?
Pretty please.
Thanks!
Migrating MovieClipLoader
Hello Everyone,
I am migrating a project from ActionScript 2.0 but I have ran into and error that has me questioning my direction and/or methods. Basically, I want to load one or more SWF/JPEGS into MovieClips whoes reference is saved into an Array so that I can cycle through them.
The main functions are
ActionScript Code:
private function getScenes ()
{
fTracer("getScenes () {");
var i:Number = -1;
while (++i < _lngth) {
_mClip = new Object ();
_loader = new Loader ();
_url = _array[i];
_urlReq = new URLRequest(_url);
fTracer(" _mClip: " + _mClip);
fTracer(" _loader: " + _loader);
fTracer(" _url: " + _url);
fTracer(" _urlReq: " + _urlReq);
addChild(_loader);
_loader.load(_urlReq);
_loader.contentLoaderInfo.addEventListener(Event.INIT, sceneLoaded);
fTracer("");
}
fTracer("}");
}
private function sceneLoaded (event:Event)
{
fTracer("initScene () {");
fTracer(" _loader: " + _loader);
_mClip = _loader.content;
fTracer(" _mClip: " + _mClip);
_mcs.push(_mClip);
fTracer(" _mcs: " + _mcs);
fTracer("}");
}
So what I am trying to do inside sceneLoaded is simply push the _loader reference into an Array so I can then rotate them.
Thoughts? Questions?
I just want an array to cycle through using the Tween Class as the transition
Migrating From ActionScript 2.0 To 3.0
Hello, and apologies for the previous non-specific posts.
I am working with a project generously provided by J.R. Graphics, which replicates the look & behavior of the Mac OS X dock. I need to update this very slick work to 3.0 because I'll eventually be replacing the provided icons with ones that have dynamic text fields populated via XML files. I have the XML loader working and providing data just fine. The problem I'm having is with the dock functionality.
Specifically, at runtime, I'm getting TypeError #1009, which apparently means I'm trying to reference something in the script that hasn't been loaded yet. Below you will find the code of the main fla file (called "navigation2.fla"), the Dock.as file, and the error in detail.
Navigation2.fla - dock behavior code:
ActionScript Code:
stage.scaleMode = 'noScale';
function dockActions(label) {
switch (label) {
case 'Preferences' :
trace('Actions here to handle Preferences.');
break;
case 'Blog' :
trace('Actions here to handle Blog.');
break;
case 'Forum' :
trace('Actions here to handle Forum.');
break;
default :
trace('Default action here.');
}
}
var dockTemplate:Dock = new Dock('0', 128, 32, 128, 2, null, null, null);
this.addChild(dockTemplate);
dockTemplate.x = stage.width / 2;
dockTemplate.y = stage.height;
dockTemplate.addEventListener(MouseEvent.CLICK, dockActions, false, 0, true);
dockTemplate.itemCount.push({data: 'settings', label: 'Preferences'});
dockTemplate.itemCount.push({data: 'blog', label: 'Blog' });
dockTemplate.itemCount.push({data: 'forum', label: 'Forum'});
dockTemplate.itemCount.push({data: 'shop', label: 'Store' });
dockTemplate.itemCount.push({data: 'support', label: 'Tech Support' });
dockTemplate.itemCount.push({data: 'search', label: 'Search Archives' });
dockTemplate.itemCount.push({data: 'contact', label: 'Contact Us' });
dockTemplate.itemCount.push({data: 'trash', label: 'Trash' });
Dock.as:
ActionScript Code:
package {
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
public class Dock extends MovieClip {
var icon_min : Number;
var icon_max : Number;
var icon_size : Number;
var icon_spacing : Number;
var span : Number;
var amplitude : Number;
var ratio : Number;
var scale : Number = Number.NEGATIVE_INFINITY;
var trend : Number = 0;
var mouse_x : Number;
var mouse_y : Number;
var layout : String;
public var itemCount: Array;
var mc : MovieClip;
var tray : MovieClip;
public function Dock(layout:String, icon_size:Number, icon_min:Number, icon_max:Number, icon_spacing:Number, span:Number, amplitude:Number, ratio:Number):void {
this.layout = this.layout ? this.layout : 'bottom';
this.icon_min = this.icon_min ? this.icon_min : 32;
this.icon_max = this.icon_max ? this.icon_max : 96;
this.icon_spacing = this.icon_spacing ? this.icon_spacing : 2;
this.span = this.span ? this.span : getSpan();
this.amplitude = this.amplitude ? this.amplitude : getAmplitude();
this.ratio = Math.PI / 2 / this.span;
setLayout();
createIcons();
createTray();
addEventListener(Event.ENTER_FRAME, monitorDock);
}
public function getSpan():Number {
return (this.icon_min - 16) * (240 - 60) / (96 - 16) + 60;
}
public function getAmplitude():Number {
return 2 * (this.icon_max - this.icon_min + this.icon_spacing);
}
public function createIcons():void {
var i:Number;
var id:String;
this.scale = 0;
this.width = (this.itemCount.length - 1) * this.icon_spacing + this.itemCount.length * this.icon_min;
var left:Number = (this.icon_min - this.width) / 2;
for(i = 0; i < this.itemCount.length; i++) {
mc = new this.itemCount[i].id();
this.itemCount[i].mc.y = -this.icon_size / 2;
this.itemCount[i].mc.rotation = -this.rotation;
this.itemCount[i].x = this[i].x = left + i * (this.icon_min + this.icon_spacing) + this.icon_spacing / 2;
this.itemCount[i].y = -this.icon_spacing;
this[i].addEventListener(MouseEvent.CLICK, launchIcon, false, 0, true);
this.itemCount[i].useHandCursor = false;
this.itemCount[i].addChild(mc);
}
}
public function createTray():void {
var height:Number = this.icon_min + 2 * this.icon_spacing;
var width:Number = this.width + 2 * this.icon_spacing;
tray = new MovieClip();
tray.lineStyle(0, 0xcccccc, 80);
tray.beginFill(0xe8e8e8, 50);
tray.lineTo(0, -height);
tray.lineTo(width, -height);
tray.lineTo(width, 0);
tray.lineTo(0, 0);
tray.endFill();
this.addChild(tray);
}
public function setLayout():void {
switch(this.layout) {
case 'left':
this.rotation = 90;
break;
case 'top':
this.rotation = 180;
break;
case 'right':
this.rotation = 270;
break;
default:
this.rotation = Number(this.layout);
}
}
public function checkBoundary():Boolean {
var buffer:Number = 4 * this.scale;
return (this.mouse_y < 0)
&& (this.mouse_y > -2 * this.icon_spacing - this.icon_min + (this.icon_min - this.icon_max) * this.scale)
&& (this.mouse_x > this[0].x - this[0]._width / 2 - this.icon_spacing - buffer)
&& (this.mouse_x < this[this.itemCount.length - 1].x + this[this.itemCount.length - 1].width / 2 + this.icon_spacing + buffer);
}
public function updateTray():void {
var x:Number;
var w:Number;
x = this[0]._x - this[0].width / 2 - this.icon_spacing;
w = this[this.itemCount.length - 1].x + this[this.itemCount.length - 1].width / 2 + this.icon_spacing;
this['tray_mc'].x = x;
this['tray_mc'].width = w - x;
}
public function monitorDock(evt:Event):Boolean {
var i:Number;
var x:Number;
var dx:Number;
var dim:Number;
// Mouse did not move and Dock is not between states. Skip rest of the block.
if((this.mouse_x == this.mouseX) && (this.mouse_y == this.mouseY) && ((this.scale <= 0.01) || (this.scale >= 0.99))) { return false; }
// Mouse moved or Dock is between states. Update Dock.
this.mouse_x = this.mouseX;
this.mouse_y = this.mouseY;
// Ensure that inflation does not change direction.
this.trend = (this.trend == 0 ) ? (checkBoundary() ? 0.25 : -0.25) : (this.trend);
this.scale += this.trend;
if( (this.scale < 0.02) || (this.scale > 0.98) ) { this.trend = 0; }
// Actual scale is in the range of 0..1
this.scale = Math.min(1, Math.max(0, this.scale));
// Hard stuff. Calculating position and scale of individual icons.
for(i = 0; i < this.itemCount.length; i++) {
dx = this[i].x - this.mouse_x;
dx = Math.min(Math.max(dx, -this.span), this.span);
dim = this.icon_min + (this.icon_max - this.icon_min) * Math.cos(dx * this.ratio) * (Math.abs(dx) > this.span ? 0 : 1) * this.scale;
this[i].x = this[i].x + this.scale * this.amplitude * Math.sin(dx * this.ratio);
this[i].scaleX = this[i].scaleY = 100 * dim / this.icon_size;
}
// Resize tray to contain icons.
updateTray();
return true;
}
}
}
Error code given at runtime:
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Dock/createIcons()
at Dock$iinit()
at Dock_fla::MainTimeline/Dock_fla::frame1()
Any help you could provide will be greatly appreciated. Thanks in advance!
Migrating From Actionscript 2.0
It would be very helpful for me to see an example of a fla with its as files of a simple website developed on Actionscript 3.0 to see how it is organized.
I find it difficult to move from my actionscript 2.0 site with procedural programming to oop with Actionscript 3.0 despite the excellent books I have :
Learning Actionscript 3.0
Essential actionscript 3.0
Thank you for your help.
marcello
Migrating From Actionscript 1.0
I like the style I've developed in Actionscript 1.0. I use a lot of this:
_root.myMC["myVariable"+(eval("a"+i))]=eval("s"+i);
I've been doing some tests, still in AS 1 and have learned that just putting my var i in the [] does not work. I assume because I did not define an array object hence the term I've learned to call this is simulated array.
How do I define my variables in MX? Why define at all? Just for a faster compile? Or just because it's the law damn it!
Help With Migrating Issue AS3 To AS2
Hi all , im havin problem migrating my 90% done codes in AS3.0 to AS2.0 because of the lack of webservices support for AS3.0 . can someone help mi with the following conversion of codes ?
Red2_mc.addEventListener("mouseDown", pieceMove);
Red3_mc.addEventListener("mouseDown", pieceMove);
Red2_mc.addEventListener("mouseUp", pieceMove);
Red3_mc.addEventListener("mouseUp", pieceMove);
function pieceMove(evt : Event):void {
if (evt.type == "mouseDown") {
evt.target.startDrag();
evt.target.parent.addChild(evt.target);
startX = evt.target.x;
startY = evt.target.y;
for (var q :Number = 0; q<beingDragged.length; q++) {
if (Math.abs(startX - beingDraggedquote:.x) == 52 && Math.abs(startY - beingDraggedquote:.y)==0 || (Math.abs(startX - beingDraggedquote:.x) == 26 && Math.abs(startY - beingDraggedquote:.y )== 39)) {
canJump = 1;
}
}
} else if (evt.type == "mouseUp") {
evt.target.stopDrag();
and :
var gameStartTime:uint;
var gameTime:uint;
var gameTimeField:TextField;
gameTimeField = new TextField();
gameTimeField.x = 1;
gameTimeField.y = 1;
gameTimeField.scaleX = 1.5;
gameTimeField.scaleY = 1.5;
addChild(gameTimeField);
gameStartTime = getTimer();
gameTime = 0;
addEventListener(Event.ENTER_FRAME,showTime);
function showTime(event:Event) {
gameTime = getTimer()-gameStartTime;
gameTimeField.text = "Time lapsed: "+clockTime(gameTime);
}
function clockTime(ms:int) {
var seconds:int = Math.floor(ms/1000);
var minutes:int = Math.floor(seconds/60);
seconds -= minutes*60;
var timeString:String = minutes+":"+String(seconds+100).substr(1,2);
return timeString;
}
thanks in advance ...
Migrating AS2 Code To AS3
ORIGINAL AS1 SCRIPT
I have already tried several ways to migrate this code, but I get unexpected behaviors. Can any one help me?
The volume control on the stage is made out of two movieClips: one called knob and the other volume_track over which the knob slides (is dragged by user) This two Clips are turned into one movieClip called volume_control. The Sound Object is within an Empty MovieClip called soundMc. the pos variable gathers the knob's position on the volume_track.
The following code is the original one, which works perfectly.
Attach Code
//VOLUME CONTROL
this._parent.volume_control.knob.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volume_track._width, this._y);
this.onEnterFrame = function() {
var pos = (this._x/this._parent.volume_track._width)*100;
this._parent._parent.soundMc.soundObj.setVolume(pos);
};
};
this._parent.volume_control.knob.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
this._parent.volume_control.knob.onReleaseOutside = function() {
stopDrag();
};
};
/*-----------------------------------------------------
This is my attempt to convert it to AS3
I am not using a movieClip to hold the sound object, so I know that part of the code is not necessary and I don't think I need to reference the TimeLine either. Instead of the setVolume() method, I need to use the SoundTransform Class to modify the volume and the Rectangle Class to get the startDrag bounds, but I don't know how to put all this together. Any thoughts on this? Thanks */
var url:String = "MySound.mp3";
var request:URLRequest = new URLRequest(url);
var soundObj:Sound = new Sound();
var channel:SoundChannel;
soundObj.load(request);
var transform:SoundTransform = new SoundTransform( );
transform.volume = .5;
channel.soundTransform = transform;
channel = soundObj.play();
volume_control.knob.addEventListener(MouseEvent.MOUSE_DOWN, dragVolumeKnob ).
function dragVolumeKnob (Event:MouseEvent):void {
startDrag(this, true, 0, this._y, this._parent.volume_track._width, this._y);
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame (e:Event) {
var pos = (this._x/this._parent.volume_track._width)*100;
this._parent._parent.sound_mc.soundObj.setVolume(pos);
}
vol_knob.addEventListener(MouseEvent.MOUSE_UP, dragNotVolumeKnob);
vol_knob.addEventListener(MouseEvent.MOUSE_OUT, dragNotVolumeKnob);
}
function dragNotVolumeKnob(Event:MouseEvent):void {
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
stopDrag();
}
Sorry about the mess, I am a new at this
Tip For Migrating From Key.isDown()
AS2 had a nice but odd function called Key.isDown(n), which would return true if the key with keyCode n was down. This worked very nicely, but didn't fit with AS3's new event model. Now Key.isDown() is gone, and its sleek functionality has gone with it.
However, I have a recommendation for designing your code when it determines which keys are down. By implementing this design, code that previously relied on Key.isDown() can be transitioned pretty easily to AS3, and IMO this will keep your AS3 a little neater.
Somewhere in your code, put together the following:
ActionScript Code:
var keysDown:Array = [];stage.focus = stage;stage.addEventListener(KeyboardEvent.KEY_DOWN);stage.addEventListener(KeyboardEvent.KEY_UP);function addKey(event:KeyboardEvent):void { keysDown[event.keyCode] = true;}function removeKey(event:KeyboardEvent):void { keysDown[event.keyCode] = false;}// here's how you'd implement it:var timer:Timer = new Timer(25);timer.addEventListener(TimerEvent.TIMER, tick);function tick(event:Event):void { // old way- if (Key.isDown(Key.RIGHT)) { if (keysDown[Keyboard.RIGHT]) { trace("right key is down!"); } // etc.}
By storing the states of all the keyboard's keys in the keysDown array, any key's current up/down state can be determined by any code that can access keysDown.
Note that, due to a bug in Flash Player 8.5 and below, this code can be run in AS2, but doesn't run well. For AS2, I would recommend always using Key.isDown(), and for AS3, use a system like the one above.
Migrating From AS 2.0 Eval()
How can i do this:
PHP Code:
var o:Object = new Object();o.a = new Object();o.a.b = "A";trace(eval("o.a.b")); // Outputs: A
in AS 3.0 ?
Migrating From Flash Player 6 To 7
Firstly I would like to say Hi to everyone! As this is my first post on Flash Kit (sorry if I have made any mistakes in this thread).
I am currently trying to move an existing turning page brochure script for my website from Flash Player 6 on to Flash Player 7. There are several features I would like to utilize from Flash Player 7 that 6 does not feature.
My best plan of attack was to export my current code to Flash Player 7 to see the results I get. Unfortunatly its not good! The turning page brochure code no longer functions correctly and im finding it hard to fix on my own...
After reading around on the web I have detemined that a mixture of lowercase and uppercase is a no no, so I have changed variables, functions etc. to lowercase accordingly (of which the code works perfect with FP6). Yet I still have problems...
I have also read that there are code problems by which undefine is returned, but I am not experienced enough to find the problems inside my code. (newbie?!)
Can you please take a look and help me find out where my problem lies? Please find attached a 4-page brochure I am trying to convert. The code itself sits inside the Bound Pages movie clip (1st frame Actions layer) on the librarys root and/or the Scene 1 stage (Book layer, pages instance).
Any help would be appreciated and I am sure I can come in handy to help others!
Migrating From Root To Stage
Hello, I am trying to update my actionscript to 3.0, here is a compiler error that I got when trying to publish:
Warning: 1058: Migration issue: The property _root is no longer supported. This property has been removed. The closest equivalent is the Stage, which serves as the root of the ActionScript 3.0 display list..
Here is the code that has problems:
Code:
picLoader.load(new URLRequest("pic.jpg", _root.tmbONE.picTMBone));
how would I update this to actionscript 3.0?
Migrating Code For Beginners
Hello everyone,
I'm new to actionscript 3.0, and I have some scripts in 2.0 that I would like to migrate, but I don't even know where to start. This is one of the examples.
_root.c = new Array();
for (var i = 0; i<11; i++) {
_root.c.push(random(0xffffff));
}
_root.v = 10;
onMouseDown = function() {
play();
}
stop();
This is the result of that code link
Thank you again for your valuable help!
Migrating From 2.0 To 3.0: Associative Arrays
Could someone please tell me why this code doesn't work. I am simply trying to create an array of the keys wit aIndices and also trying to trace the value of map_zone_3
I'm sure its something simple for you AS 3.0 gurus but I am just making the transition and the migration guide only shows how everything makes use of classes.
ActionScript Code:
var aMapLayers:Array = new Array();
aMapLayers:Array['map_frame'] = false;
aMapLayers:Array['map_scale'] = false;
aMapLayers:Array['map_latLongNumbers'] = false;
aMapLayers:Array['map_timeZoneNumbers'] = false;
aMapLayers:Array['map_oceanNames'] = false;
aMapLayers:Array['map_countryName'] = false;
aMapLayers:Array['map_nationalCapitals'] = false;
var aIndices:Array = aMapLayers.sort(Array.RETURNINDEXEDARRAY);
trace(_root.aMapLayers['map_zone_3']);
trace(aIndices);
Migrating .as 'tooltip' File, To .xml?
Just revising a tooltip stage. It's happily using an external .as file to load the title and body text into an mc, but I would like to be able to make edits without republishing the main movie each time.
Any suggestions?
Does anyone have a sample file I could see, or a tutorial I could follow?
Thank you!
Migrating From Flash Player 6 To 7
Firstly I would like to say Hi to everyone! As this is my first post on the Dev Shed Forums (sorry if I have made any mistakes in this thread).
I am currently trying to move an existing turning page brochure script for my website from Flash Player 6 on to Flash Player 7. There are several features I would like to utilize from Flash Player 7 that 6 does not feature.
My best plan of attack was to export my current code to Flash Player 7 to see the results I get. Unfortunatly its not good! The turning page brochure code no longer functions correctly and im finding it hard to fix on my own...
After reading around on the web I have detemined that a mixture of lowercase and uppercase is a no no, so I have changed variables, functions etc. to lowercase accordingly (of which the code works perfect with FP6). Yet I still have problems...
I have also read that there are code problems by which undefine is returned, but I am not experienced enough to find the problems inside my code. (newbie?!)
Can you please take a look and help me find out where my problem lies? Please see below a chunk of code from a 4-page brochure I am trying to convert.
Code:
stop();
function iii() {
pw = 480; // page width
ph = 648; // page height
pc = 0xffffff; // page colour
mp = 4; // number of pages - be sure to assign print clips in library a linkage identifier
as = .8; // autostep - how fast pages turn when autoflipping (0 to 1)
sn = .002; // snap - how close to laying flat the page needs to be before a flip is considered done (0 to 1)
dr = .4; // drag - how smooth the page will move when being dragged by hand or autoFlipping (0 to 1)
da = 30; // dragadvance - positions the corner buttons (in pixels)
sy = _y;
pwh = pw+ph;
py = ph/2+pw;
dd = 1;
vr = -1;
enp = 2.5;
cp = .5;
drg = false;
attachMovie("cb", "brb", 110);
attachMovie("cb", "trb", 111);
attachMovie("cb", "blb", 120);
attachMovie("cb", "tlb", 121);
blb._xscale = tlb._xscale=-100;
tlb._yscale = trb._yscale=-100;
brb._x = trb._x=pw;
blb._x = tlb._x=-pw;
blb._visible = tlb._visible=false;
pi(enp, dd, vr);
srp.removeMovieClip();
}
function mm() {
this.createEmptyMovieClip("fbpm", 70);
with (fbpm) {
beginfill(0x005500, 100);
lineto(pwh, -vr*pwh);
curveto(0, -vr*2*pwh, -pwh, -vr*pwh);
lineto(0, 0);
endfill();
}
fbpm.duplicateMovieClip("ftpm", 80);
this.createEmptyMovieClip("fsm", 90);
dp(fsm, -dd, vr);
fsm._rotation = vr*dd*90;
this.createEmptyMovieClip("ssm", 100);
dp(ssm, dd, vr);
fbp.setMask(fbpm);
ftp.setMask(ftpm);
fs.setMask(fsm);
ss.setMask(ssm);
}
function l01(rrr) {
return (rrr>1 ? 1 : rrr<0 ? 0 : rrr);
}
function mse(t, xq, yq) {
with (t) {
var c = [0, 0, 0, 0, 0, 0, 0];
var a = [40, 25, 15, 5, 0, 1, 6];
var ra = [0, 1, 17, 51, 89, 132, 255];
var m = {matrixType:"box", x:0, y:-yq*pw, w:xq*pw, h:-yq*ph, r:0};
begingradientfill("linear", c, a, ra, m);
moveto(0, -pw*yq);
lineto(0, -pwh*yq);
lineto(xq*pw, -pwh*yq);
lineto(xq*pw, -pw*yq);
lineto(0, -pw*yq);
endfill();
}
}
function ggr() {
if (drg) {
mrO = -dd*(_xmouse-startx-(dd*da))/(2*pw);
} else {
mrO>2/3 ? mrO += as : mrO -= as;
}
return (l01(mrO));
}
function safp(enp, dd) {
pi(enp, dd, vr);
startx = dd*pw;
brb._visible = blb._visible=trb._visible=tlb._visible=0;
pro = 0;
fff(Odr);
onEnterFrame = function () {
fa(l01(pro += as));
};
cp = enp;
}
function sb() {
var m = -vr*(pw+ph/2);
var e = (ph/2);
brb._y = blb._y=m+e;
trb._y = tlb._y=m-e;
}
function fa(goalr) {
step = (goalr-Odr)*dr;
Odr += step;
fff(Odr);
if (Odr>1-sn) {
fff(1);
fd();
if (afg) {
if (cp != eafp) {
safp(cp+daf*2, daf);
} else {
afg = false;
}
}
}
}
iii();
function turnto(enp) {
if (enp != cp) {
if (!onEnterFrame) {
var d = enp>cp ? 1 : -1;
safp(enp, d);
}
}
}
function flipto(targpage) {
if (targpage>cp) {
daf = 1;
} else if (targpage<cp) {
daf = -1;
} else {
return;
}
afg = true;
eafp = targpage;
safp(cp+daf*2, daf);
}
function dp(t, xq, yq) {
with (t) {
beginfill(pc, 100);
moveto(0, -yq*pw);
lineto(0, -yq*pwh);
lineto(xq*pw, -yq*pwh);
lineto(xq*pw, -yq*pw);
endfill();
}
}
function fff(cv) {
var r = vr*dd*45*cv;
fbpm._rotation = ftpm._rotation=-r;
fbp._rotation = fsm._rotation=vr*(dd*90)-r*2;
fs._rotation = ss._rotation=vr*(dd*45)-r;
}
function fd() {
onEnterFrame = null;
Odr = 0;
brb._alpha = blb._alpha=trb._alpha=tlb._alpha=100;
if (cp != .5) {
blb._visible = tlb._visible=true;
} else {
blb._visible = tlb._visible=false;
}
if (cp != mp+.5) {
brb._visible = trb._visible=true;
} else {
brb._visible = trb._visible=false;
}
if (pro == 0) {
fs.removeMovieClip();
fsm.removeMovieClip();
ss.removeMovieClip();
ssm.removeMovieClip();
fbp.removeMovieClip();
fbpm.removeMovieClip();
if (dd == 1) {
srp.removeMovieClip();
} else {
slp.removeMovieClip();
}
} else {
ftp.removeMovieClip();
if (dd == -1) {
srp.removeMovieClip();
} else {
slp.removeMovieClip();
}
}
ftpm.removeMovieClip();
}
function ssw() {
this.createEmptyMovieClip("fs", 50);
msw(fs, -dd, vr);
fs._rotation = vr*dd*45;
this.createEmptyMovieClip("ss", 60);
msw(ss, dd, vr);
ss._rotation = vr*dd*45;
}
function lb() {
if (cp == .5) {
slp._visible = 0;
ftp.shade._alpha = 67;
} else if (cp == mp+.5) {
srp._visible = 0;
ftp.shade._alpha = 67;
}
if (enp == .5) {
fs._alpha = 67;
ss._visible = 0;
} else if (enp == mp+.5) {
fs._alpha = 67;
ss._visible = 0;
}
}
function sfg() {
createEmptyMovieClip("ftp", 30);
dp(ftp, dd, vr);
var pn = dd == 1 ? cp+.5 : cp-.5;
with (ftp) {
attachMovie("print"+pn, "print", 10);
with (print) {
_x = dd*pw/2;
_y = -vr*py;
}
}
ftp.createEmptyMovieClip("shade", 20);
mse(ftp.shade, dd, vr);
createEmptyMovieClip("fbp", 40);
dp(fbp, -dd, vr);
var pn = dd == 1 ? enp-.5 : enp+.5;
fbp.attachMovie("print"+pn, "print", 10);
with (fbp.print) {
_x = -dd*pw/2;
_y = -vr*py;
}
fbp._rotation = dd*vr*90;
}
function msw(t, xq) {
with (t) {
var c, a, ra, mxl, m;
c = [0, 0, 0, 0, 0, 0, 0];
a = [40, 25, 15, 5, 0, 1, 6];
ra = [0, 1, 17, 51, 89, 132, 255];
mxl = Math.sqrt((pw*pw)+(pwh*pwh));
m = {matrixType:"box", x:0, y:-vr*mxl, w:xq*pw, h:vr*(mxl-pw), r:0};
begingradientfill("linear", c, a, ra, m);
moveto(0, -vr*pw);
lineto(0, -vr*mxl);
lineto(xq*pw, -vr*mxl);
lineto(xq*pw, -vr*pw);
lineto(0, -vr*pw);
endfill();
}
}
function smf(dd, vr) {
pi(cp+dd*2, dd, vr);
startx = dd*pw;
drg = true;
brb._alpha = blb._alpha=tlb._alpha=trb._alpha=0;
Odr = 0;
onEnterFrame = function () {
var goalr = ggr();
step = (goalr-Odr)*dr;
Odr += step;
fff(Odr);
if (!drg) {
if (Odr<sn) {
fff(0);
pro = 0;
fd();
} else if (Odr>1-sn) {
fff(1);
pro = 1;
fd();
}
}
};
}
function pi(ep, d, v) {
enp = ep;
dd = d;
vr = v;
_y = sy+v*(py*_yscale/100);
sst();
sfg();
ssw();
mm();
lb();
sb();
}
function sst() {
createEmptyMovieClip("slp", 10);
if (enp != .5) {
dp(slp, -1, vr);
var pn = dd == 1 ? cp-.5 : enp-.5;
var slpp = slp.attachMovie("print"+pn, "print", 1);
slpp._x = -pw/2;
slpp._y = -vr*py;
}
createEmptyMovieClip("srp", 20);
if (enp != mp+.5) {
dp(srp, 1, vr);
var pn = dd == 1 ? enp+.5 : cp+.5;
var srpp = srp.attachMovie("print"+pn, "print", 1);
srpp._x = pw/2;
srpp._y = -vr*py;
}
var t = dd>0 ? slp : srp;
t.createEmptyMovieClip("shade", 2);
mse(t.shade, -dd, vr);
}
function drrs() {
if (mrO>2/3) {
cp += 2*dd;
}
pd = drg=false;
brb._visible = blb._visible=tlb._visible=trb._visible=false;
}
function psrs(side) {
if (pd) {
pd = false;
} else {
flipto(cp+side*2);
}
}
blb.onRollOver = function() {
smf(-1, 1);
};
tlb.onRollOver = function() {
smf(-1, -1);
};
brb.onRollOver = function() {
smf(1, 1);
};
trb.onRollOver = function() {
smf(1, -1);
};
blb.onRollOut = brb.onRollOut=trb.onRollOut=tlb.onRollOut=function () {
drg = false;
};
blb.onRelease = tlb.onRelease=function () {
psrs(-1);
};
brb.onRelease = trb.onRelease=function () {
psrs(1);
};
blb.onDragOut = tlb.onDragOut=function () {
pd = true;
brb._visible = trb._visible=false;
};
brb.onDragOut = trb.onDragOut=function () {
pd = true;
blb._visible = tlb._visible=false;
};
blb.onReleaseOutside = brb.onReleaseOutside=tlb.onReleaseOutside=trb.onReleaseOutside=function () {
drrs();
};
Any help would be appreciated and I am sure I can come in handy to help others!
Migrating Non-class AS3 To Classes And Packages
I just met with a company about working on an app they've started building, and they demoed the app and showed me a few hundred lines of code they already had. Their code was all in external .AS files, but it was also all done without any class or package structures, or even comments.
They seemed open to rewriting their small codebase on this app with classes and packages, but I wanted to ask if anyone here might've had much similar experience, and what kind of issues I might want to look out for.
A few questions I've thought of:
1. If I migrate only some of the code, are there likely to be some unique or major issues with it interacting with the non-class/package-based code?
2. What other drawbacks might there be to keeping some of the code in its existing non-class, non-packaged structure?
3. Any tips on migrating this?
4. Any tips on testing?
Thanks.
TypeError When Migrating Code To A Class
Hi,
I'm trying to modify some particle generating code from Seb Lee-Delisle by moving it off the timeline and into a class. On the timeline, the code runs great. I want to control when the particle fires, so I moved it into a document class which calls Seb's class. No prob so far.
But when the code in the document class runs as a constructor function I get the following error when it begins to build the particles: TypeError: Error #1034: Type Coercion failed: cannot convert global@3385101 to flash.display.DisplayObjectContainer.
What am I referencing wrong?
notes:
The error happens at var particle:Particle = new Particle(Spark, this, 60, 400);
Spark is an embedded asset with class "Spark" in the .fla library
document class GreenParticles.as
ActionScript Code:
package com.thomasakirk{
import flash.events.*;
import flash.display.*;
import com.sebleedelisle.Particle;
public class GreenParticles extends Sprite {
function GreenParticles() {
trace("init!");
//count particles
var count:Number = 0;
//create particles array
var particles:Array = new Array();
//listen for new frame
addEventListener(Event.ENTER_FRAME, enterFrame);
//what to do on each frame
function enterFrame(e:Event) {
//max particles is 85
if (count < 85) {
// make a new particle
var particle:Particle = new Particle(Spark, this, 60, 400);
//set random particle rotation
var thisRot:Number = Math.floor(randRange(0,360));
particle.clip.rotation = thisRot;
// give it a random velocity
particle.setVel(randRange(0,30), randRange(-10,5));
// add drag;
particle.drag = 0.96;
// fade out
particle.fade = 0;
// change size
particle.shrink = 1.05;
//gravity
particle.gravity = -.1;
// and add it to the particle array...
particles.push(particle);
} else {
//trim array by 1 and get particle trimmed off
particle = Particle(particles.shift());
//remove that particle
particle.destroy();
//when you reach 0 particles, stop enter frame event
if (particles.length==0) {
removeEventListener(Event.ENTER_FRAME, enterFrame);
}
}
// go through the array of particles ...
for (var i:Number = 0; i < particles.length; i++) {
// and update each one
particles[i].update();
}
//increment particle count
count++;
}
//random number function
function randRange(min:Number, max:Number) {
var randomNum:Number = (Math.random() * (max - min )) + min;
return randomNum;
}
}
}
}
Seb's Class Particle.as
ActionScript Code:
package com.sebleedelisle
{
import flash.display.*;
public class Particle
{
public var xVel : Number; // the x and y velocity of the particle
public var yVel : Number;
public var drag : Number = 1; // the drag factor between 0 and 1, where 1 is no drag, and 0 is max drag.
public var fade : Number = 0; // the fade factor, works as a multiplier.
public var shrink : Number = 1; // another multiplier that changes the size.
// If < 1 then the particle graphic shrinks, >1 and the particle grows.
public var gravity : Number = 0; // the amount of gravity to add to the yVelocity every frame. If < 0
// then gravity goes upwards.
public var clip:DisplayObject; // display object for the particle
public function Particle ( spriteclass : Class, targetclip : DisplayObjectContainer, xpos : Number, ypos : Number)
{
// instantiate a new particle graphic
clip = new spriteclass();
// and add it to the stage
targetclip.addChild(clip);
// and set its position
clip.x = xpos;
clip.y = ypos;
}
public function setVel(xvel:Number, yvel:Number)
{
xVel = xvel;
yVel = yvel;
}
public function setScale(newscale:Number)
{
clip.scaleX = clip.scaleY = newscale;
}
public function update()
{
// add the velocity to the particle's position...
clip.x += xVel;
clip.y += yVel;
// apply drag
xVel*=drag;
yVel*=drag;
// fade out
clip.alpha -=fade;
// scale
clip.scaleX = clip.scaleY *=shrink;
// gravity
yVel+=gravity;
}
public function destroy():void
{
clip.parent.removeChild(clip);
}
}
}
Migrating Flash (&Dreamweaver&Fireworks) To New P.C.
Hi im new here, My pc is way outdated... So Im thinkng of geting a new one. But there is 1 problem I need to migrate Stuido8 Is it posible what do I use (I dont want to re-buy it)? Im gona hoprfully have it on a vista pc. Im willing to buy a proghram to do this for me... as long as its under $40-$50. Can some one help?
Migrating Custom AS 2 Easing Formula To AS 3
hey all,
i've got an AS 2 easing formula that targets a clip above it. but i can't figure out how to make it work in AS 3. flash says that _parent doesn't work anymore? is this script capable of being re-written for AS 3 or do i have to start from scratch?
thanks for your help!
var baseRate:Number = 3.5
var difference:Number = _parent.targetx - _parent.panel._x;
var rate:Number = difference / baseRate
_parent.panel._x += rate;
Migrating From AS2 To AS3 (built A Class, But What About It's Image Etc?).
So I have now migrated my flash projects bullet movieclip code into a class, like so:
Code:
package
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.*;
import String;
public class Bullet extends MovieClip
{
// Class wide variables.
var bmove:int = 1;
var b_name = this.name;
var t_bullet:String = b_name.substring(b_name.indexOf("_")+2, 20);
var o_tower:int = parent.target_array["bullet_"+t_bullet][0];
var etarget:String = parent["enemy_basic1_"+o_tower];
// Bullet class constructor.
public function Bullet():void
{
this.addEventListener(Event.ENTER_FRAME, enter_frame, false, 0, true);
}
// Bullet class, Enter Frame event.
private function enter_frame(Event)
{
if (this.DisplayObject.x < 0 || this.DisplayObject.y < 0 || parent.enemy_array[o_tower] < 1) { parent.removeChild(this) }
if (parent[etarget]._y < this.DisplayObject.y) { this.DisplayObject.y -= bmove; }
else if (parent[etarget]._y > this.DisplayObject.y) { this.DisplayObject.y += bmove; }
if (parent[etarget]._x < this.DisplayObject.x) { this.DisplayObject.x -= bmove; }
else if (parent[etarget]._x > this.DisplayObject.x) { this.DisplayObject.x += bmove; }
if (this.DisplayObject.hitTestObject(parent[etarget]))
{
parent[etarget].hp -= parent.target_array["bullet_"+t_bullet][1];
parent.removeChild(this);
}
}
}
}
Which as far as I know is fine, but it has no image, or any of the movieclip properties the original bullet did, how do I fix this? I still have my bullet movieclip on the stage, it just doesn't have any actionscript in it now (as I moved it to a class).
Am I supposed to somehow attach this movieclip (won't this cause bloat, the class itself extends a MovieClip type and then I go and add/attach a seperate MovieClip to it?).
P.S. If anyone finds anything wrong with the above class, feel free to let me know, it will certainly help (I have the class compiling without error but perhaps I might run into problems later down the track with some things), and those arrays are meant to be created in the frames onLoad event.
Migrating From Procedural Way Of Scripting To OOP Style
Hi,
I'm having some trouble migrating from procedural way of scripting to OOP. (Am comfortable with AS2 and now trying to migrate to AS3.0). Did some tutorials online but I keep finding myself stuck with this question:
"How do I build a basic website using classes?"
Is there any resources or reading materials which can help me to learn how to 'plan and break down' a website into small parts/classes?
Migrating From Win To Mac & Having Strange Font Problems
Hi all,
i'm migrating my system from windows to mac...everything in the mac is better but in a project created with flash cs3 on my old pc the font (standard 07_55) is having some problems.
I'm parsing an xml file with a simple structure, for example 20 identical rows with 4 attributes per row, and in an attribute i'm using some chars with accents (àèéìòù). On the pc all is working perfectly. On the mac instead the chars appears like this:
For example "Più valore" appears as "Pi[ valore"
Any ideas?
Thanks
Problem Migrating Angle Property In As 3.0
Problem migrating angle property in as 3.0
Hello,
I'm trying to migrate a simple actionscript 2.0 app to 3.0 and I'm having some problems finding equivelents of the angle property in as 3.0.
This section of code is based on Lee Brimelow's Carousel example.
Code:
function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = this._y/(centerX + radiusY);
trace("**** angle: " + this.angle);
this._xscale = this._yscale = s * 100;
this.angle += this._parent.speed;
trace( "this: " + this);
this.swapDepths(Math.round(this._xscale) + 100);
}
Any ideas?
Thanks,
Eric
Migrating Basic Fading Xml Slideshow From AS2
I am trying to migrate a basic xml slideshow that fades each new image over the last from AS2 because it won't work when loaded into a _root AS3 app, even though Adobe says it should. I can get it to work fine (using a transition manager) up to a point and then it will just drop the fade. I am building this for a kiosk station, so it stays live all day. Anyone else had trouble with the transition class? I can't get it to work at all with a tween...but the gist is:
1. loads XML using Loader
2. loads the first image into container2 (underneath container1, both are on the state and are attached in the as)
3. creates a Timer
4. on each TimerEvent, it loads the next image into container1 and fades it from 0 to 100 using the Transition class
5. uses TransitionManager to read when it finished fading and then removes the image in container2(on bottom) and swaps the new image from container1 (on top) to container2 (bottom).
---repeats the TimerEvent---
My code is messy because I had about 2 hours to try to crank this out as my first AS3 app, so, it isn't set up in an external .as file or anything...just all on the first frame and beware because it is creating multiple arrays because each images is ID'd as type A, B, or C and they display randomly, etc...but see below and let me know if you know what I goofed on! THANKS!
Code:
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
import flash.net.URLLoader;
import fl.transitions.*;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var currImg:Number = 0;
var myXML:XML = new XML();
var XML_URL:String = "images.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
var numImages:Number = 0
var currArr:Number = 0;
var nextArr:Number = 1;
var myImg:String = ""
var myNextImg:String = ""
var a:Array = new Array();
var arrayA:Array = new Array();
var arrayB:Array = new Array();
var arrayC:Array = new Array();
var currA:Number = -1;
var currB:Number = -1;
var currC:Number = -1;
function xmlLoaded(event:Event):void {
myXML = XML(myLoader.data);
for each (var prop:XML in myXML.image) {
numImages ++;
}
var isRandom:Boolean = myXML.@isRandom;
var slide_length:Number = myXML.@slide_length
trace (slide_length)
for (i = 0; i < numImages; i ++) {
if (isRandom){
if (String(myXML..@id[i]) == "A"){
arrayA.push(myXML..@url[i]);
}
if (String(myXML..@id[i]) == "B"){
arrayB.push(myXML..@url[i]);
}
if (String(myXML..@id[i]) == "C"){
arrayC.push(myXML..@url[i]);
}
} else {
arrayA.push(myXML..@url[i]);
}
}
if (arrayA.length > 0){
a.push("A");
if (isRandom){
trace ("shuffle it");
//shuffleArray(arrayA);
}
};
if (arrayB.length > 0){
a.push("B");
if (isRandom){
//shuffleArray(arrayB);
}
};
if (arrayC.length > 0){
a.push("C");
if (isRandom){
//shuffleArray(arrayC);
}
};
if (isRandom){
trace (String(a[currArr]))
trace (String(a[nextArr]))
if (String(a[currArr]) == "A"){
currA ++;
myImg = arrayA[currA];
} else if (String(a[currArr]) == "B"){
currB ++;
myImg = arrayB[currB];
} else if (String(a[currArr]) == "C"){
currC ++;
myImg = arrayC[currC];
}
if (String(a[nextArr]) == "A"){
currA ++;
myNextImg = arrayA[currA];
} else if (String(a[nextArr]) == "B"){
currB ++;
myNextImg = arrayB[currB];
} else if (String(a[nextArr]) == "C"){
currC ++;
myNextImg = arrayC[currC];
}
} else {
currA ++;
myImg = arrayA[currA];
currA ++;
myNextImg = arrayA[currA];
}
trace (myImg + " | " + myNextImg);
var container2:MovieClip = new MovieClip();
addChild(container2);
var container:MovieClip = new MovieClip();
addChild(container);
var pictLdr:Loader = new Loader();
var pictURLReq:URLRequest = new URLRequest(myImg);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(e:Event):void {
container2.addChildAt(pictLdr.content, 0);
//container2.addChild(pictLdr.content);
}
var myTimer:Timer = new Timer(slide_length);
myTimer.addEventListener("timer", timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent):void {
//container.addChild(pictLdr.content);
if (isRandom){
trace (currArr);
trace (nextArr);
currArr = nextArr;
myImg = myNextImg;
nextArr++;
if (nextArr == a.length) {
nextArr = 0;
}
if (String(a[nextArr]) == "A"){
currA ++;
if (currA == arrayA.length){
currA = 0;
}
myNextImg = arrayA[currA];
} else if (String(a[nextArr]) == "B"){
currB ++;
if (currB == arrayB.length){
currB = 0;
}
myNextImg = arrayB[currB];
} else if (String(a[nextArr]) == "C"){
currC ++;
if (currC == arrayC.length){
currC = 0;
}
myNextImg = arrayC[currC];
}
} else {
currA ++
if (currA == arrayA.length){
currA = 0;
}
myNextImg = arrayA[currA];
}
var pictLdr:Loader = new Loader();
var pictURLReq:URLRequest = new URLRequest(myNextImg);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(e:Event):void {
container.addChildAt(pictLdr.content, 0);
var tm:TransitionManager = new TransitionManager(container);
tm.startTransition({type:Fade, direction:Transition.IN, duration:1, easing:Regular.easeInOut});
tm.addEventListener("allTransitionsInDone", done);
function done(evt:Event):void {
trace ("anything");
container2.removeChildAt(0);
container2.addChildAt(container.getChildAt(0), 0);
}
}
}
}
Migrating Automatically From Flash At The End Of Animation
Hi all,
I'm new with using Flash5.0.
I have created an animation in Flash, and I want to go
to my homepage automatically after the animation ends.
I coded the GetURL at the end of the animation, but it pops up a
new browser window. I want to transfer within the same browser
window!
Can someone please help me on that.
many thanks.
Azora
Migrating From AS2: Problem Importing Package/class
I’m currently migrating a Flash game over to AS3 and I’m having trouble changing my classes into packages. I have a folder called “actionscript” which contains all my packages/classes, etc.
My main class file, “Main.as”, looks like this:
ActionScript Code:
package actionscript{ // Flash packages import flash.media.Sound; ... import flash.events.KeyboardEvent; // My packages (found in same “actionscript” folder) import Inventory; ... import Level1; public class Main { private var _currentLevel; ... private var _inventory; /** * Constructor */ public function Main() { ... } ... }}
I have the following code on frame 1:
ActionScript Code:
import actionscript.Main;var Main:Main = new Main();
But I get this error:
“1046: Type was not found or was not a compile-time constant: Main.”
Any idea what’s going on?
Thanks!
AS3 - Migrating A Non-class AS3 Codebase Into Classes And Packages
Today I met with a small company about working on an app they've started. They demoed the app and then showed me a few hundred lines of code that they already had. Their code was all in external .AS files, but it was also all done without any class or package structures, or even comments.
They seemed open to rewriting their small codebase on this app with classes and packages, but I wanted to ask if anyone here might've had much similar experience, and what kind of issues I might want to look out for.
I'd be open to some informed general advice, as well as some specifics. A few questions I've thought of are:
1. If I migrate only some of the code, are there likely to be some unique or major issues with it interacting with the non-class/package-based code?
2. What other drawbacks might there be to keeping some of the code in its existing non-class, non-packaged structure?
3. Any tips on migrating this?
4. Any tips on testing?
Thanks.
Problem Migrating OnClipEnter Frame And Angle Property In As 3.0
Hello,
I'm trying to migrate a simple actionscript 2.0 app to 3.0 and I'm having some problems finding equivelents of the onEnterFrame methods and the angle property in as 3.0.
In this section, I need to have the t movieClip variable onEnterFrame method call the mover function:
Code:
for(var i:Number = 0; i < numberOfItems; i++)
{
var t = attachMovie("icon", "icon"+i, i+1);
t.angle = i * ((Math.PI*2)/numberOfItems);
t.onEnterFrame = mover;
}
In this section, I need to find an as 3.0 equivelent to the this.angle property:
Code:
function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = this._y/(centerX + radiusY);
trace("**** angle: " + this.angle);
this._xscale = this._yscale = s * 100;
this.angle += this._parent.speed;
trace( "this: " + this);
this.swapDepths(Math.round(this._xscale) + 100);
}
Any ideas?
Thanks,
Eric
Problem Migrating OnClipEnter Frame And Angle Property In As 3.0
Hello,
I'm trying to migrate a simple actionscript 2.0 app to 3.0 and I'm having some problems finding equivelents of the onEnterFrame methods and the angle property in as 3.0.
In this section, I need to have the t movieClip variable onEnterFrame method call the mover function:
[code]
for(var i:Number = 0; i < numberOfItems; i++)
{
var t = attachMovie("icon", "icon"+i, i+1);
t.angle = i * ((Math.PI*2)/numberOfItems);
t.onEnterFrame = mover;
}
[/code]
In this section, I need to find an as 3.0 equivelent to the this.angle property:
[code]
function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = this._y/(centerX + radiusY);
trace("**** angle: " + this.angle);
this._xscale = this._yscale = s * 100;
this.angle += this._parent.speed;
trace( "this: " + this);
this.swapDepths(Math.round(this._xscale) + 100);
}
[/code]
Any ideas?
Thanks,
Eric
Problem Migrating OnClipEnter Frame And Angle Property In As 3.0
Hello,
I'm trying to migrate a simple actionscript 2.0 app to 3.0 and I'm having some problems finding equivelents of the onEnterFrame methods and the angle property in as 3.0.
In this section, I need to have the t movieClip variable onEnterFrame method call the mover function:
[code]
for(var i:Number = 0; i < numberOfItems; i++)
{
var t = attachMovie("icon", "icon"+i, i+1);
t.angle = i * ((Math.PI*2)/numberOfItems);
t.onEnterFrame = mover;
}
[/code]
In this section, I need to find an as 3.0 equivelent to the this.angle property:
[code]
function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = this._y/(centerX + radiusY);
trace("**** angle: " + this.angle);
this._xscale = this._yscale = s * 100;
this.angle += this._parent.speed;
trace( "this: " + this);
this.swapDepths(Math.round(this._xscale) + 100);
}
[/code]
Any ideas?
Thanks,
Eric
Problem Migrating OnClipEnter Frame And Angle Property In As 3.0
Hello,
I'm trying to migrate a simple actionscript 2.0 app to 3.0 and I'm having some problems finding equivelents of the onEnterFrame methods and the angle property in as 3.0.
In this section, I need to have the t movieClip variable onEnterFrame method call the mover function:
Code:
for(var i:Number = 0; i < numberOfItems; i++)
{
var t = attachMovie("icon", "icon"+i, i+1);
t.angle = i * ((Math.PI*2)/numberOfItems);
t.onEnterFrame = mover;
}
In this section, I need to find an as 3.0 equivelent to the this.angle property:
Code:
function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = this._y/(centerX + radiusY);
trace("**** angle: " + this.angle);
this._xscale = this._yscale = s * 100;
this.angle += this._parent.speed;
trace( "this: " + this);
this.swapDepths(Math.round(this._xscale) + 100);
}
Any ideas?
Thanks,
Eric
Problem Migrating OnClipEnter Frame And Angle Property In As 3.0
Hello,
I'm trying to migrate a simple actionscript 2.0 app to 3.0 and I'm having some problems finding equivelents of the onEnterFrame methods and the angle property in as 3.0.
In this section, I need to have the t movieClip variable onEnterFrame method call the mover function:
CODEfor(var i:Number = 0; i < numberOfItems; i++)
{
var t = attachMovie("icon", "icon"+i, i+1);
t.angle = i * ((Math.PI*2)/numberOfItems);
t.onEnterFrame = mover;
}
Migrating Tile Isometric "Engine" To AS3. Help Please
Hello there folks. As the title suggests I am migrating a my tile isometric scripts to AS3. So pretty much what the whole thing does is is you click a certain floor tile and you have object inserted there. As I am total newb with AS3 I problems were to be expected. No the problem is not the change of the z sorting model, I took care of that. The problem is something much more "serious". In the AS2 version I had a great number of library symbols, with linkage identifiers which were stored in an array. Then on the press of a tile I attached a symbol of my liking, (selected prior to the tile click). Something remotely similar to the following;
Code:
var objects:Array = ["Box1","Box2","Box3"];
//........................
var selected:Number=2;
//.......................
content_mc.attachMovie(objects[selected],"someName",content.getNextHighestDepth());
Ok, thats an oversimplified version of it but hope you get the idea. Now in AS3 the library symbols are classes by themselves. Therefore I have to use the following syntax:
Code:
var someName:Box1 = new Box1();
So I have pretty much no idea how can I achieve what I want. Only thing which comes to mind is create array of (few hundred ) simple functions, and use the appropriate one.
Code:
var funcs:Array=new Array();
funcs[0]=function () {
var box1:Box1=new Box1();
return (box1);
};
funcs[1]=function () {
var box2:Box2=new Box2();
return (box2);
};
//.....................
var selected:Number=2;
//.....................
funcs[selected]();
Any better ideas?
Thank you
Migrating From Flash MX To Flash MX 2004... Is It Worth?
Hi People:
I'm thinking about jumping into Flash MX 2004. I could get it as soon as tomorrow morning... but have one concern. I'm pretty satisfied with the stability and funcionality of Studio MX at this point (I'm not a pro but can deliver some high aces with it) and have read some bad stuff about 2004. Bugs and stuff mainly, the lack of some old components (scroll bar) and lots of conflicts and bigger swf sizes make me wonder.
Is it worth to move up to 2004 or should I stay with MX? I'm very curious but don't have much trust on it.
All your suggestions will be welcomed and taken into consideration.
Thanks in advance.
Migrating From Flash MX To Flash MX 2004... Is It Worth?
Hi People:
I'm thinking about jumping into Flash MX 2004. I could get it as soon as tomorrow morning... but have one concern. I'm pretty satisfied with the stability and funcionality of Studio MX at this point (I'm not a pro but can deliver some high aces with it) and have read some bad stuff about 2004. Bugs and stuff mainly, the lack of some old components (scroll bar) and lots of conflicts and bigger swf sizes make me wonder.
Is it worth to move up to 2004 or should I stay with MX? I'm very curious but don't have much trust on it.
All your suggestions will be welcomed and taken into consideration.
Thanks in advance.
|