View Full Version : migration trouble from as2 to as3
Actarus
10-09-2008, 04:00 PM
Hi guys !
I'm having big problems trying to migrate this code from AS2 to AS3. :confused:
i have understood the way to change the createEmptyMovieClip but i still don't know how to translate the mc[clip_name].
private function makeclip(mc: MovieClip, clip_name : String, bm_width : Number, bm_height : Number)
{
mc.createEmptyMovieClip(clip_name, mc.getNextHighestDepth());
('field_container_mc', mc[clip_name].getNextHighestDepth());
mc[clip_name].field_container_mc.createTextField('field_mc', mc[clip_name].field_container_mc.getNextHighestDepth(), 0, 0, bm_width, bm_height);
mc[clip_name].field_container_mc.field_mc.autoSize = 'left';
mc[clip_name].field_container_mc.field_mc.embedFonts = true;
mc[clip_name]._x = - Math.round(bm_width / 2);
mc[clip_name]._y = - Math.round(bm_height / 2);
}
:eek:
thanks to anybody who can help :rolleyes:
- Actarus -
xxneon
10-09-2008, 04:23 PM
accessing instances in actionscript is different then as2 in alot of ways.. like for instance.. createEmptyMovieClip() is simply 'new MovieClip()' now.. but you still need to add it to the display list..
so like in your code if you use the function the same way.. then you would have the first couple lines look like this..
private function makeclip(mc: MovieClip, clip_name : String, bm_width : Number, bm_height : Number)
{
var clip:MovieClip = new MovieClip();
clip.name = clip_name;
mc.addChild(clip);
//...
but inside that function whenever you need to target the mew movieclip you would reference clip directly .. when dynamically creating instance there is no more 'mc[clip_name]'.. unless you accually make a property that is attached to the mc..
mc[clip_name] = new MovieClip();
mc[clip_name].name = clip_name;
mc.addChild(mc[clip_name]);
Actarus
10-09-2008, 05:04 PM
Thanks xxneon ! ;)
So, i have tried to update the following AS2 script :
private function __createClips(mc: MovieClip, clip_name : String, bm_width : Number, bm_height : Number)
{
mc.createEmptyMovieClip(clip_name, mc.getNextHighestDepth());
mc[clip_name].createEmptyMovieClip('field_container_mc', mc[clip_name].getNextHighestDepth());
mc[clip_name].field_container_mc.createTextField('field_mc', mc[clip_name].field_container_mc.getNextHighestDepth(), 0, 0, bm_width, bm_height);
mc[clip_name].field_container_mc.field_mc.autoSize = 'left';
mc[clip_name].field_container_mc.field_mc.embedFonts = true;
mc[clip_name]._x = - Math.round(bm_width / 2);
mc[clip_name]._y = - Math.round(bm_height / 2);
}
by this AS3 script :
private function __createClips(mc: MovieClip, clip_name : String, bm_width : Number, bm_height : Number)
{
var clip:MovieClip = new MovieClip();
clip.name = clip_name;
mc.addChild(clip);
mc[clip_name] = new MovieClip();
mc[clip_name].name = 'field_container_mc';
mc.addChild(mc[clip_name]);
var m_Label:TextField = new TextField();
m_Label.name = 'field_mc';
m_Label.x = 0;
m_Label.y = 0;
m_Label.width = bm_width;
m_Label.height = bm_height;
m_Label.autoSize = 'LEFT';
m_Label.embedFonts = true;
mc[clip_name].addChild(m_Label);
mc[clip_name]._x = - Math.round(bm_width / 2);
mc[clip_name]._y = - Math.round(bm_height / 2);
}
As createTextField don't exists either in AS3, i tried to follow this old example here (http://www.actionscript.org/forums/showthread.php3?t=157989).
do you see something strange in this convert ? :rolleyes:
Actarus
10-09-2008, 05:08 PM
except an update :
i have replaced
mc[clip_name]._x = - Math.round(bm_width / 2);
mc[clip_name]._y = - Math.round(bm_height / 2);
by
mc[clip_name].x = - Math.round(bm_width / 2);
mc[clip_name].y = - Math.round(bm_height / 2);
xxneon
10-09-2008, 05:10 PM
i should have been more clear i guess with my code.. it was more of 1st example .. or 2nd example .. not to use both..
but this might be more what you need.
var clip:MovieClip = new MovieClip();
clip.name = clip_name;
mc.addChild(clip);
var field_container = new MovieClip();
field_container.name = 'field_container_mc';
clip.addChild(field_container);
var m_Label:TextField = new TextField();
m_Label.name = 'field_mc';
m_Label.x = 0;
m_Label.y = 0;
m_Label.width = bm_width;
m_Label.height = bm_height;
m_Label.autoSize = 'LEFT';
m_Label.embedFonts = true;
field_container.addChild(m_Label);
clip.x = - Math.round(bm_width / 2);
clip.y = - Math.round(bm_height / 2);
Actarus
10-09-2008, 05:26 PM
Thanks again xxneon ! I thought that mc[] act an array. But, if i understood correctly, it's like a node and many nodes (child) can refer to mc. :)
ok, then, i will try to continue with some other script that i have to migrate too. Hope i will solve them alone as i understood this child structure :cool:
Actarus
10-09-2008, 10:30 PM
still lost in depth :eek:
so, i was doing my script migration, then i got stuck in this one :o
AS2
step_clip.createEmptyMovieClip(step_name, 60 + steptrack);
I want to try
var step:MovieClip = new MovieClip();
step.name = step_name;
step_clip.addChild(step);
but i don't know how to set the depth (see 60+steptrack) :confused: any clue ?
Actarus
10-10-2008, 01:50 PM
does anyone have an idea ? :eek: please
Actarus
10-10-2008, 02:18 PM
I have seen an example here (http://www.actionscript.org/forums/showthread.php3?t=180513&highlight=depth). Can anyone could confirm that this following code is ok ?
From AS2
step_clip.createEmptyMovieClip(step_name, 60 + steptrack);
To AS3
var clip:MovieClip = new MovieClip();
clip.name = step_name;
step_clip.addChildAt(clip, 60 + steptrack);
Is it ok ? Sorry, i'm asking because i can't try/run the script for the moment.
xxneon
10-15-2008, 04:03 PM
you can not set the depth in as3 in the same fashion as as2.. when you use addChild() it will automatically assign it a depth.. unless you set the depth with addChildAt().. but your limited to what you can set it to.. 0 to DisplayObjectContainer.numChildren (which would give you the number of children already on its display list.. so you don't need the 60+steptrack..
addChild() will be sufficient..
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.