AS3 addChild() to what????

I'm trying to figure out this new DisplayObject list and
stuff. I wanted to make some random boxes and put them on the stage
– which works great. Then I decided I would like to drag them
around – again no problem. Then I decided I would like the
one I clicked on to come to the front – big problem.
I'm really wondering when I do something like
addChild(sprite) or what ever, what am I adding to it to? I thought
it was stage, but that isn't it. Evidently after a loooonnggg time
of trying to understand the help files, I figured out that it was
the
[object MainTimeline]
Whatever that was. And that I could use "this" in my click
handler because they happened to be the same scope. But I imagine
at some point they won't be the same. So how do I reference [object
MainTimeline].
I guess it is the same issue as AS2 with root and that I
could use:
var home=this;
And then later use:
home.setChildIndex(event.target,home.numChildren-1);
Mostly I think typing this up has helped me work out a lot of
this. But if anybody has any pointers, please share.

kglad – thanks for that suggestion and I will
experiment around with it. The strange thing is that if I type home
as Object the exact line of code (with the event.target not cast as
anything) works just fine.
Strangely enough, when I do this:
setChildIndex(event.target,this.numChildren-1);
I get the Object coercion error, but if I have home typed as
an object and do this:
home.setChildIndex(event.target,this.numChildren-1);
It works.
And again the way you have written it, with just
setChildIndex and nothing in front of that confuses me and brings
me back to my initial question setChildIndex() of what? How does it
magically know what scope it should be on. And if I don't need
anything to scope the setChildIndex, evidently I don't need
anything to scope the numChildren either so this line works:
setChildIndex(DisplayObject(event.target),numChildren-1);
And thanks for that describeType() except it traces a couple
of pages! And that is what seems to be wrong with AS3, nothing is
simple! But…wait a minute…that did lead me to
getQualifiedClassName() which is what I was looking for!

