The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.
The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.
4 | 4283 |
Hey there,
I was messing around with AS3 and I made it with some help to get my Character in my Game and let it walk. I have made a new AS File and called it Friend and made a new MC with a linkage: mc_Friend, and i have made this script, no errors too.. strange..
package
{
import flash.display.*;
import flash.events.*;
public class Friend extends MovieClip
{
var parentMC:MovieClip;
var friendMC:MovieClip;
public function Friend(mcParent:MovieClip)
{
parentMC = mcParent;
friendMC = null;
AddFriend(350, 250);
}
public function AddFriend(xPos:Number, yPos:Number)
{
friendMC = new mc_Friend();
parentMC.addChild(friendMC);
friendMC.x = xPos;
friendMC.y = yPos;
}
}
}
When I test my Movie my friend wont show up, and now my question is WHY? . Can someone explain me??
Thanks
In your AddFriend function try:
friendMC.x = xPos - parentMC.x;
friendMC.y = yPos - parentMC.y;
please someone correct me if I am wrong :3
so is this your document class? and if its not the movieclip must be added threw the document class. MovieClip extension is really the swf, its like the parent Movieclip of all other movieclips
No my document class is Main, i have made 3 other classes, character, KeyObject and Friend but I got trouble with getting Friend on stage.
Nevermind guys, was trying to fix this for a half hour and finaly figured out how the script need to be:
package
{
import flash.display.*;
import flash.events.*;
public class Friend extends MovieClip
{
var friendMC:MovieClip;
var parentMC:MovieClip
public function Friend(mcParent:MovieClip)
{
parentMC = mcParent;
friendMC = null;
AddFriend(350, 250, "John"
}
public function AddFriend(xPos:Number, yPos:Number, friendName:String)
{
friendMC = new mc_Friend();
parentMC.addChild(friendMC);
friendMC.x = xPos;
friendMC.y = yPos;
friendMC.name = friendName;
}
}
}
And maybe it was because I forgot to add this in the Main Class:
package
{
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip
{
var myCharacter:Character;
var myFriend:Friend;
public function Main()
{
myCharacter = new Character(this);
myFriend = new Friend(this);
}
}
}
Thanks for the answers and this can be locked.
You must be logged in to post a reply!