Flex mobile Button skinning in ActionScript - multiline labelDisplay - actionscript-3

I am working on a Flex mobile application, and have been optimizing its performance on mobile. I have read that skins must be written in ActionScript so I have tried to create my AS ButtonSkin.
public class mButtonSkin extends ButtonSkin
{
private static var colorMatrix:Matrix = new Matrix();
protected var radiusX:Number = 12;
protected var mAngle:Number = 30;
protected var labelWidth:Number;
protected var labelHeight:Number;
protected var paddingLeft:Number = 12;
protected var paddingRight:Number = 12;
protected var paddingTop:Number = 2;
protected var paddingBottom:Number = 2;
public function mButtonSkin() {
super();
}
override protected function drawBackground(unscaledWidth:Number,unscaledHeight:Number) : void {
colorMatrix.createGradientBox(width,height,mAngle);
if (currentState == "up") {
graphics.beginGradientFill(GradientType.LINEAR,
[hostComponent.getStyle("fill3"),hostComponent.getStyle("fill1")], [1,1], [0,255], colorMatrix);
} else {
graphics.beginFill(hostComponent.getStyle("fill4"));
}
graphics.lineStyle(0.5,hostComponent.getStyle("borderColor"),0.5);
graphics.drawRoundRect(0,0,hostComponent.width,hostComponent.height,12);
graphics.endFill();
}
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number) : void {
labelDisplay.wordWrap = true;
labelDisplay.multiline = true;
labelDisplay.commitStyles();
labelWidth = width - paddingLeft - paddingRight;
labelHeight = height - paddingTop - paddingBottom;
var x:Number = width / 2 - labelWidth / 2;
var y:Number = height / 2 - getElementPreferredHeight(labelDisplay) / 2;
setElementSize(labelDisplay,labelWidth,labelHeight);
setElementPosition(labelDisplay,x,y);
}
override protected function labelDisplay_valueCommitHandler(event:FlexEvent) : void {
labelDisplayShadow.text = "";
}
}
Applying this skin in my buttons:
Button labelDisplay has wrong alignment (verticalAlignment must be middle).
After clicking the button:
My button's labelDisplay is now vertically-aligned to middle.
Did i miss something? What have I done wrong?

on the layoutContents function, before positioning the labelDisplay element, i checked first whether it's numLines property is greater than 1. here's my updated function:
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number) : void {
labelDisplay.wordWrap = true;
labelDisplay.multiline = true;
labelWidth = width - paddingLeft - paddingRight;
labelHeight = height - paddingTop - paddingBottom;
var x:Number = width * .5 - labelWidth * .5;
var y:Number = height * .5 - getElementPreferredHeight(labelDisplay) * .5;
setElementSize(labelDisplay,labelWidth,labelHeight);
if (labelDisplay.numLines == 1)
setElementPosition(labelDisplay,x,y);
else
setElementPosition(labelDisplay, x, labelDisplay.getLayoutBoundsY());
}
this solution may not be useful to other devs out there but it solved my problem.

Related

AS3 Issues with Rotation