Similar Messages

  • AS3: addChild()

    I'm just getting into AS3 and it is making me crazy. All over
    the place (help files etc.) I see code like this.
    addChild(myLoader);
    Where myLoader is an instance of the Loader class. But it
    could be a Sprite or something else. But to what are we adding the
    child? It seems that Loader inherits like this (has anybody else
    noticed that copying from the help files never seems to work on the
    first try?):
    Loader DisplayObjectContainer InteractiveObject DisplayObject
    EventDispatcher Object
    And it seems that addChild() is inherited from the
    DisplayObjectContainer class. So is the addChild adding the loader
    to itself?

    When you create a DisplayObject using the new operator, it
    has no parent.
    The addChild method allows you to change the objects
    parentage -- a real
    improvement for Flash.
    Try this snippet in the timeline:
    import flash.display.*;
    import flash.events.MouseEvent;
    var s1:Sprite = new Sprite();
    var s2:Sprite = new Sprite();
    s1.x = 10;
    s1.y = 10;
    s2.x = 200;
    s2.y = 10;
    this.addChild(s1);
    this.addChild(s2);
    var rect:Shape = new Shape();
    rect.graphics.beginFill(0xff0000);
    rect.graphics.drawRect(0,0,100,100);
    rect.graphics.endFill();
    rect.x = 20;
    rect.y = 20;
    s2.addChild(rect);
    s2.addEventListener(MouseEvent.CLICK, clickHandler);
    s1.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:MouseEvent){
    if(event.target == s1){s2.addChild(rect);}
    else{s1.addChild(rect);}
    trace(rect.parent.name)

  • AS3: addChild from an AS file

    Hello,
    I have a fla file with a MovieClip named Billy (class: Billy,
    Base Class: flash.display.MovieClip) linked to Billy.as.
    I am trying to get .as file to add an instance of the
    MovieClip Billy onto the stage with no luck. If anybody can help me
    here, Thank You! I am not getting any error messages, just a blank
    swf file...
    this is the code in Billy.as. The fla file is blank.
    package
    import flash.display.MovieClip;
    import Billy;
    public class Billy extends MovieClip
    private var _billy:Billy;
    public function Billy()
    _billy = new Billy();
    addChild(_billy);

    No, it's not tracing.
    package
    import flash.display.MovieClip;
    public dynamic class Billy extends MovieClip
    public function Billy()
    // trace sth just to see it works
    trace("Billy()");
    Also, I learned from a tutorial to name the class.as file as
    the same as the name of the movie clip in the fla file. This was
    from Lynda.com and hasn't caused problems before. I just don't know
    why the class file is not seeing the MovieClip in the fla
    file.

  • What is wrong with as3

    this is not a question about 'how i do X'. is rather a 'discussion' (flame or whatever, but to defend or argue about aspects, not people) about 'what is wrong with as3' and what aspects whould be taken into consideration for updates. right now i am using as3, and since i paid for this license, i choose this tool over some alternatives and i am using it to do stuff for other people who pay me to do it, i think it can be helpful for all of us if some actions are started in the right direction. i have already posted about 'all people in adobe are dumbasses that do not know how to make a scripting tool and are messing up my work', but i was pissed at the time (i still am pissed) but i believe this is not the right aproach. instead, if this goes to the right people in adobe, we all may get something in the future, like better and easier todo apps and web presentations.
    pre: not only about the as3 specification, but COMPLY with the specification that you set. for example, some time ago there were problems with matrix transforms. this was corrected later with a patch. but this means it is not even doing what is is supposed to do
    1. scriptable masks and movement, sprites and child sprites: there is a sprite with a mask, the mask is a shape drawn via script, something like
    somemask=new shape();
    somemask.graphics.beginfill();
    (...etc)
    somesprite.mask=somemask;
    just like that. now add some child sprites to 'somesprite', and make 'somesprite' move, scale and rotate. there you will have something like a kaleidoscope, but not what you expected to do with your script. as the child sprites move in the parent mask, you will see that the child sprites appear or dissapear kind of randomly, and if the child sprites are textfields, it may be that the text is rendered outside the mask, or partially rendered outside the mask (as in only part of the text), rendered with the wrongf rotation or in the wrong place. some child sprites are clipped correctly, some dissapear totally when only a part should dissapear (clipped) etc.
    way around: have not tried it yet, but i have the impression that bitmaps have different criteria for clipping, so i am thinking of trying this: appli an empty filter (a filter with params so it does not have any effect on the sprite or in the textfield) so the sprite is rendered as bitmap before doing anything else with it. as i said, i have not done it yet, but it may be a way around this problem, to avoid all this inconsistency with clipping
    1-b. inconsistency between hierarchy and coordinates, specially masks: you apply a mask to a sprite, yet the sprite has a set of coordinates (so 'x' in the sprite means an x relative to its container), yet the mask applied to the very same sprite, as another reference as reference for coordinates (like the stage)
    2. painting via script: in any other languaje, in any other situation, something like:
    beginFill(params);
    (...stuff 1)
    endFill();
    beginFill(params);
    (...stuff 2)
    endFill();
    (...etc)
    means: render region of block 1, then render region of block 2 etc, and no matter what, it should be consistent, since there is noplace for ambiguity. if you read it, you may think what that means, even if you dont run it you may have an idea of the picture you want to draw, but not with as3. as3 somehow manages to screw something that simple, and mixes all the blocks, and somehow uses the boundaries of one block as boundaries for other block. is like all blocks are dumped into whatever, and then uses all lines defined into it as boundaries for a unique block. it changes all boundaries and generates inconsistency between what is shown and redraw regions of the resulting picture, like lines that go to the end of the screen and then dont go away in the next frames, even tough the beginfill endfill block should prevent it
    3. event flow: i dont know what was the policy behind as3 event flow design. it is in no way similar or an extension to previous event flow, neither with any event flow in any other plattform. i dont know how most people start with as3; in my case, i unpacked, installed and when i tried to do something with what i already knew i could not, so i started reading the as3 docs, and since is like 800 pages long, i just read the basics and the rest i would 'wing it'. in the part of the event flow, there was something about bubbling and stuff, it was not clear at all and when i tried to do what is was said in the documentation (like preventing events to 'bubble', as is called in the documentation), i could not see any effect but i could see it was a mess. flash is not the only thing out there to work with pictures or to work with mouse events, but is the only one that deals with things like 'target' and 'currentTarget'. my first experience on needing this was when i was dealing with my own event handlers (so the only thing that had control over mouse was the stage, and i would admin everything via script). there were events generated everywhere, the stage got events that were not genrated directly over the stage, but got there not with stage coordinates but the coordinates relative to the sprite that generated the event. so if i hover the mopuse over the stage, and the stage has some things on it how does it work? i get multiple event calls, like it was hovering multiple times over the stage in a single frame, but in each call with different coordinates? and what if i set all child sprites as mouseenabled=false or compare like 'if (event.target != event.currenttarget)', what if i move the mouse over a child, does it prevent the move mouse event at all? or does it filter only the event call with only stage coordinates? in my case, every time i move over another clip (with mouseenabled = true), the stage gets it as 'mouse up', even tough there was never a mouse release, what the hell? do even the people at adobe know how to handle events with their own tool when they require it? why does an event 'bubble' when i have not specifically tell it to do it? mi thought is that this event flow was very poorly conceived, and tough the intention may have been that there were different cases and it shopuld cover all cases, they actually introduced new problems that were not present in traditional ways to handle it, and it is neither the easier way to handle things, and this way, a very simple problem turns into a very ugly thing because it must handle things that were not neccesary to handle, or were implicit in other situations.
    4. legacy: since as3, all interaction is different, and if you want to do things in the new plattform, using the new features, what you already knew just goes to the garbage can. when a new tool arrives, it should be an extension to previous tools (which is a reason to update instead of just buying a new tool from a different vendor). if everything i had or knew just means nothing from now on, then i can not say 'i know flash script', and my previous knowledge gives me no advantage when aproaching the new version. as3 is a new aproach that requires doc reading and stuff, even if you knew something about previous as specifications or other oo languajes. if you decide to change things from now on, like the things mentioned in this post, instead of just throwing away everything the users alerady knew about the tool, do like in java releases, they mark some things as 'deprecated', they keep working as they should, give a warning, but also a message saying this feature is deprecated, we suggest you use this library instead.
    5. lack of previous functionality: if you 'update' something, it meand all previos functionality is still there (probably improved, but not with bugs if it was working fine), plus something else. now it seems backwards, there are some things that could be done in previous versions but not in this one, like 'duplicatemovieclip'
    6. inconsistency with scripting/programming paradigms: (ok, fancy work, but fits perfectly here): as3 proposed ways to handle things, but the people who designed it got 'too creative', and they did something that is not consistent neither with previous versions of as or with other languajes. the documentations is full of things like 'it looks like x languaje or languaje family, but instead of using XXX word, you must use YYY'. great, what is this? namespaces 'work like', but 'differently' for example from java, .net, .c. its got the idea that a namespace means a grouped functionality but there are rules about where should be placed the file (ok, java has this also, .net takes care of it automatically if all files are registered in the project), but what you got is a mess that 'if you know other languajes you got the general idea, but nonetheless, even if you knew this or previosu versions of as, you still have to read whatever we decided arbitrarily just to be different'. namespaces, event handling, vars definition which is not like previous scripting neither like fully typed languajes.. is just a mess.
    7. lack of scripting and graphics integration: unlike flash and adobe tools that just got on the graphics side leaving all the scripting integratuion apart, most tools from other vendors integrate very well interacton with what is on the screen. the script editor: very poor. autocompletion? a drop down list that does not heklp at all, appears in the wrong places, and when you need it to go, it does not go (so if i want to move away from the uncalled drop down list, i have to click somewhere else, making developement slowewr instead of helping, so the drop down list does not capture all events when i dont want to). in other ides you double click somewhere and it will go to the part of code relevant to that event or whatever. for example microsoft tools, ok i am antimicrosoft, and one of the reasons was that when windows 95 got to market proposing itself as the ONLY pc os you could use if you wanted to keep useing the apps you already had, it was a lousy product full of flaws but you had to keep using it because you had no choice. what is so different from what is happening with flash just now? yet the ide of c# is awesome, works very well and seems reliable.
    adobe people: not all user are designers that just make pretty pictures. if it is not intended for scripting then why is it there. and if there are corrections to be done, they should patch all versions, not only the last one. previous version users also paid for their versions.

    Well, there is no point in arguing.
    I personally believe AS3 does exactly what it promises to do within limits (read: reasonable limits) of ECMA type of language. And sometimes it doesn’t do what we expect it to for it cannot possibly emulate everyone’s thinking process. The task, I guess, is to learn to think in terms of AS3 – not to try to make AS3 think like us. No language covers all the grounds. And no, it is not Java - with no negative or positive connotation. It is what it is. Period. I just hope that AS5 will be more Java like.
    You are right about the fact that it is not necessary to know all the aspects of language in order to perform the majority of tasks. But it is paramount to have a clear idea about such fundamental concepts as display list model and events. For instance, depth swap has no meaning in terms of AS3 because display list object stacking is controlled automatically and there is no need for all these jumping through hoops one has to perform in order to control depth in AS2. There no more gaps in depths and one always know where to find things.
    Similarly, there is no point in having duplicateMovieClip method. More conventional OOP ways of object instantiation accomplishes just that and much more. Just because OOP object instantiation needs to be learned doesn’t mean past hacks have place in modern times. duplicateMovieClip is a horse carriage standing next to SUV. What one should choose to travel?
    Events are implemented to the tee in the context of ECMA specifications. I consider Events model as very solid, it works great (exactly as expected) and never failed me. True, it takes time to get used to it. But what doesn’t?
    By the way, speaking about events, contrary to believe in Adobe’s inconsideration to their following. Events are implemented with weakly reference set to false although it would be better to have it set to true. I think this is because there are smart and considerate people out there who knew how difficult it would be for programming novices to deal with lost listeners.
    I think AS3 is million times better than AS2. And one of the reasons it came out this way is that Adobe made a very brave and wise decision to break totally loose from AS2’s inherent crap. They have created a totally new and very solid language. If they had tried to make it backward compatible – it would be a huge screw up, similar to how our friends at Microsoft are prostituting VB and VBA – extremely irritating approach IMHO.
    Also, Flash legacy issues shouldn’t be overlooked. Flash did not start as a platform for programmers. Entire timeline concept in many ways is not compatible with the best OOP practices and advancements. I think for anyone who is used to writing classes the very fact of coding on timeline sounds awkward. It feels like a hack (and AS2 IS a pile of hacks) – the same things can be nicely packaged into classes and scale indefinitely. As such I wouldn’t expect Adobe to waste time on hacking timeline concept issues by making smarter editor. They have made a new one – FlexBuilder – instead. Serious programmers realize very soon that Flash IDE is not for developing industrial strength applications anyway. So, why bother with channeling great minds into polishing path to the dead end?
    I would like to state that all this is coming form a person who knew Flash when there was no AS at all. And I applaud every new generation of this wonderful tool.
    I believe Adobe does a great job making transition from timeline paradigm to total OOP venue as smooth as possible. And no, they don’t leave their devoted followers behind contrary to many claims. They are working on making developing Flash applications as easy as possible for people of all walks. Welcome Catalyst!
    Of course there is not enough information about AS3 capabilities and features. But, on the other hand, I don’t know any area of human kind activities that does.

  • Some AS3 code needs to be AS2

    As I have been told, the following code is mixing as2 and as3.
    picHolder[1].onPress = function() {
              picHolder[1].width = card.width;
              picHolder[1].height = card.height;
              picHolder[1].x = 0;
              picHolder[1].y = 0;
              card.addChild(picHolder[1]);
    I presume the AS3 code is whats inside the function (My addition), as the function code was there when following the as2 tutorial.  Basically, when the user clicks the image in array element 1, this image should be set as the background of the movieclip card.  How would I change the inside so that is was AS2 code?
    cheers

    Well, what I have done is
    picHolder[1].onPress = function() {
              picHolder[1]._width = card._width;
              picHolder[1]._height = card._height;
              picHolder[1]._x = 0;
              picHolder[1]._y = 0;
              card.addChild(picHolder[1]);
    Now it does slightly what I want, but it doesnt get placed into the movieclip how it should.  Not sure if I am doing everything how i should be doing it.

  • Reference external library movieclip in library with AS3

    Hello, i am able to load at runtime a library asset in flash
    cs3. i do this by setting up its linkage property and setting its
    base class. for eg
    Class: MyButton
    Base: flash.display.MovieClip
    then in my document class, say i had
    com.kofi.InitializeTemplate, my class looks like this
    package com.kofi
    import flash.display.MovieClip;
    import MyButton;
    public class InitializeTemplate extends MovieClip
    var testButton:MyButton;
    public function InitializeTemplate():void
    trace("the button class has been called");
    testButton = new MyButton();
    addChild(testButton);
    however, once i bring in an external library asset(which i
    have already exported and set it base class etc), i am unable to
    call this shared library asset with as3. anyone know what i am
    talking about?

    Hi Sigiswald,
    well it seems SAP also considers that a bug, if you go to the Service marketplace -> Support Packages and Patches -> SAP NetWeaver -> SAP NETWEAVER -> SAP NETWEAVER 2004S -> Entry by Component -> Development Infrastructure, there is a SAP_BUILDT SP09 Patch 1 referring to note 993799 which says:
    "Jar files, especially from development components with type "External Library" are not assembled into the WDA archive for Web Dynpro development components."
    Are you using the original SP09 version or this patch?
    Regards,
    Marc

  • Putting movie clips in AS3 package into movie clip on stage

    Hi - I am a as2/flash animator and am working on an AS3
    project. The AS is in a separate file, inside a package. I am
    modifying existing code.
    The script adds movie clips in a function via addchild.
    What I am hoping to do, is have the movieclips added to a
    clip that already exists on the stage.
    I put a clip on the stage named holder, with the instance
    name holder_mc - and I tried to add the clip with
    holder_mc.addchild in the AS3 file - it seemed to work, but
    manipulating the holder_mc - it looks like the added clips are not
    affected?
    Any help is appreciated.

    Child_array is a property of the Parent class.
    It's only added to in one point, in a function that creates a
    Child and adds it to the array.
    I think I might have found out the problem with my code after
    adding a trace to the function, think I'm creating twice the number
    of clips I'm removing, and the deletion part of my code is fine!
    Turns out AS3 is maybe not so bad after all :P
    Thanks alot for taking the time to reply though kglad!

  • AS2 to AS3 Streaming Video Player

    Ok so Im trying to convert a video play that i made in AS2 to
    AS3 (I had a problem with nested movie clips and the control bar
    and i want to learn AS3) and i am having troblem even connecting to
    my rtmp server. With the player i made in AS2 i was able to connect
    and stream video no problem. But with AS3 I am not even able to
    connect to the rtmp server. Here is the AS2 code and the AS3 code:
    AS3:
    var video:Video = new Video(853,480);
    addChild(video);
    var nc:NetConnection = new NetConnection();
    nc.connect("rtmp://[ip of server]/sumone4life/videos");
    var ns:NetStream = new NetStream(nc);
    ns.addEventListener(NetStatusEvent.NET_STATUS,
    onStatusEvent);
    function onStatusEvent(stat:Object):void
    trace(stat.info.code);
    var meta:Object = new Object();
    meta.onMetaData = function(meta:Object)
    trace(meta.duration);
    video.attachNetStream(ns);
    ns.play("AdobeBand_640");
    And I get the error:
    ArgumentError: Error #2126: NetConnection object must be
    connected.
    at flash.net::NetStream/construct()
    at flash.net::NetStream()
    at videoPlayer_fla::MainTimeline/frame1()
    Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095:
    flash.net.NetConnection was unable to invoke callback onBWDone.
    error=ReferenceError: Error #1069: Property onBWDone not found on
    flash.net.NetConnection and there is no default value.
    at videoPlayer_fla::MainTimeline/frame1()
    Flash media server 3 Administrative Panel also shows that I
    am infact connected to the server but there is nothing being
    streamed from the server.
    AS2 Works:
    //Video Loading Controls
    var fileName:String = "AdobeBand_640";
    var nc:NetConnection = new NetConnection();
    var ns:NetStream;
    nc.onStatus = function(info){
    trace(info.code);
    if(info.code == "NetConnection.Connect.Success"){
    playVideo();
    function playVideo(){
    ns = new NetStream(nc);
    ns.onMetaData = onMetaDataHandler;
    videoObject.attachVideo(ns);
    _root.createEmptyMovieClip("vSound",
    _root.getNextHighestDepth());
    vSound.attachAudio(ns);
    ns.setBufferTime(5);
    ns.onStatus = function(info){
    trace(info.code);
    if(info.code == "NetStream.Buffer.Full"){
    bufferClip._visible = false;
    if(info.code == "NetStream.Buffer.Empty"){
    bufferClip._visible = true;
    if(info.code == "NetStream.Play.Stop"){
    ns.seek(0);
    ns.play(filename);
    //connects the stream
    nc.connect("rtmp://[ip of server]/sumone4life/videos");
    Can anyone offer any insite as to why it would be workin in
    AS2 and not in AS3? Or what i am doing wrong...

    I have a similar problem. Did you get your to work?

  • Get URL from embedded Flash AS3 movie

    I have a thumbnail scroller app built with AS3 on my website
    homepage. I have the class files but would like to know of any
    quick workaround to make the embedded Flash movie clickable without
    reworking the AS3 files. What I would like to do is if you click on
    a thmbnail or anywhere in the movie, the "portfolio" page loads. I
    asume this would use javascript? Any help is greatly appreciated.
    Thank you.

    I notice that when I click on the thumbnails in the browser,
    a "0" appears on top of each thumb. When i test in Flash preview
    clicking on an image generates:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL
    Not Found.

  • Convert text in pdf with as3

    Hallo,
    1) what is the best way to convert text to pdf from as3?
    2) what is the best way to import pdf in fash?
    Thanks.

    you'll need to use a 3rd party library like alivePDF, AlivePDF - ActionScript 3 Open-Source PDF Library – 100% client side PDF generation which makes you and your server happ… and/or purePDF, purePDF, a complete actionscript PDF library - sephiroth.it - flash world

  • FlashVars into AS3 Project.....!!?

    I am working in AS3, I know what needs to be done in AS2. I am needing to pass the FlashVars value to my swf. the FlashVars variable statement for this example is hard coded, but is actually dynamic data being passed from CF. So, to simplify this, I hard coded the FlashVars variable.
    So, I am having trouble passing the FlashVars variable in the following code to the AS3 coding below. Instead of "data/cgal.xml", I need it to pass the variable and dynamically read "http://www.stuartsandlin.com/adirectory/anxmlfile.xml".
    I'm sure can't be that much different from AS2.
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%" id="main" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="true" />
    <param name="movie" value="main.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" />
    <param name="FlashVars" value="http://www.stuartsandlin.com/adirectory/anxmlfile.xml" />
    <embed src="main.swf" quality="high" bgcolor="#000000" width="100%" height="100%" name="main" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </object>
    var loaderXML:URLLoader = new URLLoader();
    LoaderXML.load(NewURLRequest("data/cgal.xml"));

    actually you need to fix your html:
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#ve rsion=9,0,0,0" width="100%" height="100%" id="main" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="true" />
    <param  name="movie" value="main.swf" /><param name="quality"  value="high" /><param name="bgcolor" value="#000000" />
    <param name="FlashVars" value="xmlVar=http://www.stuartsandlin.com/adirectory/anxmlfile.xml" />
    <embed src="main.swf" FlashVars="xmlVar=http://www.stuartsandlin.com/adirectory/anxmlfile.xml"  quality="high" bgcolor="#000000" width="100%" height="100%" name="main"  align="middle" allowScriptAccess="sameDomain" allowFullScreen="true"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </object>
    and that actionscript:
    var loaderXML:URLLoader = new URLLoader();
    LoaderXML.load(NewURLRequest(LoaderInfo(loaderInfo).parameters["xmlVar"]));
    and if you're using a tlf textfield that's loaded you may need an additional step.

  • Creating AS3 code for C++ classes converted with Alchemy (a là Box2D)

    So I've a collection of C++ classes which I now have converting fine with Alchemy to a swc file and can call the exposed functions fine from my AS3 code.
    What I'd really like to do is recreate stuff like Box2D's b2Vec.as class,
    public class b2Vec2 extends b2Base {
        public function b2Vec2(p:int) {
            _ptr = p;
        public function get v2():V2 {
            return new V2(x, y);
        public function set v2(v:V2):void {
            x = v.x;
            y = v.y;
        public function get x():Number { return mem._mrf(_ptr + 0); }
        public function set x(v:Number):void { mem._mwf(_ptr + 0, v); }
        public function get y():Number { return mem._mrf(_ptr + 4); }
        public function set y(v:Number):void { mem._mwf(_ptr + 4, v); }
    This is a simple example, but shows what I'd like to do.  On the C side of things, b2Vec2 is a struct,
    /// A 2D column vector.
    struct b2Vec2
        /// Default constructor does nothing (for performance).
        b2Vec2() {}
        float32 x, y;
    So, for this struct, it's easy to calculate that the first variable of a b2Vec2 object is a float, which will be the value in x and can be read via Alchemy's MemUser classes _mrf (read a fload from a point in memory) with _mrf(pointerAddress) and you can read in the second float with _mrf(pointerAddress + 4).
    My question is, if you're not a C++ expert (me), is there any way to get the definition of a class, as in the addresses of all the variables within and what they are?  So, for the b2Vec2 one, I'd imaging it'd be something like, float32 x 0 float34 y 4 ...
    The reason I'm asking is because one of the classes in particular has loads of variables and to try and get each and every one's information so I can access it directly from the AS3 code would be lots of work and I'm going to assume I'll introduce plenty of human error to it.

    Hi,
    I am facing the similar issue. Can you please tell me how you solved this problem in more details?
    which sample code and how u can find that in SE24 and where to copy that code.
    Thanks in advance..
    vamsi.

  • AS3... why?

    what is the point of AS3?. Why is there AS3?.. what doors of possiblities does it open?
    I wouldn't mind if AS3 was an extention to AS2 but it seems to be completely different, not similar to other languages, and takes ten times as long to code something simple as it did with AS2..
    before people respond with well just use AS2 I would, however every flash job is for people that can AS2 and AS3...
    am i going to spend ages learning AS3 to find that adobe have already launched AS4, which im sure will have no relation to AS3?
    ... sorry for a rant and possibly a pointless post, but thats life.

    Hi, Jonny.
    First, considering the advantages of AS3 over AS2, one of the most important is that more and more developers are migrating to it, it means that inevitable the AS2 community will slown down...
    But, let's go to the languages advantages. First: the new VM of Flash Plugin, the one that runs AS3 is kind of 100 times faster! Run this simple test and confirm what I'm saying:
    [AS2]
    var initTime:Number = getTimer();
    var endTime:Number;
    for(var i:Number=0; i < 1000000; i++)
    endTime = getTimer();
    trace(endTime - initTime);
    [/AS2]
    [AS3]
    var initTime:uint = getTimer();
    var endTime:uint;
    for(var i:intr=0; i < 1000000; i++)
    endTime = getTimer();
    trace(endTime - initTime);
    [/AS3]
    AS3 is really a very superior language. About the time to develop, I also has this impression: AS3 is much more exigent than AS2. But, go for my words, when you get it, you gonna see you will have a much faster and consistent development, without annoying bugs and this stuffs.
    I really think that everyone sould migrate to AS3. If you're not convinced yet, some other features:
         Native support to 3D;
         Access to Local File system;
         Native peer-to-peer support coming there (look for Stratus);
         indexOf method in the Array, that became much times faster;
         Control of the loaded data at the byte level (ByteArray);
         Typed vectors (making array much more faster);
         Consistent event structure;
         An incrideble RegExp solution;
         And so on...
    AS4 is not about to be launched. It'll take time to. The AS3 language is more compliant with the standards of development, and I believe that it can pass by a improvement on the plugin side, but the language will stay stand for many years. Years enough to worth learn the AS3 and be prepared to the 4. Anothe little advantage, it's very similar to Java, for those familiarized with Java.
    These are only some of the advantages of the AS3 engine... but, pal, go AS3!
    Cheers,
    CaioToOn!

  • Anyone: as2 vs as3?

    was looking at summerLongSince's post, basic as3, and it
    occurred to me that the as3 version of what had been previously
    done using as2 was more complicated and involved (see script
    below). i am still relatively new to actionscripting and am
    currently using/learning as2, so i am ignorant to the benefits as3
    has to offer at this point. could anyone tell me what benefits the
    as3 code below has over the as2 that precedes it? they both seem to
    accomplish the same goal, only as3 seems to take more time and code
    to do so. also, is moving to as3 worth the hassles that come with
    learning an entirely new scripting language? i haven't even
    mastered as2 and the thought of losing all the work i have put in
    thus far is somewhat sickening. lastly, couldn't as3's benefits
    have been implemented into flash without restructuring the entire
    programming language?
    thanks in advance,
    _name

    AS 3.0 comes with great features and 10 time faster than AS
    2.0. you may find some link on adobe.com site.
    for your current code. see this.

  • AddChild / removeChild variables declaration (when is best?)

    I am putting together my file right now which is now using visual elements purely added and removed via AS3 (addChild / removeChild) methods. My question is just about the proper time / place to declare their variables.
    Can I declare them all at the start of the movie (frame 1) and just call them when I need them, or is it better to declare them on the frames that they are introduced on? I guess the question is really, will I ever lose those variables throughout the movie once they are declared?
    thanks.

    you won't lose variable declarations.  the only thing that could cause a problem was if you referenced an object in a frame where the object doesn't exist.   but you can declare variables to have an object types and do not need to point the variables to objects (until later in your code).

Maybe you are looking for

  • Need help with explanation of FRAPS to Adobe Pre Elements

    Hello Everyone. So I'm having this issue and its really holding me back. I am a complete hobbyist when it comes to editing and I'm trying to solve my issue where my fraps footage looks like garbage once imported into Adobe Pre Elements 9. Now I wante

  • Mac Mini redirect LineIn to LineOut

    Guitar is connected to the MacMini and I want just to hear the sound which I play, without running GarageBand. I've checked, the power of signal is enough for this (I did this by going to System Preferences-Speech-Speech Recognition, button Calibrate

  • Purchase Requisition Date before SC Creation Date

    Hi We have a odd situation with a shopping Cart where Purchase Requisition Date (REL_DATE = March 11 2009) before SC Creation Date (March 31 2009). Any comments/suggestions? Nikhil

  • 6280 + Gcalsync on vodafone doesn't work for me :-...

    As per the subject, has anyone got Gcalsync working on this phone? All the tests work OK but if I try to sync then I get "invalid port - synchronization failed". Cheers..

  • Why applets are not having constructors?

    hi, could anyone please explain ,why do we need to use init() method instead of constructor to initialize the applets.why applets are not having constructors?. thanks in advance Santhosh