Migrating array functions from AS2 to AS3
The code below is meant to load randomly selected "koan swfs" into a movie clip on the main root timeline called "koan_loader_mc" using a loader called "koan_loader." Are the actions of this array correctly migrated to AS3? Thanks for your help
// creates function called at the end of koan_#.swfs
// this code is in the first frame of the root timeline
Array.prototype.shuffle = function() {
for (var ivar = koan.length-1; ivar>=0; ivar--) {
var p = random(ivar+1);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
MovieClip(root).index=0;
var koan_loader:Loader = new Loader();
var koan:Array =["swfs/koans/koan_1.swf","swfs/koans/koan_2.swf", "swfs/koans/koan_3.swf", "swfs/koans/koan_4.swf", "swfs/koans/koan_5.swf", "swfs/koans/koan_6.swf", "swfs/koans/koan_7.swf", "swfs/koans/koan_8.swf", "swfs/koans/koan_9.swf", "swfs/koans/koan_10.swf", "swfs/koans/koan_11.swf", "swfs/koans/koan_12.swf"];
koan.shuffle();
koan_loader.load(new URLRequest(koan[index]));
MovieClip(root).koan_loader_mc.addChild(koan_loader);
This is the code in a frame at the end of koan swfs:
MovieClip(root).index++
if(root.index>_root.koan.length-1){
root.index=0;
root.koan.shuffle();
var koan_loader:Loader = new Loader();
koan_loader.load(new URLRequest(koan[root.index]);
MovieClip(root).koan_loader_mc.addChild(koan_loader);
loadMovie(_root.koan[root.index]);
function shuffle(a:Array) {
for (var ivar = a.length-1; ivar>=0; ivar--) {
var p = random(ivar+1);
var t = a[ivar];
a[ivar] = a[p];
a[p] = t;
Similar Messages
-
Please help 'Translate' These codes from AS2 to AS3 for me
Hi, i need help 'translating' these codes from Action Script 2 to Action Script 3. Please Do it for me:
toc loadText = new LoadVars();
loadText.load("Curie.txt");
loadText.onLoad = function(success) {
if (success) {
// trace(success);
Curie.html = true;
Curie.htmlText = this.Curie;
Please translate it for me, i need it ASAP thanks
KennethThank you for helping me
Kenneth
Date: Thu, 15 Oct 2009 05:49:14 -0600
From: [email protected]
To: [email protected]
Subject: Please help 'Translate' These codes from AS2 to AS3 for me
Take a look at that:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/migration.html
There is a LoadVars section on that.
There is also a tutorial here:
http://www.republicofcode.com/tutorials/flash/as3externaltext/
Cheers,
CaioToOn!
> -
Issues converting scroll bar components from AS2 to AS3
I am working on editing a document that has scroll bar components that I would like to convert from AS2 to AS3 since everytime I try to open the document it shows a WARNING and won't convert them and when I publish and look at the final document the scroll bar seems to act unusally since it is obviously still on AS2.
Here are two of the scripts I finally was able to find within it. Should I fix it and how so? This first is for the "Creative Scroll Area" and the second is for the "Creative Scrollbar"
package {
import flash.display.MovieClip;
public class Creative Scroll Area extends MovieClip {
public function Creative Scroll Area() {
// constructor code
package {
import flash.display.MovieClip;
public class Creative Scrollbar extends MovieClip {
public function Creative Scrollbar() {
// constructor codeOkay, well I know the code is making a scroll bar and a scroll area and under the "type" it says they are "compiled..." which is unusual since most of the other components I've worked with have been movie clips or bitmaps. Do I need to look up what AS3 components I need to replace the script from above? Because when I looked for that I couldn't specifically find what I needed or really understood if I was looking at the right information.
Here is something I found when trying to "debug" it:
WARNING: The component 'UIScrollBar' requires ActionScript 2.0, which is not supported in this version of Flash Professional.
WARNING: The component 'Creative Scrollbar' requires ActionScript 2.0, which is not supported in this version of Flash Professional.
WARNING: The component 'Creative Scroll Area' requires ActionScript 2.0, which is not supported in this version of Flash Professional. -
Declare new color from AS2 to AS3
Hi All,
Could you let me know how to "convert" the following code from AS2 to AS3:
var distracterBkgdColor = new Color(this.distracterBkgd_mc);
Thanks!var ct:ColorTransform = this.distracterBkgd_mc.transform.colorTransform;ct.color = 0xrrbbgg;
this.distracterBkgd_mc.transform.colorTransform=ct; -
Major gaming system Migration from AS2 to AS3
I have a major project entirely in AS2. It is made of a
Multimedia Application, which provides access to functions needed
to load games, save information, insert *.jpg files... The 50+
games each have their own graphic.swf and engine.swf, where the
graphics deal with gameplay and the engine communicates with the
Multimedia Application.
If the Multimedia Application is migrated to AS3 but the game
swf files remain the same, will the functions still be able to
communicate (call functions and send references to objects)?No, AS2 and AS3 are absolutely different animals. There are
some techniques (search for as2 as3 bridge in the net) that create
a bridge which are cumbersome in my view. -
Calling flex functions from flash swf (AS3)
Hi all, i'm stuck with communication between loaded AS3 SWF
from Flash and Flex3 project. I use SWFLoader for runtime loading
SWF, call functions inside SWF, but cannot find the way to call
functions declared in Flex project. I try to use ExternalInterface
class, but it does not help me, or maybe i use it incorrect. Is
there a method to call Flex user declared functions from Flash SWF?
All i need is a syntax sample, thank you in advance!Also, application.application will point to the top-level app
scope, even from a loaded swf.
I believe parentApplication will resolve to what you usually
want as well.
For looser coupling, consider using a bubbling event.
Tracy -
Converting short code from as2 to as3
Some of these functions wont work in as3, and i would like it to be using gestures instead of mouse clicks.. Any help please?
_root.attachMovie("brush","brush",10)
_root.brush.onEnterFrame=function()
Mouse.hide()
startDrag(this,true)
new Color (this.brushColor).setRGB(_root.brushColor)
on(press)
new Color(this).setRGB(_root.brushColor)
onClipEvent (load) {
myColor = 0x0000CC
new Color(this).setRGB(myColor);
on (release) {
_root.brushColor= myColor;no code should be attached to objects.
most of that looks like it's useless or worse than useless. in particular, everything in the enterframe loop looks like it serves no purpose and repeatedly does useless things. if it is doing something useful, it doesn't need to be done in a loop.
and setting the rgb of a color instance does nothing useful.
the only thing useful is setting brushColor when that brush movieclip is clicked.
so, if you have a movieclip with class = "brush" in your library, you can use:
var brushColor:uint;
var blackBrush:brush=new brush();
blackBrush.col = 0x000000;
addChild(blackBrush);
blackBrush.addEventListener(MouseEvent.CLICK,clickF);
function clickF(e:MouseEvent):void{
brushColor = MovieClip(e.currentTarget).col -
Migration plans for Stock Captivate Animations from AS2 to AS3
The stock animations that come with Adobe Captivate were published in ActionScript 2 many years ago and carried forward with each new release of Captivate.
This presents a problem, because Captivate publishes to ActionScript 3.
So, I get lots of Flash Error messages popping up when I run my lessons with the debug version of the Flashplayer.
Example:
Error #2044 Unhandled SecurityErrorEvent:. text=Error #2047: Security sandbox violation: LocalConnection.send: ...
If I could find the original FLA files, I'd republish them myself, but I can't find them on my drive.
Does anyone know where I can find this source code?
I hate to have to do this every time I install a new version of Captivate, but the Adobe developers seem oblivious/apathetic to this recurring bug.
Thoughts? Comments? Suggestions?No, the MovieClip class is still dynamic so you can add
properties. If you extend MovieClip but you dont declare your
subclass dynamic, then you cannot add properties.
To access a display list you need to use getChildByName or
getChildAt. If you would add an instance name on your tf you can
retrieve that tf using getChildByName(), see attached snippet
(assuming you assign an instance name in the loop using tf.name =
"tf";
You need to read up on the target and currentTarget
properties of events. -
Please, HELP to convert code from AS2 to AS3!!!
there is source code from paint application, thank to human who will convert this code, it's codeimportant for us.
stop();
var arrSloy:Array = new Array();
//Initial
//OnMove
_root.onMouseMove = function() {
if (checkPole() && onTool) {
Mouse.hide();
_root.kist._visible = true;
_root.eras._visible = true;
_root.pen._visible = true;
_root.line._visible = true;
} else {
Mouse.show();
_root.kist._visible = false;
_root.eras._visible = false;
_root.pen._visible = false;
_root.line._visible = false;
updateAfterEvent();
//OnMove
//New
_root.panelMane.butNew.onRelease = function() {
_root.newClip1.removeMovieClip();
_root.clipMask.removeMovieClip();
onTool = false;
Mouse.show();
_root.pen.removeMovieClip();
_root.line.removeMovieClip();
_root.gotoAndStop("newImg1");
_global.XO = null;
_global.YO = null;
_global.WO = null;
_global.HO = null;
//creatNewPalitra
function creatNewPalitra(color:String, w:Number, h:Number) {
XO = 120;
YO = 130;
WO = w;
HO = h;
gotoAndStop(51);
_root.createEmptyMovieClip("newClip1",0);
newClip1.lineStyle(0,"0xFFFFFF");
newClip1.beginFill(color);
newClip1.moveTo(XO,YO);
newClip1.lineTo(XO+w,YO);
newClip1.lineTo(XO+w,YO+h);
newClip1.lineTo(XO,YO+h);
newClip1.lineTo(XO,YO);
newClip1.endFill();
_root.createEmptyMovieClip("clipMask",1);
clipMask.lineStyle(0,"0xFFFFFF");
clipMask.beginFill("0xFFFFFF");
clipMask.moveTo(XO,YO);
clipMask.lineTo(XO+w,YO);
clipMask.lineTo(XO+w,YO+h);
clipMask.lineTo(XO,YO+h);
clipMask.lineTo(XO,YO);
clipMask.endFill();
newClip1.setMask(clipMask);
function checkPole() {
if (WO == null) {
return false;
if ((_xmouse>=XO && _xmouse<=XO+WO) && (_ymouse>=YO && _ymouse<=YO+HO)) {
return true;
} else {
return false;
//New
_root.panelTool.butCursor.onRelease = function() {
onTool = false;
Mouse.show();
_root.kist.removeMovieClip();
_root.pen.removeMovieClip();
_root.line.removeMovieClip();
//PEN
creatClip = 10;
_root.panelTool.butPen.onRelease = function() {
onTool = true;
_root.attachMovie("pensil","pen",1000000);
Mouse.hide();
_root.pen.startDrag(true);
function drawPen() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = _root.panelProperties.poleColorLine.text;
lineAlpha = _root.panelProperties.poleAlphaLine.text;
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
_root.pen.onMouseDown = function() {
if (checkPole()) {
drawPen();
pen_draw_flag = true;
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.moveTo(this._x,this._y);
_root.pen.onMouseUp = function():Void {
pen_draw_flag = false;
_root.pen.onMouseMove = function():Void {
if (pen_draw_flag) {
if (checkPole()) {
clip.lineTo(this._x,this._y);
updateAfterEvent();
//BRUSH
_root.panelTool.butkist.onPress = function() {
onTool = true;
_root.attachMovie("kister","kist",1000000);
Mouse.hide();
_root.kist.startDrag(true);
function drawKist() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = _root.panelProperties.poleFill.text;
lineAlpha = _root.panelProperties.poleAlphaLine.text;
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
_root.kist.onMouseDown = function() {
if (checkPole()) {
drawKist();
kist_draw_flag = true;
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.moveTo(this._x,this._y);
_root.kist.onMouseUp = function():Void {
kist_draw_flag = false;
_root.kist.onMouseMove = function():Void {
if (kist_draw_flag) {
if (checkPole()) {
clip.lineTo(this._x,this._y);
updateAfterEvent();
//LINE
_root.panelTool.butLiner.onRelease = function() {
onTool = true;
_root.attachMovie("liner","line",1000000);
_root.line.startDrag(true);
Mouse.hide();
function drawLine() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = _root.panelProperties.poleColorLine.text;
lineAlpha = _root.panelProperties.poleAlphaLine.text;
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
thisx = thisy=null;
_root.line.onMouseDown = function() {
if (checkPole()) {
drawLine();
line_draw_flag = true;
thisx = this._x;
thisy = this._y;
_root.line.onMouseUp = function():Void {
line_draw_flag = false;
_root.line.onMouseMove = function():Void {
if (line_draw_flag) {
if (checkPole()) {
clip.clear();
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.moveTo(thisx,thisy);
clip.lineTo(this._x,this._y);
updateAfterEvent();
//ERASER
_root.panelTool.butEras.onPress = function() {
onTool = true;
_root.attachMovie("eraser","eras",1000000);
Mouse.hide();
_root.eras.startDrag(true);
function drawEras() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = "0xFFFFFF";
lineAlpha = "100";
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
_root.eras.onMouseDown = function() {
if (checkPole()) {
drawEras();
eras_draw_flag = true;
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.moveTo(this._x,this._y);
_root.eras.onMouseUp = function():Void {
eras_draw_flag = false;
_root.eras.onMouseMove = function():Void {
if (eras_draw_flag) {
if (checkPole()) {
clip.lineTo(this._x,this._y);
updateAfterEvent();
//CURV
_root.panelTool.butCurv.onRelease = function() {
onTool = true;
_root.attachMovie("liner","line",1000000);
_root.line.startDrag(true);
Mouse.hide();
anchor1X = anchor2X=controlX=null;
anchor1Y = anchor2Y=controlY=null;
onClic = 0;
function drawCurv() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = _root.panelProperties.poleColorLine.text;
lineAlpha = _root.panelProperties.poleAlphaLine.text;
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
_root.line.onMouseDown = function() {
if (onClic == 0) {
if (checkPole()) {
drawCurv();
anchor1X = this._x;
anchor1Y = this._y;
onClic = 1;
_root.attachMovie("point","point1",1000001);
point1._x = anchor1X;
point1._y = anchor1Y;
} else if (onClic == 1) {
if (checkPole()) {
anchor2X = this._x;
anchor2Y = this._y;
onClic = 2;
_root.attachMovie("point","point2",1000002);
point2._x = anchor2X;
point2._y = anchor2Y;
} else if (onClic == 2) {
if (checkPole()) {
controlX = this._x;
controlY = this._y;
onClic = 0;
curv_draw_flag = true;
point1.removeMovieClip();
point2.removeMovieClip();
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.moveTo(anchor1X,anchor1Y);
clip.curveTo(this._x,this._y,anchor2X,anchor2Y);
_root.line.onMouseUp = function():Void {
curv_draw_flag = false;
_root.line.onMouseMove = function():Void {
if (curv_draw_flag) {
if (checkPole()) {
clip.clear();
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.moveTo(anchor1X,anchor1Y);
clip.curveTo(this._x,this._y,anchor2X,anchor2Y);
updateAfterEvent();
//STAR
_root.panelTool.butStar.onRelease = function() {
onTool = true;
_root.attachMovie("liner","line",1000000);
Mouse.hide();
_root.line.startDrag(true);
function drawStar() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = _root.panelProperties.poleColorLine.text;
lineAlpha = _root.panelProperties.poleAlphaLine.text;
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
thisx = thisy=null;
_root.line.onMouseDown = function() {
if (checkPole()) {
drawStar();
star_draw_flag = true;
clip.lineStyle(lineSize,lineColor,lineAlpha);
thisx = this._x;
thisy = this._y;
clip.moveTo(thisx,thisy);
_root.line.onMouseUp = function():Void {
star_draw_flag = false;
_root.line.onMouseMove = function():Void {
if (star_draw_flag) {
if (checkPole()) {
clip.moveTo(thisx,thisy);
clip.lineTo(this._x,this._y);
updateAfterEvent();
//KVADRAT
_root.panelTool.butRecttangle.onRelease = function() {
onTool = true;
_root.attachMovie("liner","line",1000000);
_root.line.startDrag(true);
Mouse.hide();
function drawRecttangle() {
creatClip++;
lineSize = _root.panelProperties.poleSizeLine.text;
lineColor = _root.panelProperties.poleColorLine.text;
lineAlpha = _root.panelProperties.poleAlphaLine.text;
fillColor = _root.panelProperties.poleFill.text;
clip = _root.newClip1.createEmptyMovieClip("newClip"+creatClip, creatClip);
arrSloy.push(clip);
thisx = thisy=null;
_root.line.onMouseDown = function() {
if (checkPole()) {
drawRecttangle();
kvadrat_draw_flag = true;
thisx = this._x;
thisy = this._y;
_root.line.onMouseUp = function():Void {
kvadrat_draw_flag = false;
_root.line.onMouseMove = function():Void {
if (kvadrat_draw_flag) {
if (checkPole()) {
clip.clear();
clip.lineStyle(lineSize,lineColor,lineAlpha);
clip.beginFill(fillColor,lineAlpha);
clip.moveTo(thisx,thisy);
clip.lineTo(this._x,thisy);
clip.lineTo(this._x,this._y);
clip.lineTo(thisx,this._y);
clip.lineTo(thisx,thisy);
clip.endFill();
updateAfterEvent();
//Clear
_root.panelMane.butClear.onRelease = function() {
for (a=0; a<arrSloy.length; a++) {
clip = arrSloy[a];
clip.removeMovieClip();
delete arrSloy[a];
//Back
_root.panelMane.butBack.onRelease = function() {
i = arrSloy.length-1;
clip = arrSloy[i];
clip.removeMovieClip();
arrSloy.pop();
Thank you very much!!!Zhanbolat,
In theory, conversion of this code is not difficult, especially because it is clear what the logic is designed to do. The issue is that you will not have an expected result once only this code is converted in isolation. This puppy uses some other objects that are written in AS2 including entities in the FLA library.
In short, it looks like this application needs a total overhaul at every level in order for it to properly function as an AS3 program.
With that said, although this is, again, not a difficult task, it is unlikely to find someone to do it for free. You may have a better luck if you start conversion yourself and post focused questions as you go. -
Hi.
Below I have a bit of code that determines the bandwidth that a user has. It is written in ActionScript 2. The problem is that I am unfamiliar with AS2, and I wanted to use this in conjunction with a live streaming video player built in AS3. I was wondering if anyone could give me the equivalent code in AS3, or if there's any way to tell flash that a portion of the code will be written in AS2.
Thank You,
Ari Amiri
nc = new NetConnection();
nc.onStatus = function(info) {
trace("Level: "+info.level+" Code: "+info.code);
if (info.code == "NetConnection.Connect.Success") {
trace("--- connected to: " + this.uri);
nc.onBWDone = function(kbitDown, deltaDown, deltaTime, latency) {
trace("onBWDone: kbitDown:"+kbitDown+" deltaDown:"+deltaDown+" deltaTime:"+deltaTime+" latency:"+latency);
// app logic based on the bandwidth detected follows here
detected_bw = kbitDown;
// close the Netconnection to bwcheck
this.close();
nc.onBWCheck = function() {
trace("onBWCheck");
return ++counter; // Serverside, just ignore any return value, For now return the call count
nc.connect("rtmp://localhost/bwcheck", true);
stop();Yah very important point from NetDragon. As of version 3.0
the netconnection " class was dynamic in ActionScript 2.0 but is
now sealed. " so you can't just do something like:
netconnection.client.somefunction = function() {...}
The default netconnection.client = this, so you need to
extend it with a custom class or an object to be able to add
callback functions
But be careful, I wrote an entire app that worked with the
AS2.0 technique ...without an error from the compiler.....(flex
2.0). -
EventListener...: From AS2 to AS3..?
I'm trying to rewrite som AS2 code so it will fit to AS3 but
some minor problem occurs...
Here's the AS2 code:
panel.onRollOver = panelOver;
function panelOver() {
this.onEnterFrame = scrollPanel;
delete this.onRollOver;
The idea here is to create an EventListener in AS3 that will
trigger when the pointer is rolling over the movieclip "panel".
So far, so good...
Here's the AS3 code so far:
panel.addEventListener(MouseEvent.MOUSE_OVER, panelOver);
function panelOver(myEvent:MouseEvent):void {
this.onEnterFrame = scrollPanel;
Now, the problem is to rewrite [delete this.onRollOver;] so
it will work in AS3...
Could it be something like:
delete this.EventListener(panel)?
I'm really struggling these days finding my way through AS3
but I do feel that I'm starting to get a hang of it...
Thank you for any help I get...!
PS.
I think I might run into some more problems after solving
this one.. But we're all here to learn, aren't we?panel.removeEventListener(MouseEvent.MOUSE_OVER, panelOver);
(parameters should match as in addEventListener)
delete doesn't work.
this.onEnterFrame = scrollPanel; wont work either. infact
there is nothing called onEnterFrame in AS3..
it would be like
this.addEventListener(Event.ENTER_FRAME, scrollPanel); -
Converting code from as2 to as3 and getting errors
I am trying to get a counter that I found in as2 to work in as3 but I am getting errors when I publish.
Here is my code:
stop();
var currSlide;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(evt:Event):void
currSlide = root.rdinfoCurrentSlide +1;
this.curSlide_txt.text = currSlide;
this.totSlide_txt.text = root.rdinfoSlideCount;
any suggestions?no code should be attached to objects.
most of that looks like it's useless or worse than useless. in particular, everything in the enterframe loop looks like it serves no purpose and repeatedly does useless things. if it is doing something useful, it doesn't need to be done in a loop.
and setting the rgb of a color instance does nothing useful.
the only thing useful is setting brushColor when that brush movieclip is clicked.
so, if you have a movieclip with class = "brush" in your library, you can use:
var brushColor:uint;
var blackBrush:brush=new brush();
blackBrush.col = 0x000000;
addChild(blackBrush);
blackBrush.addEventListener(MouseEvent.CLICK,clickF);
function clickF(e:MouseEvent):void{
brushColor = MovieClip(e.currentTarget).col -
Preloader (from as2 to as3)
Hey ladies and gentlemen
I'm currently converting one of my project to as3 and I hit a
wall with this preloader problem.
Before, with as2, I was using getBytesLoaded() and
getBytesTotal() in a frame loop to display a progress bar and know
when the loading was finished. I can't seem to find how to do this
in as3.
I read as3 language reference and some examples but they all
deal with loading an external swf or file.
I would think that the main swf would trigger progress events
as it gets loaded so I made this little piece of code, which
doesn't work.
function ProgressHandler(theEvent:ProgressEvent)
trace("bytes Loaded: " + theEvent.bytesLoaded + "
bytesTotal: " + theEvent.bytesTotal);
addEventListener(ProgressEvent.PROGRESS, ProgressHandler);
stop();
Can anyone point me back in the right direction?
ThanksI just wanna make it clear that I'm trying to preload the
main swf itself, I still can't find anything on the net about that.
Anyone?
Thanks! -
Convert simple animation code from as2 to as3
Hi everyone,
I have a simple animation that is controlled by the y movement of the mouse. The code for the animation is put in frame 1 and is as follows:
var animationDirection:Boolean = false;
var prevMousePosition:Boolean = false;
var mouseListener = new Object();
mouseListener.onMouseMove = function () {
var curMousePosition = _ymouse;
if(curMousePosition > prevMousePosition) {
animationDirection = false;
}else if(curMousePosition < prevMousePosition) {
animationDirection = true;
prevMousePosition = curMousePosition;
Mouse.addListener(mouseListener);
function onEnterFrame() {
if(animationDirection && _currentframe < _totalframes) {
nextFrame();
}else if(!animationDirection && _currentframe > 1) {
prevFrame();
Is it possible to use this code in as3 or do I need to convert it? I am grateful for any help. Best wishesYes, you need to convert the code. Here is what looks like a similar logic in AS3:
import flash.events.Event;
import flash.events.MouseEvent;
var animationDirection:Boolean = false;
var prevMousePosition:Boolean = false;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
function onMouseMove(e:MouseEvent):void {
var curMousePosition = mouseX;
if (curMousePosition > prevMousePosition)
animationDirection = false;
else if (curMousePosition < prevMousePosition)
animationDirection = true;
prevMousePosition = curMousePosition;
function onEnterFrame(e:Event):void
if (animationDirection && _currentframe < _totalframes)
nextFrame();
else if (!animationDirection && _currentframe > 1)
prevFrame(); -
Convert simple code from as2 to as3
Hello, i am looking for some help here for something simple (i think)
var txt:String = link1;
btn.onRelease = function():Void {
if( sample_id )
getURL("http://www.website.com/registration?partner_id=" + sample_id + "sampleURLCode", "_blank");
else
getURL("http://www.website.com/registration?sampleURLCode", "_blank");
Is there a way to make this simple code into AS3?Hi, Apparantly that's because the 'link1' and 'sample_id' variables are not within the scope of the code you posted above, Perhaps you have defined them outside on a different frame or class. You can either define them with the same code like:
var sample_id:Number=1234; //Use your own variable type and value here
var link1:String = "your string or link URL here";
var txt:String = link1;
btn.addEventListener(MouseEvent.CLICK, gotoURL);
function gotoURL(e:MouseEvent)
if( sample_id )
navigateToURL(new URLRequest("http://www.website.com/registration?sample_id=" + sample_id + "sampleURLCode"),"_blank");
else
navigateToURL(new URLRequest("http://www.website.com/registration?sampleURLCode"),"_blank");
Or you can put a direct reference to your existing variable like (If your variables are defined on root/frame 1) :
var link1:String = "your string or link URL here";
var txt:String = MovieClip(this.root).link1;
btn.addEventListener(MouseEvent.CLICK, gotoURL);
function gotoURL(e:MouseEvent)
if( MovieClip(this.root).sample_id )
navigateToURL(new URLRequest("http://www.website.com/registration?sample_id=" + sample_id + "sampleURLCode"),"_blank");
else
navigateToURL(new URLRequest("http://www.website.com/registration?sampleURLCode"),"_blank");
try that, or you can share your .fla !
cheers
Maybe you are looking for
-
I updated to iOS 8 on my iPhone 5 yesterday and now when I press the home button even once, it opens the app switcher (which is supposed to only open after pressing the home button twice quickly). Sometimes pressing the home button once even brings u
-
Importing large amounts of baggage files?
I'm making generating a new roboproject from a Word document. Only one of the problems I'm having is that the Word document contains a lot of links to external files. These links still exist in Robohelp, but they don't refer to right location anymore
-
Hi experts , i heard from someone while we r doing LO extraction there is an T code BF 11 was being using for purchase analysis data sources, i just want to know, From which steps the BF11 will take effect? like Rsa5-lbwe-lbwg accordingly plz answer
-
Crystal Reports Server XI Release 2 - Automated clearing of user sessions.
I am having issues with unused user sessions not clearing automatically from the CMS Server after they have finished using "InfoView". 1) I have set their preferences to "always log me off InfoView" when closing the browser. 2) I have uncommented out
-
Hi Community, we have a fpn working here with RRA. Filter_id's are implemented in the consumer portal desktops. Navigation is built by roles RoleA (Entry Point, Filter_id = A, Merge_id = x) - RoleB(Entry Point, Filter_id = A, Merge_id = x) - Folder