I have a fairly basic app where you navigate menus and then access videos and demos.
My issue is that when you access a video, it forces you to rotate the screen first.
By using stage.scaleMode = Stage.ScaleMode.NO_SCALE I was able to make it work perfectly on my iPhone 7, but I can't find a way to scale up for iPhone 8 or 10.
I've been trying to use other StageScaleModes, and they work perfectly for the menus but when the screen is rotated, the scale becomes insanely wonky.
It either stays within the original aspect ratio or becomes much to big for the screen.
I've tried using stage.stageWidth and stage.stageHeight to correct this but they never return the correct size.
Any help in either fixing the issue in rotation or making NO_SCALE work would be greatly appreciated.
EDIT:
public function playVideo(path2: String): Function {
path = path2;
var listener: * ;
listener = function (e: MouseEvent = null): void {
stage.addChild(pleaseRotateScreen);
stage.autoOrients = true;
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener_Videos);
}
return listener;
}
function orientationChangeListener_Videos(e: StageOrientationEvent) {
if (e.afterOrientation == StageOrientation.ROTATED_RIGHT || e.afterOrientation == StageOrientation.ROTATED_LEFT) {
stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener_Videos);
stage.autoOrients = false;
stage.removeChild(pleaseRotateScreen);
startVideo();
}
}
EDIT2
public function startVideo(): void { //bring up the video UI.
stage.displayState = StageDisplayState.FULL_SCREEN;
headerTextField = new TextField();
headerTextField.autoSize = TextFieldAutoSize.LEFT;
var theFont = new BrownReg();
var rectClip: Sprite = new Sprite();
headerTextField.autoSize = "left";
//headerTextField.text = pageClip2.uiText;
headerTextField.text = "Stage Width: " + stage.width + " Stage.Height: " + stage.stageHeight;
headerTextField.selectable = false;
backPlate = new MovieClip;
backPlate.graphics.beginFill(0x000000);
backPlate.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
backPlate.graphics.endFill();
overlay = new blackOverlay;
video_UI.addChild(overlay);
overlay.addEventListener(MouseEvent.CLICK, bringUpVideoUI);
mcScroll.addChild(backPlate);
TweenLite.to(menu_clip, .4, { alpha: 0, ease: Expo.easeOut });
TweenLite.to(screen_clip, .4, { alpha: 0, ease: Expo.easeOut });
TweenLite.to(pageClip, .4, { alpha: 0, ease: Expo.easeOut });
TweenLite.to(mcScroll, .4, { alpha: 0, ease: Expo.easeOut });
TweenLite.to(topbar_clip, .4, { alpha: 0, ease: Expo.easeOut });
video_UI.addChild(gradientVid);
gradientVid.y = 750 - 100;
X_UI = new videoX;
X_UI.x = (1254+24); X_UI.y = (678+24);
video_UI.addChild(X_UI);
X_UI.addEventListener(MouseEvent.CLICK, closeVideo);
pauseUI = new MovieClip;
pauseUI.addChild(pauseClip);
pauseUI.x = (140+24); pauseUI.y = (672+30);
video_UI.addChild(pauseUI);
pauseUI.addEventListener(MouseEvent.CLICK, pauseVid);
jumpBackUI = new mcFastForward;
jumpBackUI.rotation = 180;
jumpBackUI.x = (32+30); jumpBackUI.y = (672+30);
video_UI.addChild(jumpBackUI);
jumpBackUI.addEventListener(MouseEvent.CLICK, seekBack);
jumpForwardUI = new mcFastForward;
jumpForwardUI.x = (248+30); jumpForwardUI.y = (672+30);
video_UI.addChild(jumpForwardUI);
jumpForwardUI.addEventListener(MouseEvent.CLICK, seekForward);
var f: TextFormat = new TextFormat();
headerTextField.x = 32; headerTextField.y = 60;
f.size = 48;
f.font = theFont.fontName;
f.color = 0xffffff;
headerTextField.embedFonts = true;
headerTextField.setTextFormat(f);
video_UI.addChild(headerTextField);
video_UI.alpha = 0;
videoRect.width = stage.stageWidth;
videoRect.height = stage.stageHeight;
//videoRect.scaleX = videoRect.scaleY;
initVideo();
bringUpVideoUI();
}
Before Rotate
After Rotate
Edit 3:
public function initVideo(): void {
var obj: MovieClip = new MovieClip();
var nc: NetConnection = new NetConnection();
nc.connect(null);
netstream = new NetStream(nc);
netstream.client = obj;
obj.onMetaData = onMetaData;
stageVideo = stage.stageVideos[0];
stageVideo.addEventListener(StageVideoEvent.RENDER_STATE, onRender);
stageVideo.attachNetStream(netstream);
netstream.play(path);
netstream.seek(0);
netstream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
netstream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
netstream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
netstream.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
netstream.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
if (netstream != null) {
netstream.removeEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
netstream.removeEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
netstream.removeEventListener(IOErrorEvent.IO_ERROR, doIOError);
}
}
//Video Functions
public function shrinkVideo() { }
public function enlargeVideo() { }
protected function doSecurityError(evt: SecurityErrorEvent): void { trace("AbstractStream.securityError:" + evt.text); }
protected function doIOError(evt: IOErrorEvent): void { trace("AbstractScreem.ioError:" + evt.text); }
protected function doAsyncError(evt: AsyncErrorEvent) { trace("AsyncError:" + evt.text); }
protected function doNetStatus(evt: NetStatusEvent): void { }
private function onMetaData(e: Object): void { duration = e.duration; }
private function onRender(e: StageVideoEvent): void {
if(videoDemo == true){
addEventListener(Event.ENTER_FRAME, onEnterFrame);
cl.addEventListener(MouseEvent.CLICK, _handleClick); //add the clickforward to the the rectangle.
}
stageVideo.viewPort = videoRect;
}
private function netStatusHandler(e: NetStatusEvent): void { //get the end of a video
if (e.info.code == "NetStream.Play.Stop") {
if (demo == true) {
netstream.play(path); //loop the video if its in a demo
} else if (videoDemo == true) {
returnFromDemo();
}else{
exitVid();
}
}
}
When developing a multiscreen game or app, developers need to read device's screen size to correctly rescale and reorganise screen elements.
These sizing issues can be very frustrating, especially as behavior is not the same across OSes and devices.
My personal preference is to always have my apps run in
fullscreenMode = true / aspectRatio = portrait / autoOrients = false, only.
If there is a need to redraw/resize stuff based on a change in orientation, then a handler should be able to 'fake' it, rather than actually modifying the stage.

