SwapDepths in AS3
how to use swapDepths in AS3
maybe what he mean is how to swap children index,
if that the case u can use:
u can use it by reffering to the name of the movieclip :
swapChildren( firstMovieCliptoBeSwaped, secondMovieCliptoBeSwaped);
or by reffering to it's index:
swapChildren( firstMovieCliptoBeSwapedIndex, secondMovieCliptoBeSwapedIndex);
u can't do swap all then movie clip child index at once,
you need to do it one by one
Similar Messages
-
I'm trying to port an AS 2.0 file to AS 3.0 but I'm having
trouble making the menu (little boxes) rotate, and I'm not sure
what to do with a swapdepths(); in AS3.0. Here's my code:
//------3D menu system in
AS3.0-------------------------------------//
use in website
import flash.display.MovieClip;
import flash.events.*;
//-------variables, set 0,0 point to the center of
stage------------//
var Xcenter:Number = new Number(stage.width/2);
var Ycenter:Number = new Number(200);
var objectsTotal:uint = new uint(12);
var i:uint = new uint();
//--------3D ellipse and rotation
speed---------------------------//
var radiusX:Number = new Number(250);
var radiusY:Number = new Number(15);
var speed:Number = new Number(0.02);
//--------add clips to stage
var object_mc:MovieClip = new MovieClip();
addChild(object_mc);
object_mc.x = 250;
object_mc.y = 0;
for (i=0; i<objectsTotal; i++) {
var obj:menuItems = new menuItems();
obj.gotoAndStop(i+2);
obj.angle = i * ((Math.PI*2)/objectsTotal);
object_mc.addChild(obj);
obj.addEventListener(Event.ENTER_FRAME, rotator);
//----------event
Listener-----------------------------------//
//--------event handler to animate the
menu-------------------------//
function rotator(event:Event)
//calculate value
event.target.x = Math.cos(event.target.angle) * radiusX +
Xcenter;
event.target.y = Math.sin(event.target.angle) * radiusY +
Ycenter;
//speed
//event.target.angle += event.target.parent.speed;
//resize
var size:Number = new
Number(event.target.y/(Ycenter+radiusY));
event.target.xscale = event.target.scaleX = size * 1;
event.target.yscale = event.target.scaleY = size * 1;
//alpha
event.target._alpha = 100 * size;
//event.target.swapDepths(Math.round(event.target.scaleX)+50);
event.target.addEventListener(MouseEvent.MOUSE_MOVE, spin);
trace(event.target.x +" "+ event.target.y);
function spin(event:MouseEvent)
speed = (event.target.mouseX-Xcenter)/3000;
//trace(object_mc.x + object_mc.y);
Anyways I think the problem lies in these lines of code:
//event.target.angle += event.target.parent.speed;
and
//event.target.swapDepths(Math.round(event.target.scaleX)+50);
of course my whole approach could be wrong, right? classes
maybe? I don't know but I've been at it for a while now....
please help.
vErGinstead of using a menuitem class create a loader subclass that loads and sizes your images.
-
Hi all,
how to set the FLV Playback Custom UI's mute button to
default state to "OFF"?
Any ideas?In case I don't come back:
AS2:
Drag the component on stage, double click to get inside.
Create a new layer and open up the actions panel, add this:
off_mc.swapDepths(on_mc);
AS3:
Drag the component on stage, click it once and give it an
instance name of, mute_btn, create a new layer and open the actions
panel, add this:
mute_btn.setChildIndex(mute_btn.getChildAt(1), 0);
**Notice Difference**
AS2 you go into the component to add the actions, and the
instance names are already there by default. AS3 you need to give
the component an instance name, and don't go into the component,
put that script on the main stage. -
I have converted AS2 Carousel to AS3 and it works fine without swapDepth line, which is:
this.swapDepths(Math.round(this._xscale) + 100);
I need to convert this line to AS3 ... it's very important because it prevents overlapping between layers.
the place for this line should be inside "mover" function.
My Code is:
var numOfItems:Number = 5;
var radiusX:Number = 200;
var radiusY:Number = 30;
var speed:Number = 0.05;
var arrItems:Array = new Array();
//var angle:Number = 0;
for (var i:uint = 0; i < numOfItems; i++){
var t:dress1 = new dress1();
t.angle = i * ((Math.PI*2) / numOfItems);
addChild(t);
t.addEventListener(Event.ENTER_FRAME, mover);
t.addEventListener(MouseEvent.MOUSE_OVER, over);
t.addEventListener(MouseEvent.MOUSE_OUT, out);
var centerX:Number = stage.stageWidth / 2 - t.width / 2;
var centerY:Number = stage.stageHeight / 2 - t.height / 2;
function mover (e:Event):void {
e.currentTarget.x = Math.cos(e.currentTarget.angle) * radiusX + centerX;
e.currentTarget.y = Math.sin(e.currentTarget.angle) * radiusY + centerY;
var s:Number = e.currentTarget.y / (centerY + radiusY);
e.currentTarget.scaleX = e.currentTarget.scaleY = s * 1.5;
e.currentTarget.angle += speed;
var test = speed;
function over (e:Event):void {
speed = 0;
function out (e:Event):void {
speed = test;
Thanks and Regrads,
SPrinceyou'll need to check those angles and use addChild() to move a dress1 to the top.
-
Convert as2 code to as3 please help
function fDieList()
if (pDieList.length > 0)
_root.inSFX.die.start();
for (var _loc2 = 0; _loc2 <= pDieList.length; ++_loc2)
pDieList[_loc2].fDie();
} // end of for
pDieList = [];
actioner.pKills = true;
} // end if
} // End of the function
function fDieListSetup()
if (pDieList.length > 0)
for (var _loc1 = 0; _loc1 <= pDieList.length; ++_loc1)
pDieList[_loc1].fDieSetup();
} // end of for
} // end if
} // End of the function
function recur(fromx, fromy, tox, toy)
var _loc2 = fromy;
var _loc1 = fromx;
var _loc3 = toy;
if (_loc1 == tox && _loc2 == _loc3)
return (true);
else
++len;
drum[len][0] = _loc1;
drum[len][1] = _loc2;
wa[_loc1][_loc2] = 1;
if (_loc1 > tox && _loc2 > _loc3)
if (_loc1 > 1 && wa[_loc1 - 1][_loc2] == 0)
ok = recur(_loc1 - 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc2 > 1 && wa[_loc1][_loc2 - 1] == 0)
ok = recur(_loc1, _loc2 - 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc1 < limits && wa[_loc1 + 1][_loc2] == 0)
ok = recur(_loc1 + 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc2 < limits && wa[_loc1][_loc2 + 1] == 0)
ok = recur(_loc1, _loc2 + 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
else if (_loc1 <= tox && _loc2 > _loc3)
if (_loc2 > 1 && wa[_loc1][_loc2 - 1] == 0)
ok = recur(_loc1, _loc2 - 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc1 < limits && wa[_loc1 + 1][_loc2] == 0)
ok = recur(_loc1 + 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc2 < limits && wa[_loc1][_loc2 + 1] == 0)
ok = recur(_loc1, _loc2 + 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc1 > 1 && wa[_loc1 - 1][_loc2] == 0)
ok = recur(_loc1 - 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
else if (_loc1 > tox && _loc2 <= _loc3)
if (_loc1 > 1 && wa[_loc1 - 1][_loc2] == 0)
ok = recur(_loc1 - 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc2 < limits && wa[_loc1][_loc2 + 1] == 0)
ok = recur(_loc1, _loc2 + 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc1 < limits && wa[_loc1 + 1][_loc2] == 0)
ok = recur(_loc1 + 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc2 > 1 && wa[_loc1][_loc2 - 1] == 0)
ok = recur(_loc1, _loc2 - 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
else
if (_loc2 < limits && wa[_loc1][_loc2 + 1] == 0)
ok = recur(_loc1, _loc2 + 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc1 < limits && wa[_loc1 + 1][_loc2] == 0)
ok = recur(_loc1 + 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc2 > 1 && wa[_loc1][_loc2 - 1] == 0)
ok = recur(_loc1, _loc2 - 1, tox, _loc3);
if (ok)
return (ok);
} // end if
} // end if
if (_loc1 > 1 && wa[_loc1 - 1][_loc2] == 0)
ok = recur(_loc1 - 1, _loc2, tox, _loc3);
if (ok)
return (ok);
} // end else if
} // end else if
} // end else if
--len;
return (ok);
} // end else if
} // End of the function
function way(fromx, fromy, tox, toy)
len = 0;
ok = false;
for (i = 1; i <= limits; i++)
for (j = 1; j <= limits; j++)
wa[i][j] = ma[i][j];
} // end of for
} // end of for
wa[fromx][fromy] = 0;
return (recur(fromx, fromy, tox, toy));
} // End of the function
function init()
var _loc2 = _root;
scorerule = new Array(40, 50, 60, 70, 80);
score = 0;
totalballs = 7;
nextballs = 3;
limits = 9;
kkk = 1000;
xnext = next1._x - 19;
ynext = next1._y + 21;
ballsput = 0;
drum = new Array();
wa = new Array();
st = new Array();
for (i = 1; i <= limits * limits; i++)
drum[i] = new Array(0, 0);
} // end of for
for (i = 1; i <= limits * limits; i++)
wa[i] = new Array(limits + 1);
} // end of for
selected = new Array(0, 0);
ma = new Array();
for (i = 1; i <= limits; i++)
ma[i] = new Array(limits + 1);
for (j = 1; j <= limits; j++)
ma[i][j] = 0;
_loc2.inGame["balls" + i + j].x = i;
_loc2.inGame["balls" + i + j].y = j;
} // end of for
} // end of for
nextarray = new Array();
for (i = 1; i <= nextballs; i++)
nextarray[i] = new Array(0, 0, 0);
attachMovie("balls", "nextballs" + i, kkk++);
_loc2.inGame["nextballs" + i]._x = xnext;
_loc2.inGame["nextballs" + i]._y = ynext + i * 60;
_loc2.inGame["nextballs" + i]._xscale = 140;
_loc2.inGame["nextballs" + i]._yscale = 140;
} // end of for
actioner2.swapDepths(20000);
} // End of the function
function generatenext()
var _loc2 = _root;
if (ballsput <= 81 - nextballs)
togenerate = nextballs;
else
togenerate = 81 - ballsput;
} // end else if
for (i = 1; i <= togenerate; i++)
do
x = random(limits) + 1;
y = random(limits) + 1;
} while (ma[x][y] != 0)
nextarray[i][0] = random(totalballs) + 1;
nextarray[i][1] = x;
nextarray[i][2] = y;
_loc2.inGame["nextballs" + i].gotoAndStop(nextarray[i][0] + 1);
_loc2.inGame["nextballs" + i].buton._visible = false;
} // end of for
for (i = togenerate + 1; i <= nextballs; i++)
_loc2.inGame["nextballs" + i].gotoAndStop("blank");
} // end of for
nextballs3.buton._visible = false;
} // End of the function
function putnextballs()
var _loc2 = _root;
_loc2.inSFX.grow.start();
if (ballsput <= 81 - nextballs)
togenerate = nextballs;
else
togenerate = 81 - ballsput;
} // end else if
for (i = 1; i <= togenerate; i++)
if (ma[nextarray[i][1]][nextarray[i][2]] == 0)
ma[nextarray[i][1]][nextarray[i][2]] = nextarray[i][0];
else
do
x = random(limits) + 1;
y = random(limits) + 1;
} while (ma[x][y] != 0)
nextarray[i][1] = x;
nextarray[i][2] = y;
ma[nextarray[i][1]][nextarray[i][2]] = nextarray[i][0];
} // end else if
_loc2.inGame["balls" + nextarray[i][1] + nextarray[i][2]].gotoAndStop(nextarray[i][0] + 1);
line(nextarray[i][1], nextarray[i][2], ma[nextarray[i][1]][nextarray[i][2]]);
} // end of for
ballsput = ballsput + togenerate;
if (ballsput == limits * limits)
_loc2.fEndGame();
} // end if
} // End of the function
function line(x, y, c)
var _loc4 = 0;
var _loc6 = new Array();
var _loc5 = new Array();
var _loc2 = new Array();
var _loc3 = new Array();
for (var _loc4 = 1; _loc4 <= limits; ++_loc4)
_loc6[_loc4] = new Array(2);
_loc5[_loc4] = new Array(2);
_loc2[_loc4] = new Array(2);
_loc3[_loc4] = new Array(2);
} // end of for
var _loc7 = 0;
fl = 0;
for (var _loc4 = 1; _loc4 <= limits; ++_loc4)
if (ma[_loc4][y] == c)
if (fl == 0)
++_loc7;
_loc6[_loc7][0] = _loc4;
_loc6[_loc7][1] = y;
} // end if
continue;
} // end if
if (_loc7 < 4)
_loc7 = 0;
continue;
} // end if
fl = 1;
} // end of for
st1 = 0;
fl = 0;
for (var _loc4 = 1; _loc4 <= limits; ++_loc4)
if (ma[x][_loc4] == c)
if (fl == 0)
++st1;
_loc5[st1][0] = x;
_loc5[st1][1] = _loc4;
} // end if
continue;
} // end if
if (st1 < 4)
st1 = 0;
continue;
} // end if
fl = 1;
} // end of for
fl = 0;
st2 = 0;
imin = x;
for (jmin = y; imin > 1 && jmin > 1; jmin--)
--imin;
} // end of for
imax = x;
for (jmax = y; imax < limits && jmax < limits; jmax++)
++imax;
} // end of for
if (imin == 1)
for (var _loc4 = imin; _loc4 <= imax; ++_loc4)
if (ma[_loc4][jmin + _loc4 - 1] == c)
if (fl == 0)
++st2;
_loc2[st2][0] = _loc4;
_loc2[st2][1] = jmin + _loc4 - 1;
} // end if
continue;
} // end if
if (st2 < 4)
st2 = 0;
continue;
} // end if
fl = 1;
} // end of for
else
for (var _loc4 = jmin; _loc4 <= jmax; ++_loc4)
if (ma[imin + _loc4 - 1][_loc4] == c)
if (fl == 0)
++st2;
_loc2[st2][0] = imin + _loc4 - 1;
_loc2[st2][1] = _loc4;
} // end if
continue;
} // end if
if (st2 < 4)
st2 = 0;
continue;
} // end if
fl = 1;
} // end of for
} // end else if
fl = 0;
st3 = 0;
imin = x;
for (jmin = y; imin > 1 && jmin < limits; jmin++)
--imin;
} // end of for
imax = x;
for (jmax = y; imax < limits && jmax > 1; jmax--)
++imax;
} // end of for
if (imin == 1)
for (var _loc4 = imin; _loc4 <= imax; ++_loc4)
if (ma[_loc4][jmin - _loc4 + 1] == c)
if (fl == 0)
++st3;
_loc3[st3][0] = _loc4;
_loc3[st3][1] = jmin - _loc4 + 1;
} // end if
continue;
} // end if
if (st3 < 4)
st3 = 0;
continue;
} // end if
fl = 1;
} // end of for
else
for (var _loc4 = jmax; _loc4 <= jmin; ++_loc4)
if (ma[jmin - _loc4 + jmax][_loc4] == c)
if (fl == 0)
++st3;
_loc3[st3][0] = jmin - _loc4 + jmax;
_loc3[st3][1] = _loc4;
} // end if
continue;
} // end if
if (st3 < 4)
st3 = 0;
continue;
} // end if
fl = 1;
} // end of for
} // end else if
destroyed = 0;
if (_loc7 >= 4)
for (var _loc4 = 1; _loc4 <= _loc7; ++_loc4)
pDieList.push(_root.inGame["balls" + _loc6[_loc4][0] + _loc6[_loc4][1]]);
ma[_loc6[_loc4][0]][_loc6[_loc4][1]] = 0;
} // end of for
destroyed = destroyed + _loc7;
score = score + scorerule[_loc7 - 4];
} // end if
if (st1 >= 4)
for (var _loc4 = 1; _loc4 <= st1; ++_loc4)
pDieList.push(_root.inGame["balls" + _loc5[_loc4][0] + _loc5[_loc4][1]]);
ma[_loc5[_loc4][0]][_loc5[_loc4][1]] = 0;
} // end of for
destroyed = destroyed + st1;
score = score + scorerule[st1 - 4];
} // end if
if (st2 >= 4)
for (var _loc4 = 1; _loc4 <= st2; ++_loc4)
pDieList.push(_root.inGame["balls" + _loc2[_loc4][0] + _loc2[_loc4][1]]);
ma[_loc2[_loc4][0]][_loc2[_loc4][1]] = 0;
} // end of for
destroyed = destroyed + st2;
score = score + scorerule[st2 - 4];
} // end if
if (st3 >= 4)
for (var _loc4 = 1; _loc4 <= st3; ++_loc4)
pDieList.push(_root.inGame["balls" + _loc3[_loc4][0] + _loc3[_loc4][1]]);
ma[_loc3[_loc4][0]][_loc3[_loc4][1]] = 0;
} // end of for
destroyed = destroyed + st3;
score = score + scorerule[st3 - 4];
} // end if
if (destroyed >= 10)
--destroyed;
} // end if
ballsput = ballsput - destroyed;
scoretxt = score;
if (destroyed != 0)
fDieListSetup();
_root.inSFX.pickup.start();
} // end if
return (destroyed != 0);
} // End of the function
function fromactioner(fromx, fromy, tox, toy)
var _loc3 = toy;
var _loc2 = tox;
var _loc4 = fromy;
ma[_loc2][_loc3] = ma[fromx][_loc4];
ma[fromx][_loc4] = 0;
_root.inGame["balls" + fromx + _loc4].gotoAndStop("blank");
_root.inGame["balls" + fromx + _loc4].ball.gotoAndStop(1);
_root.inGame["balls" + _loc2 + _loc3].gotoAndStop(ma[_loc2][_loc3] + 1);
_root.inGame["balls" + _loc2 + _loc3].ball.gotoAndStop(1);
selected[0] = 0;
selected[1] = 0;
line(_loc2, _loc3, ma[_loc2][_loc3]);
actioner.gotoAndPlay(2);
} // End of the function
function move(fromx, fromy, tox, toy)
var _loc2 = _root;
var _loc3 = false;
if (way(fromx, fromy, tox, toy))
_loc3 = true;
fromactioner(fromx, fromy, tox, toy);
_loc2.inGame["balls" + _loc2.inGame.drum[ii][0] + _loc2.inGame.drum[ii][1]].gotoAndStop("blank");
} // end if
return (_loc3);
} // End of the function
function movetest(fromx, fromy, tox, toy)
var _loc1 = false;
if (way(fromx, fromy, tox, toy))
_loc1 = true;
} // end if
return (_loc1);
} // End of the function
pLastClicked = "none";
pLastClickedType = 1;
pClicked = false;
pDieList = [];
init();
generatenext();
putnextballs();
generatenext();
stop ();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. -
Hello folks! Looking for a little technical advice - let me
explain:
I'm converting a small flash game that I had built in flash 8
with as2 to flash 9 with as3 and have hit a snag. The visible
object on the stage in that application is simialr to a rubiks cube
as seen from an upper corner (sort of an isometric view). There are
mutliple rows and columns and levels...lets just say it's a 3x3x3
cube. Through gameplay various cubes are moved around, added and
removed from the grid, sometimes a slot is empty sometimes full. In
order to track this and make sure that the cubes stay at the proper
depth relative to each other I had assigned each slot in the full
grid a grid number incremented by 10's for rowsand 100's for layers
and stored the numbers in an array. Then when I added a cube to the
stage I just looked up its depth value from the array, attached it
and appended its number to it's instance name and set it's depth to
the same number . Nothing ever got at an improper depth becuase
every slot had a fixed absolute number that could be pulled from
the array. My problem is that the new depth manager won't allow
gaps - each depth needs to be used before the next one can be used,
and that when you insert someting at an occupied depth everything
above it is pushed up by one so I can't track any of my cubes depth
as I had been becuase they keep changing.
Example: I'm my old system if I needed to move the first row
of cubes from the 3rd layer (cubes 310, 320, 330) straight down
into the second layer I would simply move them then swapdepth to
210, 220, 230. In the new system since i cant reserve a depth for
an empty slot I never know what number to move the cube to without
a convoluted lookup process, and once I do move it...every single
depth after it gets altered (which seems like a lot of extra work
for the system by the way)
So...anyone know a better way to manage depths of a 3
dimensional grid in as3?Personally, I think the new depth system introduces more
problems than it fixes.
One advantage in AS3, though, is that you can move a
DisplayObject from one DisplayObjectContainer to another.
[edit] Oops, GWD already mentioned this, so I'm basically
re-iterating what he said [/edit]
So based on your setup, it might be helpful to make different
container clips for each "layer" as you described it. Then you can
simply move the rows into the different containers, and the
containers are at different depths. -
I'm making photo gallery where photos will be loaded from external xml file but i have problem. I want to add an effect when photo is changing like on this site: http://www.studiomelon.pl/index.html#/1/ Could somebody help me with that? I am noob in flash so please explain it as clear as you can. Thanks.
I was sesrching for that for a long time before i created this tread. There is many tutorials and exaple files for page flip or page turn but i cant find good one. Many of them was coded in as1 or as2 other using php and java script so its difficult to understant. I just want one simple solution for that. It cant be so hard to create something like that. Could you help me to find some good and simple tutorial in as3?
-
Creating an "if" Statement in AS3
I've been having a problem trying to implement 2 email forms in the same scene at different places in the timeline. If I do just one form, there isn't a problem, but there is a problem with the 2nd form (I've tried using different instance names to no avail). However, it appears I have most of it figured out, but am still having a problem, which I believe I may have a solution for by using an "if" statement. In the following AS3 code is a string that reads var URL_request:URLRequest = new URLRequest( "send_email.php" ); I believe I may be able to resolve the problem if I had a 2nd string (in the same code) that read var URL_request:URLRequest = new URLRequest( "send_email_02.php" ); Is there a way to include that string in the same AS3 by using an "if" statement telling the code to "submit" the 2nd form? If so, could someone please give me an example of how to write that "if" statement? This form has been driving me nuts for 4 days now and any help would be greatly appreciated. Thank you.
stop();
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = "";
send_button.addEventListener(MouseEvent.CLICK, submit);
reset_button.addEventListener(MouseEvent.CLICK, reset);
var timer:Timer;
var var_load:URLLoader = new URLLoader;
var URL_request:URLRequest = new URLRequest( "send_email.php" );
URL_request.method = URLRequestMethod.POST;
function submit(e:MouseEvent):void
if( contact_name.text == "" || contact_email.text == "" ||
contact_subject.text == "" || contact_message.text == "" )
message_status.text = "Please complete all text fields.";
else if( !validate_email(contact_email.text) )
message_status.text = "Please enter a valid email address.";
else
message_status.text = "sending...";
var email_data:String = "name=" + contact_name.text
+ "&email=" + contact_email.text
+ "&subject=" + contact_subject.text
+ "&message=" + contact_message.text;
var URL_vars:URLVariables = new URLVariables(email_data);
URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
URL_request.data = URL_vars;
var_load.load( URL_request );
var_load.addEventListener(Event.COMPLETE, receive_response );
function reset(e:MouseEvent):void
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = "";
function validate_email(s:String):Boolean
var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var r:Object = p.exec(s);
if( r == null )
return false;
return true;
function receive_response(e:Event):void
var loader:URLLoader = URLLoader(e.target);
var email_status = new URLVariables(loader.data).success;
if( email_status == "yes" )
message_status.text = "Success! Your message was sent.";
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
else
message_status.text = "Failed! Your message was not sent.";
function on_timer(te:TimerEvent):void
if( timer.currentCount >= 10 )
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = "";
timer.removeEventListener(TimerEvent.TIMER, on_timer);While the overall scenario isn't all that clear to me, you don't necessarily need an if statement, but just have the different submit buttons assign the different URL_request values before they intiate any other processing.
-
Hi,
I upload a website and I have problems with the preloader did it in AS3. It starts after two or three minutes. I have a MC with an animation of 100 frames and the dynamic text of the percent. The preloader is located in the 1 frame to the 10, I mean, first frame with the actions and the other three layers (text, MC and background) with a lenght of 10. The movie has 525 frames. Here is the code:
stop();
addEventListener(Event.ENTER_FRAME, lodeando);
function lodeando(event:Event):void
var bytesTotales = stage.loaderInfo.bytesTotal;
var bytesCargados = stage.loaderInfo.bytesLoaded;
var porcentaje = Math.round(bytesCargados * 100 / bytesTotales);
textoPorcentaje.text = porcentaje + "% Cargados";
cargaAnimada_mc.gotoAndStop(porcentaje);
if (bytesCargados == bytesTotales)
removeEventListener(Event.ENTER_FRAME, lodeando);
gotoAndPlay(2);
textoPorcentaje.text = "";
removeChild(textoPorcentaje);
removeChild(cargaAnimada_mc);
Please, Could you help me?.These screen captures show the library of the movie. As you can see I export the most of them. However I have doubts about if I must convert to symbol the graphics. I have the preloader in the "presentación" folder without any exportation.
Please, Could you correct the website?. Please, tell me an e-mail address and I send you the website via WeTransfer. -
I have a text input field on the timeline that I want the user to enter specific information in. When that information is correctly entered, I need the timeline to progress.
I successfully used the following AS2, but I cant find corresponding code for AS3
on (keyPress "x") {
gotoAndPlay("s05");
Any help on converting this function to AS3 is greatly appreciated.You can use an Event.CHANGE listener for the textfield and then test its value in the event handler function to see if it agrees with the required string...
inputtField.addEventListener(Event.CHANGE, testEntry);
function testEntry(evt:Event):void {
if(inputField.text == "whatever"){
// do stuff -
Basically, the buttons are not visible when siteplan_mc is replayeed after floorplan closes, but they still work. Most things are only working on double click for soe reason, tho I have them to function on click. and the back button only woorks on unit 1 floorplan, tho the code it the same for all floorplans. I have a feeling it has something to do with levels... but I really have no idea... hopefully someone can help!
thanks in advance,
Sarah
http://www.30eastroosevelt.com/RRHA_SITE.flaThere are at least two things you're doing wrong. You can't go to a frame where something exists for the first time, and immediately do something to it. Like in your playunit functios for example:
gotoAndStop("unit1")
unit1_mc.alpha = 1
unit1_mc hasn't yet drawn itself on stage to have its alpha set, and so there's an error. That is something that was improved in Flash 10, so if you had set the Flash to publish for Flash 10 and not Flash 9, then the floor plans and the back buttons appears ok. It would sometimes work with double clicks because by the second time you clicked, the movieclip now existed. You might be able to do what you want by having all of the room units on frame 1 of the siteplan_mc, and then set their visible to true or false as you need them, instead of doing the gotoAndStop().
The other problem is that you're trying to set listeners on the Back buttons that don't yet exist. Wait until you're on the frame where the buttons exists, and then set its listener for the mouse click.
Other things you're doing could be improved too, but really you might want to get together with someone who has done more AS3, to help you become more familiar with how it works. -
Hello, relatively new to AS3 and flash, this is the first time i am publishing anything. We are trying to upload our simple flashgame to our webserver, the game works perfectly fine locally save for one thing. We get an error regarding TLF which says it wont stream or something. So when it gets online, no sounds play and spacebar doesn't work, left and right arrow does work. We have three TLF text fields that are used to update score, lives and show you final score. If i turn these into classical text they stop working.
Things we have tried: Changing default linkage from RLS to Merged into code, changing the text boxes to classical text(they then stop working), made sure the paths are correct(all files are in the same directory including the .swz file)
This is the code from the soundclass:
package
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.*;
public class MySound
private var bgSound:Sound;
private var fireSound:Sound;
private var waterSound:Sound;
private var earthSound:Sound;
private var lightSound:Sound;
private var soundChannel:SoundChannel;
public function MySound()
soundChannel = new SoundChannel();
bgSound = new Sound();
var req:URLRequest = new URLRequest("BackgroundSound.mp3");
bgSound.load(req);
//fire
fireSound = new Sound();
var req2:URLRequest = new URLRequest("soundFire.mp3");
fireSound.load(req2);
// water
waterSound = new Sound();
var req3:URLRequest = new URLRequest("soundWater.mp3");
waterSound.load(req3);
// earth
earthSound = new Sound();
var req4:URLRequest = new URLRequest("soundEarth.mp3");
earthSound.load(req4);
// light
lightSound = new Sound();
var req5:URLRequest = new URLRequest("soundLight.mp3");
lightSound.load(req5);
public function playBgSound()
soundChannel = bgSound.play(0, 999999);
public function stopBgSound()
soundChannel.stop();
public function playFireSound()
fireSound.play();
public function playWaterSound()
waterSound.play();
public function playEarthSound()
earthSound.play();
public function playLightSound()
lightSound.play();
I can somewhat get that sound can bugg out, but why does spacebar stop functioning? ANy help is greatly appreciated as this has to be delivered in twelve hours(published online) for a school assignment.Also might add publishing it locally in my own browser everything works, as does ofcourse playing it in flash itself. Changing from RLS to merged into code stops the error from coming, but doesn´t fix the problem on the server.
Code from main class related to sound and spacebar:
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.text.TextField;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class main extends MovieClip
private var fireTimer:Timer; //delay between shots
private var canFire:Boolean = true;
private var mySound:MySound;
private var bulletSpeed:Number = -450;
public function main()
//load sounds
mySound = new MySound();
private function playGame(event:MouseEvent)
gotoAndStop(2);
// initialize
myLives = 5;
myHitsNo = 0;
weaponType = 1;
mybullets = new Array();
enemys = new Array();
myScoreTxt.text = "Score: " + myHitsNo;
myLivesTxt.text = "Lives: " + myLives;
fireTimer = new Timer(400, 1);
fireTimer.addEventListener(TimerEvent.TIMER, shootTimerHandler, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_DOWN, listenKeyDown);
stage.addEventListener(Event.ENTER_FRAME, addEnemy);
stage.addEventListener(Event.ENTER_FRAME, checkCollision);
player = new thePlayer(stage.stageWidth-40, spawnPoint2);// stage.stageHeight/2);
stage.focus = player;
addChild(player);
mySound.playBgSound();
public function listenKeyDown(event:KeyboardEvent) // Controls and weapontype selector
if (event.keyCode == 37) //left
player.movethePlayerDown();
if (event.keyCode == 39) //right
player.movethePlayerUp();
if (event.keyCode == Keyboard.SPACE) //space
shootBullet();
//soundFX.attachSound("Pistol Fire.wav");
//soundFX.start(); -
How to use as3 in flash cs3 to add dynamic text from a text file into a flash file
let me start out by saying today is my first day of scripting
in flash.
I have a text file text.txt
it contains
text1=hello world
can someone please show me how to display this text in a
flash file
i have been searching for this for hours and there are
solutions with flash mx and actionscript 2.0 but i would like to
see how to do this in as3.
just a simple frame that loads that file and displays it when
you test run the program
much apreciated
RCI'm not up on AS3 yet, but many things are still similar. You
need to use the LoadVars class to accomplish this, You can find
information this in Flahs Help>Actionscript>Actionscript
Language Reference>Actionscript classes.
rem: the text.txt file and the text.fla file must be in the
same directory.
The code will look something like this: -
AS3 Scripting for Animated GIF
Hi,
I am trying to create an animated GIF for a white noise animation (needed for those viewers who don't have access to a Flash player). The SWF version runs perfectly. Currently, all of the AS3 for the bitmapData.noise and bitmapData.palettemap script is in the first keyframe. So, when I export as an animated GIF, I get a white screen in playback.
I think the problem for the animated GIF is that there are no frames past the first frame. But, I am not sure how to add frames or re-write the AS3 to get a 30 second animated GIF? I tried duplicating the first keyframe into several new keyframes and get error messages. I would appreciate any help.
Here's the AS3 in the first keyframe that works well for a SWF (previous relevant thread: http://forums.adobe.com/thread/734335?tstart=0):
var array:Array=new Array();
for (var i:uint = 0; i < 255; i++) {
array[i] = 0xffffff * (i % 2);
var _bitmapData:BitmapData;
var bDHolder:Sprite = new Sprite();
_bitmapData = new BitmapData(stage.stageWidth/4, stage.stageHeight/4);
bDHolder.addChild(new Bitmap(_bitmapData));
bDHolder.scaleX = bDHolder.scaleY = 4;
addChild(bDHolder);
addEventListener(Event.ENTER_FRAME, onSpriteEnterFrame);
function makeNoise():void {
_bitmapData.noise(getTimer(), 100, 255, 7, true);
_bitmapData.paletteMap(_bitmapData, _bitmapData.rect, new Point(0,0), array, array,array);
function onSpriteEnterFrame(event:Event):void {
makeNoise();
var itsNoisy:Boolean = true;
stage.addEventListener(MouseEvent.MOUSE_DOWN, manageNoise);
function manageNoise(evt:MouseEvent):void {
if(itsNoisy){
removeEventListener(Event.ENTER_FRAME, onSpriteEnterFrame)
} else {
addEventListener(Event.ENTER_FRAME, onSpriteEnterFrame)
itsNoisy = !itsNoisy;
Kind Regards,Jimmy,
You may (also) try to ask in the (most) relevant Photoshop forum.
http://forums.adobe.com/community/photoshop -
How to read a local file using as3 in a flash object in HTML? [urgent]
My web site contains a flash object.
I want to use as3 to read some local .txt file
by getting the user directory of the file.
i know AIR can support this by sth like:
File.desktopDirectory.resolvePath
but when i open a AIR file for this, it seems
the action cant be run when i embed it in html.
And i tried to use the above function in a normal
flash file in the action script.
But it cant recognize the File. class..
How can it be done ?
It's reli urgent,
please help...
Thanks !a web based flash app can't detect user directories. you can use the filereference class'es browse method to let the user locate a file in any directory the user wants. flash can then retrieve the file's name and type. but, as mentioned before, flash can't determine the file's directory.
Maybe you are looking for
-
I have Lion as my current and main OS. Is it possible to partition part of my hard drive for Snow Leopard? I'm good on partitioning but when I insert the Snow Leopard install disk a message tells me I can't run the install program because I currently
-
hi, i have to display a report using ldb PNPCE .Displayed Data should be between the date period entered in selection-screen. say pn-begda = 11.02.2008 and pn-endda = 17.02.2008.for this i hav written code GET PERAS. PROVIDE massn massg begda pernr s
-
Huge Delay in accessing DataBase When Net is down
Hi, I am using MySQL 4.1.9 as the backend for my Java Application On Linux Fedora Core III. MySQL and the Java Application, both resides in the same host. When net (Internet) is Up, there is no delays in accessing MySQL Databases. And its too slow wh
-
VZW not honering advertised pricing
I recently upgraded my "feature" phone and my wife's feature phone to two new free iPhone 4 smart phones using Verizon's website. During the checkout process I confirmed with customer service that I would be charged $80.00 per month (plus taxes) for
-
Scroll entire panels into view
A pet peeve of mine is that, when opening a panel, sometimes LR 2.1 doesn't scroll it entirely into view when it could have. Specifically, I use Solo mode, I'm in Develop using the Basic panel and I then click on the Tone Curve panel to open it up. T