MouseEvent Not Happening On Click AS3

This looks all fine to me, but I have a simple star shape on the screen and when that star shape has been clicked it should remove the image from the screen. Can't see why its not working hoping one of you can, would be much appreciated
public class TouchRemove extends Sprite
{
private var _color:uint;
private var _radius:int;
private var star:Sprite;
public function mouseClick(event:MouseEvent): void {
star.visible = false;
}
public function TouchRemove(c:uint = 0xffff00, r:int = 100)
{
_color = c;
_radius = r;
star = new Sprite();
createStar();
addChild(star);
star.x = 250;
star.addEventListener(MouseEvent.CLICK, mouseClick);
}
private function createStar():void
{
star.graphics.lineStyle(9,_color);
star.graphics.moveTo(_radius, 0);
var angleIncrement = Math.PI / 5;
var ninety:Number = Math.PI * 3;
for (var i:int = 0; i <= 10; i++)
{
var radius:Number = (i % 2 > 0 ? _radius : _radius * .5);
var px:Number = Math.cos(ninety + angleIncrement * i) * radius;
var py:Number = Math.sin(ninety + angleIncrement * i) * radius;
if (i == 0) star.graphics.moveTo(px, py);
star.graphics.lineTo(px, py);
}
}
}
}
Your code looks correct.
Try this:
- Add listener to the parent
- Add star manually and add listener at it through the code
This will help locate the error.

Moving b2body With Keyboard

I have this code that gives the b2Body an impulse towards the cursor when you click on stage.
private function clicked(e:MouseEvent):void
{
var impulse_x:Number = (mouseX / world_scale - mainChar.GetPosition().x);
var impulse_y:Number = (mouseY / world_scale - mainChar.GetPosition().y);
var impulse:b2Vec2 = new b2Vec2(impulse_x, impulse_y);
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
}
I was trying to use keyboard right arrow key for movement and so in the update function I added the if key[Keyboard.RIGHT]:
private function update(e:Event):void {
world.Step (1 / 30, 10, 10);
if (key[Keyboard.RIGHT]) {
impulse_x = 3;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
}
}
private function onKeyUp(e:KeyboardEvent):void
{
key[e.keyCode] = false;
}
private function onKeyDown(e:KeyboardEvent):void
{
key[e.keyCode] = true;
}
But the b2body goes to top left on the screen and stays there and doesn't move. I am changing the impulse value that then goes into the vector that is applied to the body.
Although it doesn't give me any errors.
EDIT: The whole code!
package
{
import Box2D.Collision.Shapes.b2PolygonShape;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Dynamics.b2FixtureDef;
import Box2D.Dynamics.b2World;
import Box2D.Dynamics.Contacts.b2ContactEdge;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
public class Main extends Sprite
{
public var world:b2World = new b2World(new b2Vec2(0, 0), true);
public var world_scale:Number = 30;
public var mainChar:b2Body;
private var ground:b2Body;
public var keys:Array = [];
public var beingPressed:Boolean;
public var impulse_x:Number;
public var impulse_y:Number;
public var impulse:b2Vec2 = new b2Vec2(impulse_x, impulse_y);
public function Main():void
{
createMainCharacter(stage.stageWidth / 2, stage.stageHeight / 2, 50, 100);
var th:uint = 10;
addEventListener(Event.ENTER_FRAME, update);
//stage.addEventListener(MouseEvent.CLICK, clicked);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
/**private function clicked(e:MouseEvent):void
{
var impulse_x:Number = (mouseX / world_scale - mainChar.GetPosition().x);
var impulse_y:Number = (mouseY / world_scale - mainChar.GetPosition().y);
var impulse:b2Vec2 = new b2Vec2(impulse_x, impulse_y);
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
}**/
private function update(e:Event):void
{
world.Step (1 / 30, 10, 10);
var temp:Sprite;
for (var body:b2Body = world.GetBodyList(); body != null; body = body.GetNext())
{
if (body.GetUserData())
{
temp = body.GetUserData() as Sprite;
temp.x = body.GetPosition().x * world_scale;
temp.y = body.GetPosition().y * world_scale;
temp.rotation = body.GetAngle() * (180 / Math.PI); // radians to degrees
}
}
if (keys[Keyboard.RIGHT])
{
impulse_x = 3;
impulse_y = 0;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
} else {
impulse_x = 0;
impulse_y = 0;
}
}
private function createMainCharacter(x:Number, y:Number, width:Number, height:Number):void
{
var mainCharSprite:Sprite = new Sprite();
mainCharSprite.graphics.beginFill(0x000000);
mainCharSprite.graphics.drawRect( -width / 2, -height / 2 , width, height);
mainCharSprite.graphics.endFill;
mainCharSprite.x = x;
mainCharSprite.y = y;
addChild(mainCharSprite);
var mainCharDef:b2BodyDef = new b2BodyDef();
mainCharDef.userData = mainCharSprite;
mainCharDef.type = b2Body.b2_dynamicBody;
mainCharDef.position.Set (x / world_scale, y / world_scale);
mainChar = world.CreateBody(mainCharDef);
var shape:b2PolygonShape = new b2PolygonShape();
shape.SetAsBox((width / 2) / world_scale, (height / 2) / world_scale);
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.shape = shape;
fixtureDef.restitution = 0.1;
fixtureDef.friction = 0.1;
fixtureDef.density = 0.5;
mainChar.CreateFixture(fixtureDef);
}
private function onKeyUp(e:KeyboardEvent):void
{
keys[e.keyCode] = false;
}
private function onKeyDown(e:KeyboardEvent):void
{
keys[e.keyCode] = true;
}
}
}
Changing the values of impulse_x and impulse_y is not going to update the values used by the b2Vec2 impulse. In AS3 primitives are passed by value not by reference. If you want the b2Vec2 object referenced by the variable impulse to change its values you need to change them directly on the object itself:
impulse.x = 3.0;
impulse.y = 0.0;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());

Code for a 10x10 multiplication table in flash as3,

I'm new to coding in AS3, and I would like some assistance. I've recieved a task where I have to code a Multiplication table (10 rows, 10 columns). I've managed to code the table, but I need help to add the numbers needed without manually adding the text.
It should look somewhat like this;
Can someone here assist me with this task?
Here is my code:
var xColumns:uint=10;
var xRows:uint=10;
var _columnWidth:Number=40;
var _rowHeight:Number=40
var _width:Number=_columnWidth*xColumns;
var _height:Number=_rowHeight*xRows;
graphics.lineStyle(2, 0x0000ff, 1);
for(var i:int=1; i<=xColumns; i++){
graphics.moveTo(i*_columnWidth,0);
graphics.lineTo(i*_columnWidth,_height);
}
for(i=1; i<=xRows; i++){
graphics.moveTo(0,i*_rowHeight);
graphics.lineTo(_width,i*_rowHeight);
}
This is the sample of "Cell" class:
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class Cell extends Sprite
{
//---------------------------------------
protected var m_oLabel:TextField;
protected var m_nWidth:Number = 20;
protected var m_nHeight:Number = 20;
protected var _backgroundColor:Number;
//---------------------------------------
//Group: CONSTRUCTOR
public function Cell()
{
super();
m_oLabel = new TextField();
m_oLabel.text = "999";
m_oLabel.autoSize = TextFieldAutoSize.CENTER;
addChild(m_oLabel);
setLabel("999");
}
//--------------------------------------------------//
// PUBLIC PUBLIC PUBLIC PUBLIC //
//--------------------------------------------------//
public function setLabel(p_sLabel:String):void
{
m_oLabel.text = p_sLabel || "";
updateLayout();
}
public function get backgroundColor():Number
{
return _backgroundColor;
}
public function set backgroundColor(value:Number):void
{
_backgroundColor = value;
redraw();
}
//------------------- OVERRIDDEN -------------------//
override public function get width():Number
{
return m_nWidth;
}
override public function set width(value:Number):void
{
m_nWidth = value;
updateLayout();
redraw();
}
override public function get height():Number
{
return m_nHeight;
}
override public function set height(value:Number):void
{
m_nHeight = value;
updateLayout();
redraw();
}
//--------------------------------------------------//
// PRIVATE/PROTECTED PRIVATE/PROTECTED //
//--------------------------------------------------//
protected function updateLayout():void
{
//adjust layout
if (m_oLabel)
{
m_oLabel.x = width * .5 - m_oLabel.width * .5;
m_oLabel.y = height * .5 - m_oLabel.height * .5;
}
}
protected function redraw():void
{
var g:Graphics = this.graphics;
g.beginFill(_backgroundColor);
g.drawRect(0, 0, width, height);
g.endFill();
}
//------------------- OVERRIDDEN -------------------//
//--------------------------------------------------//
// EVENTS EVENTS EVENTS EVENTS //
//--------------------------------------------------//
//------------------- OVERRIDDEN -------------------//
//--------------------------------------------------//
// UTILS UTILS UTILS UTILS //
//--------------------------------------------------//
//------------------- OVERRIDDEN -------------------//
}
}
and usage:
var container:Sprite = new Sprite();
addChild(container);
container.x = 10;
container.y = 10;
for (var i:int = 0; i <= 10; i++)
{
for (var j:int = 0; j <= 10; j++)
{
var cell:Cell = new Cell();
if (i == 0 || j == 0)
{
//headers
cell.setLabel(Math.max(i, j).toString());
cell.backgroundColor = 0x808080;
}
else
{
var mul:Number = i * j;
cell.setLabel(mul.toString());
cell.backgroundColor = 0xC0C0C0;
}
container.addChild(cell);
cell.x = cell.width * j;
cell.y = cell.height * i;
}
}
which looks like this:
new class "Cell" gives you flexibility and encapsulation of code for creation of single table cell. In my example it is only container for textfield and has ability to draw background. I've created public methods/accessors that allow to modify the "features" of the cell (i.e. what is displayed in TextField and what is colour of background). I had to override default width/height behaviour as otherwise it would return the size of it's content which would vary depending on the TextField content and size and in table we need steady size.

how to make Astar pathfinding can used by multi enemy?

i have learn A star pathfinding from "AdvancED_ActionScript_Animation" e-book:
List item
i make node class, Node.as .
i make grid class, Grid.as .
i make AStar class, AStar.as .
and the main clas, Game.as .
A-star Pathfinding is work, but just 1 player.
how to make it work in multi player?
spoiler
4.Game.as :
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
public class Game extends Sprite
{
private var _cellSize:int = 30;
private var _grid:Grid;
private var _player:Sprite;
private var _index:int;
private var _path:Array;
public function Game()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
makePlayer();
makeGrid();
stage.addEventListener(MouseEvent.CLICK, onGridClick);
}
private function makePlayer():void
{
_player =new Sprite();
_player.graphics.beginFill(0x336633);
_player.graphics.drawCircle(0,0,5);
_player.graphics.endFill();
_player.x = Math.random() * 100;
_player.y = Math.random() * 100;
addChild(_player);
}
private function makeGrid():void
{
_grid = new Grid(10,10);
for (var i:int =0; i < 10; i++)
{
_grid.setWalkable(Math.floor(Math.random()*10),
Math.floor(Math.random()*10),false);
}
drawGrid();
}
private function drawGrid():void
{
graphics.clear();
for (var i:int =0; i < _grid.numCols; i++)
{
for (var j:int =0; j<_grid.numRows; j++)
{
var node:Node = _grid.getNode(i,j);
graphics.lineStyle(0);
graphics.beginFill(getColor(node));
graphics.drawRect(i *_cellSize,
j*_cellSize,_cellSize,
_cellSize);
}
}
}
private function getColor(node:Node):uint
{
if (! node.walkable)
{
return 0;
}
if (node == _grid.startNode)
{
return 0xcccccc;
}
if (node == _grid.endNode)
{
return 0xcccccc;
}
return 0xffffff;
}
private function onGridClick(event:MouseEvent):void
{
var xpos:int =Math.floor(mouseX/_cellSize);
var ypos:int =Math.floor(mouseY/_cellSize);
_grid.setEndNode(xpos,ypos);
xpos = Math.floor(_player.x / _cellSize);
ypos = Math.floor(_player.y / _cellSize);
_grid.setStartNode(xpos,ypos);
drawGrid();
findPath();
}
private function findPath():void
{
var astar:AStar = new AStar();
if (astar.findPath(_grid))
{
_path = astar.path;
_index = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
private function onEnterFrame(event:Event):void
{
var targetX:Number = _path[_index].x * _cellSize
+ _cellSize / 2;
var targetY:Number = _path[_index].y * _cellSize
+ _cellSize / 2;
var dx:Number = targetX - _player.x;
var dy:Number = targetY - _player.y;
var dx2:Number = targetX - _box.x;
var dy2:Number = targetY - _box.y;
var dist2:Number =Math.sqrt(dx2*dx2+dy2+dy2);
var dist:Number =Math.sqrt(dx*dx+dy+dy);
if (dist<1)
{
_index++;
if (_index >= _path.length)
{
removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
else
{
_player.x += dx * .5;
_player.y += dy * .5;
}
}
}
}
I am not going to go the extra mile and code this for you. (Anyone else can feel free to do that)
What you need to do is create a function that accepts a start node and end node, and returns the path. Something like this :
public function getPath(starNode:Point, endNode:Point):Array
{
// get your path by utilizing the astar instance
// return that path array
// note that I have used Points to store the x,y location
// you'll need to apply those values to the grid before your astar call
// using the setStarNode and setEndNode methods of the grid instance
}
Then you can modify the code that is used in your enterFrame, to utilize an array containing path data for any player/enemy you want.
For example you might have a function you call for each entity such as :
public function followPath(entity:MovieClip, pathData:Array, pathIndex:int):void
{
// your modified code from onEnterFrame
// replace _player variable with entity
// replace _path variable with pathData
// replace _index with pathIndex
}
If you understand OOP well enough, you might want to create a class for your player/enemy entities that has properties for pathData and pathIndex. If you do that, than you can just call an update method that will update their movement each frame using the pathData and pathIndex properties of that instance.
This is a basic approach you could use to accomplish your goal.