Migrate existing code of AS3 to AS2 - URLRequest, URLLoader

Hi,
I have written code to read an XML file by using URLRequest and URLLoader in ActionScript 3.0. Code is pasted below. This runs well in AS3.  Problem I am facing is because I wrote this in AS3, I am not able to use the DateChooser component in another part of the flash module because it seems like DateChooser component is not supported in AS3. So I want to migrate my below AS3 code back to AS2.
**** Code in AS3 (I need help in writing equivalent code in AS2) :-
var xmlText:XML ;
var xmlReq:URLRequest = new URLRequest("myFile.xml");
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(xmlReq);
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
function xmlLoaded(event:Event):void
    xmlText = new XML(xmlLoader.data);  
    info_txt.htmlText = xmlText.someTag ;
**** I cannot use the above as is because, when I change the publish settings from AS3 to AS2, I get following errors -
The class or interface 'URLRequest' could not be loaded.
The class or interface 'URLLoader' could not be loaded.
The class or interface 'Event' could not be loaded.
Same works well in AS3. What should I do to make this work in AS2 or can anyone direct me in writing an equivalent in AS2.
Please assist.
Thanks in advance.
MG

parsing is done using the xmlnode methods and properties.  how you parse an xml file (in as2) depends on its structure.  but generally, you use firstChild, nextSibling, childNodes and nodeValue in the appropriate sequence to extact data.  the flash help files have sample code.  for tutorials, check google.
if you're trying to load a cross-domain xml file, you'll have a cross-domain security issue to deal with.

Similar Messages

  • Change some code from as3 to as2

    Hi, I want to use as2 because it compatible with my website.
    I want to change some code from as3 to as2
    /////////////////////////////image1//////////////////////////////// if(MovieClip(this.parent).imagetxt.text == "a") {     var imgurl:String = "C:/Users/Thái/Desktop/ls/cotton-1.jpg";     var myrequest:URL = new URL(imgurl);     myloader.scaleContent = true;     myloader.load(myrequest); } /////////////////////////////image2//////////////////////////////// else if(MovieClip(this.parent).imagetxt.text == "b") {     var imgurl2:String = "http://aloflash.com/images/upload/3.jpg";     var myrequest2:URLRequest = new URLRequest(imgurl2);     myloader.scaleContent = true;     myloader.load(myrequest2); }thank you for your support.

    use:
    var myloader:MovieClip=this.createEmptyMovieClip("loader_mc",this.getNextHighestDepth());
    if (MovieClip(this._parent).imagetxt.text == "a") {
        var imgurl:String = "C:/Users/Thái/Desktop/ls/cotton-1.jpg";
        myloader.load(imgurl);
    } else if (MovieClip(this._parent).imagetxt.text == "b") {
        var imgurl2:String = "http://aloflash.com/images/upload/3.jpg
        myloader.load(imgurl2);

  • How do you convert this code from AS3 to AS2?

    Hi,
    I created some AS3 code that is working perfectly for us.
    However now we need to convert it to AS2 so that it can be Flash
    Player 8 compatible. If it could also be compatible for Flash
    Player 7 that would be ideal but not a requirement.
    Thanks in advance.

    Are you wanting someone to do the conversion for you, or are
    you asking for general tips for doing the conversion yourself?
    i can give you tips:
    have a look at the
    ActionScript
    2.0 Migration page.
    In this you'll find the property conversions eg(going from
    AS3 to AS2). y becomes _y, height becomes _height, scaleX becomes
    _xscale, void becomes Void etc.
    you'll find that events need to be converted, eg.
    particle.addEventListener(Event.ENTER_FRAME,
    animateParticle);
    becomes:
    particle.onEnterFrame=animateParticle;
    the onEnterFrame class doesn't pass an Event parameter to the
    event listener. Instead, the event listener is automatically in the
    scope of the event dispatcher, so instead of 'event.target' you
    will be able to just target 'this'.
    You'll need to use setInterval() instead of the Timer class.
    You'll need to use attachMovie() instead of
    addChild().

  • AS2 to AS3 migration of code...

    ==============
    This code is in AS2
    ==============
    _root.createEmptyMovieClip("tmp",900);
    _root.createEmptyMovieClip("tmpLoded",101);
    _root.interval = setInterval(_root.logger,5000);
    loadVariables("http://www.site.com/trackL.php?eid="+_root.id+"&rdoc="+_root.rdoc+"&str="+_root.generateRandomStr(),_root.tmpLoded);  
    function logger () {
    loadVariables("http://www.site.com/track.php?eid="+_root.id+"&str="+_root.generateRandomStr(),_root.tmp);
    function generateRandomStr () {
    var dt = new Date();
    var str = dt.getMilliseconds()+""+dt.getSeconds()+""+dt.getMinutes()+""+dt.getHours()+""+dt.getDate ()+""+dt.getMonth()+""+dt.getFullYear();
    return str;
    trackL.php - tracking if it loads correctly
    while
    track.php - will be generated periodically every 5 seconds.
    How would I pass a variable from flash to php?
    I've been in many tutorials in the net but I cannot understand much of the tutorials...
    I only saw same method like using URLRequest & URLLoader with the location of the php files then the variables in the php which connects to the database is accessible.
    All are accessing the php not passing flash variables to the php file like in the above code.
    All help is greatly appreciated.

    that's really poor as2 coding so it will translate to really poor as3 coding.
    but, to answer your question, you assign a data property to your urlrequest to convey data from flash to php.  the data property will be a urlvariables instance and you assign variables/values to your urlvariables instance:
    var urlVar:URLVariables=new URLVariables();
    urlVar.eid=whatevervalue;
    urlVar.rdoc=whatever;
    urlVar.str=whateverelse;
    yourURLRequest.data=urlVar;

  • Migrating AS2 Code to AS3

    ORIGINAL AS1 SCRIPT
    I have already tried several ways to migrate this code, but I
    get unexpected behaviors. Can any one help me?
    The volume control on the stage is made out of two
    movieClips: one called knob and the other volume_track over which
    the knob slides (is dragged by user) This two Clips are turned into
    one movieClip called volume_control. The Sound Object is within an
    Empty MovieClip called soundMc. the pos variable gathers the knob's
    position on the volume_track.
    The following code is the original one, which works
    perfectly.

    Hi, Kglad,
    I had made a mistake, that's why the code didn't work at all.
    My bad.
    I modified a little the code you suggested as well as the
    Clips Instance Names.
    I used the Rectangle Class to get the
    startDrag(lockCenter:Boolean = false, bounds:Rectangle = null)
    method's bound argument. This is how the Rectangle is set up:
    Rectangle(x:Number, y:Number, width:Number, height:Number);
    It works now, but there's a couple of unexpected things
    happening.
    1. It really hard to make the knob move left and right
    because the cursor seems not to get a firm hold of it.
    2. Once it starts dragging, I have to move it very slowly
    otherwise I lose a hold on the knob.
    3 - In order to get the knob to drag within the bounderies of
    its track, I had to add extra numbers in the x (8 instead of 0),
    width (a -12), and height (0 instead of e.currentTarget.y), but
    this poses a problem later when I try to get a definite value to
    control the volume intensity between 0.0 (Minimum volume) and 1.0
    (Max Vol). Tracing pos, I got these results:
    Min pos: 0.10810810810810811
    Max pos: 0.9459459459459459
    Is there a way to clean up those results, like a Math
    function, so that I can get something like this 0.1 and 0.9 instead
    of those long numbers?
    volume_control.volKnob.addEventListener(MouseEvent.MOUSE_DOWN,
    dragKnob);
    volume_control.volKnob.addEventListener(MouseEvent.MOUSE_UP,
    stopKnob);
    volume_control.volKnob.addEventListener(MouseEvent.MOUSE_OUT,
    stopKnob);
    var t:Timer=new Timer(70,0);
    t.addEventListener(TimerEvent.TIMER,volF);
    function dragKnob(e:MouseEvent) {
    trace("Begin dragging");
    var rect:Rectangle = new Rectangle(8, e.currentTarget.y,
    e.currentTarget.parent.volTrack.width-12, 0);
    e.currentTarget.startDrag(false, rect);
    t.start();
    function stopKnob(e:MouseEvent) {
    trace("Stop draggin");
    e.currentTarget.stopDrag();
    t.stop();
    function volF(e:TimerEvent) {
    var pos:Number =
    (volume_control.volKnob.x/volume_control.volTrack.width);
    //soundObjChannel.soundTransform.volume =pos; // you need to
    define your soundChannel object whereever you're applying the play
    method to your sound object
    trace("pos" + pos);
    }

  • Dummy Guide needed for converting AS2 code into AS3

    I have to convert my existing AS2 code into AS3, but I might as well be reading chinese. I never even began to learn AS3, it was still fairly new at the time and the class ended before we had an opportunity to even touch on it. My major was not web design, it was the print side of design. I took an additional class, after I graduated, to learn web design and our teacher told us, basically, that we were designers, not coders so we won't be getting much into actionscripting, beyond the basics. At the time I was relieved, but looking back, I really wish we would have gotten more into it. Bottom line, I need to learn now.
    Is there ANYONE that can help me out? I will list my code below, buy I am way beyond lost any help that can be provided, I would be so grateful!!!!
    On the main timeline I have the basic..
    stop(); -- I found the AS3 version, but I don't know what I'm looking at. I get "not_yet_set.stop()" and there are are 8 options I can choose from. I just want the timeline to stop until I tell it where to go next. And what is "not_yet_set"
    Then I have my buttons, which are, basically...
    on (release) {
    gotoAndStop("Home");
    Or "gotoAndPlay("Whatever");"
    I also have buttons for scrolling...
    on (press) {
    play();
    on (release) {
    stop();
    AND
    on (press) {
    _root.AboutMe_Controller.gotoAndPlay(…
    on (release) {
    _root.AboutMe_Controller.gotoAndStop(…
    For the on(release) command, this is what I found as the AS3 version: not_set_yet.dispatchEvent()

    because that's really as1 code, you have steeper learning curve than going from as2 to as3.
    first, remove all code from objects, assign instance names to your buttons and you can then start on as3:
    // so, if you name your home button, home_btn:
    home_btn.addEventListener(MouseEvent.CLICK,homeF);
    function homeF(e:MouseEvent):void{
    gotoAndStop("Home");
    p.s.  the not_yet_set stuff is there because you tried to use script assist or some other actionscript shortcut.

  • Help! Convert simple Flash AS2 code to AS3

    Hi everyone,
    I'm a Flash beginner and followed a tutorial: http://www.webwasp.co.uk/tutorials/018/tutorial.php ... to learn how to make a "live paint/draw" effect. I didn't realize  that if I made something in AS2, I wouldn't be able to embed it (and  have it work) into my root AS3 file, where I've got a bunch of other  stuff going on. I've tried following tips on how to change AS2 code to  AS3, but it just doesn't work. I know it's simple code, and that some  genius out there can figure it out, but I'm at a loss. Please help!
    Here's the AS2 code:
    _root.createEmptyMovieClip("myLine", 0);
    _root.onMouseDown = function() {
       myLine.moveTo(_xmouse, _ymouse);
       ranWidth = Math.round((Math.random() * 10)+2);
       myLine.lineStyle(ranWidth, 0xff0000, 100);
       _root.onMouseMove = function() {
          myLine.lineTo(_xmouse, _ymouse);
    _root.onMouseUp = function() {
       _root.onMouseMove = noLine;
    Thanks in advance!
    Signed,
    Nicolle
    Flash Desperado

    Considering the code is on timeline:
    var myLine:Sprite = new Sprite();
    addChild(myLine);
    var g:Graphics = myLine.graphics;
    addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    function onMouseDown(e:MouseEvent):void {
         var ranWidth:Number = Math.round((Math.random() * 10) + 2);
         g.clear();
         g.lineStyle(ranWidth, 0xFF0000, 1);
         addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
         addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    function onMouseMove(e:MouseEvent):void {
         g.lineTo(mouseX, mouseY);
    function onMouseUp(e:MouseEvent):void {
         removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
         removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);

  • Change as2 code to as3

    I used a tutorial http://www.flash-game-design.com/flash-tutorials/funky-flash-website-tutorial-5.html to make a menu for my application, I've tried following tips on how to change AS2 code to AS3, but it just doesn't work.
    menu = ["bulls", "about", "roster", "schedule"];
    var current = menu[0];
    for (var i = 0; i<menu.length; i++) {
    var b = menu[i];
    this[b+"_btn"].stars._visible = false;
    this[b+"_btn"].txt = b;
    this[b+"_btn"].onPress = function() {
    _root.site[current+"_btn"].stars._visible = false;
    _root.site[this.txt+"_btn"].stars._visible = true;
    current = this.txt;
    _root.site.content.gotoAndStop(this.txt)
    this[current+"btn"].stars._visible = true;
    this.onEnterFrame = function() {
    this[current+"_btn"].stars.s1._rotation += 1;
    this[current+"_btn"].stars.s2._rotation += 0.5;
    Thank you,
    Glenn

    Just a note. Function declarations in a loop is an EXTREMELY bad practice that will lead to many problems if it doesn't have some already. So, the following lines:
    for (var i:int = 0; i<menu.length; i++) {
        var b:String = menu[i];
        this[b+"_btn"].stars.visible = false;
        this[b+"_btn"].addEventListener(MouseEvent.CLICK,fn);
        this[b+"_btn"].txt=b;
        function fn(e:MouseEvent):void{
            this[current].stars.visible = false;
            var nam:String=e.target.parent.name;
            this[nam].stars.visible = true;
            current = nam;
            //MovieClip(root).site.content.gotoAndStop(this.txt)
    should be:
    for (var i:int = 0; i < menu.length; i++) {
         var b:String = menu[i];
         this[b+"_btn"].stars.visible = false;
         this[b+"_btn"].addEventListener(MouseEvent.CLICK,fn);
         this[b+"_btn"].txt=b;
    function fn(e:MouseEvent):void {
         this[current].stars.visible = false;
         var nam:String=e.target.parent.name;
         this[nam].stars.visible = true;
         current = nam;
         //MovieClip(root).site.content.gotoAndStop(this.txt)

  • AS3 centering and resizing a background in existing code

    I have a code for a page I am using and I would like to add a background and have it resize with the screen like the rest of the page.  I have created a movie button named "pic" with the image in it but I don't know how to write the code and place it in the existing AS3 code file.  Could someone please help.  I am brand new to this so if someone could tell me how to place the code like i was in 3rd grade, that would be great. Here is the existing code.
    package com.modules
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import caurina.transitions.Tweener;
    import com.utils.*;
        public class About extends Sprite
    private var content_height:int;
    private var content_width:int;
    private var marginTop:int;
    private var marginBottom:int;
    private var content_y:int;
    private var _content:Content;
    private var news:News;
    private var array:Array;
    private var pan:Panning;
       public function About()
    // listen for when this is added to stage
    this.addEventListener(Event.ADDED_TO_STAGE, ini); 
    // listen for when this is removed from stage
    this.addEventListener(Event.REMOVED_FROM_STAGE, remove);
    private function ini(e:Event)
    stage.addEventListener(Event.ADDED, onStageResize);
    stage.addEventListener(Event.RESIZE, onStageResize);
    content_y = int(GlobalVarContainer.vars.CONTENT_Y);
    _content = new Content;
    addChild(_content);
    _content.visible=false;
    // load xml
    if((GlobalVarContainer.vars.XML_PATH!="") && (GlobalVarContainer.vars.XML_PATH!=undefined))
    var loadXml:LoadXml;
    loadXml = new LoadXml(GlobalVarContainer.vars.XML_PATH);
    loadXml.addEventListener(Event.COMPLETE, onXmlComplete);
    private function onXmlComplete(e:Event)
    // set up content
    content_width = e.target.returnData.attribute("width");
    marginTop = e.target.returnData.attribute("marginTop");
    marginBottom = e.target.returnData.attribute("marginBottom");
    var backgroundColor = e.target.returnData.attribute("backgroundColor");
    Tweener.addTween(_content.bg, {_color:backgroundColor, time:.1, transition:"linear"});
    _content.bg.width = content_width;
    _content.masc.area.width = (content_width -_content.masc.x)-20;
    _content.holder.txt.width = _content.masc.area.width -10;
    // write text
    _content.holder.txt.mouseWheelEnabled = false;
    _content.holder.txt.styleSheet = GlobalVarContainer.vars.CSS;
    _content.holder.txt.condenseWhite = true;
    _content.holder.txt.htmlText = e.target.returnData;
    _content.holder.txt.autoSize = TextFieldAutoSize.LEFT;
    onStageResize();
    _content.visible=true;
    // create new Panning instance;
    pan = new Panning(_content.holder, _content.masc, _content.bg, 4, true);
    pan.addEventListener(Event.ADDED, scInit);
    addChild(pan);
    // Initialize panning
    function scInit(e:Event):void
    pan.init();
    // resize contents
    private function onStageResize(e:Event = null):void
    resizeContent((stage.stageHeight - ((content_y + marginTop) + int(GlobalVarContainer.vars.BOTTOM_SHAPE_H)))-marginBottom);
    private function resizeContent(height_:int):void
    content_height = height_;
    _content.bg.height = content_height;
    _content.masc.area.height = (content_height -_content.masc.y)-20;
    _content.holder.mask = _content.masc;
    Tweener.addTween(_content, {x: Math.round(stage.stageWidth/2 - _content.width/2) , time:.5, transition:"linear"});
    _content.y=content_y+ marginTop;
    // used to change colors. here we not use
    public function changeTheme():void
    // remove listeners, images and unload panning;
    function remove(event: Event) : void
    pan.unload();
    stage.removeEventListener(Event.ADDED, onStageResize);
    stage.removeEventListener(Event.RESIZE, onStageResize);
    this.removeEventListener(Event.ADDED_TO_STAGE, ini); 
    this.removeEventListener(Event.REMOVED_FROM_STAGE, remove);
    trace("remove about");

    I just wanted to say that the above code works fine, I just need to add the resizing background code to it. Please help.  thanks

  • As2 code to As3 conversion please

    Hey, could someone help me converting the following code to AS3. Thanks for any help..
    id=_root.id;
    if(this._y<>_root.txk){
    this._y=_root.txk;
    _root.txk+=60;
    this._x=_root.txx;
    textyazı="";
    onEnterFrame=function(){
    this._name=namet.text;
    if(_root.txk==360){
    _root.txx+=60;
    _root.txk=60;
    this.onPress=function(){
    if(_root["t"+namet.text].txtn.text<>namet.text){
    _root.attachMovie("txt_dd","t"+namet.text,_root.derinlik);
    _root["t"+namet.text]._x=100;
    _root["t"+namet.text]._y=100;
    _root["t"+namet.text].txtyname.text=namet.text;
    _root["t"+namet.text].txtn.text=namet.text;
    _root["t"+namet.text].txtyazılar.text=textyazı;
    _root.derinlik++;
    txtac = SharedObject.getLocal(id);
    setInterval(function(){
    if(txtac.data.namet<>"" && txtac.data.id>0){
    namet.text=txtac.data.namet;
    textyazı=txtac.data.textyazı;
    id=txtac.data.id;
    }else{
    namet.text=_name;
    if(namet.text=="undefined"){
              namet.text=_name;
    if(textyazı==undefined){
              textyazı="";
    },50);
    this.useHandCursor=false;

    1.download flashdevelop (Flash has bad code hinting and error descriptions)
    2.start with deleting underscores in _root,_x,_y
    3.work your way up from there
    4.Lines like:
    this.onPress=function
    are probably attached directly to a button or MovieClip: This is not possible in as3 anymore. You have to take the code out of the button and put it on the timeline of the button, if it is a MovieClip.
    5.The Event Model has changed considerably:
    onEnterFrame=function(){
    // do stuff here
    is now
    addEventListener(ENTER_FRAME, enterFrameHandler);
    function enterFrameHandler(e:Event):void{
    //do stuff here

  • Converting AS3 to AS2

    Does anyone know how to translate this code into AS2? My client can't support AS3.
    var exitTimer:Timer = new Timer(15000, 1);
    exitTimer.addListener(TimerEvent.TIMER, jump);
    function jump(event:TimerEvent):void {
        gotoAndStop("Scene 1")
    exitTimer.start();
    Thank you!

    I put the wrong script in. This is the one I'm trying to convert from AS3 to AS2. Do I still use the setTimeout function or is the getTimer function more appropriate?
    var exitTimer:Timer = new Timer(15000, 1);
    exitTimer.addListener(TimerEvent.TIMER, jump);
    function jump(event:TimerEvent):void {
        navigateToURL(new URLRequest("http://www.url.com"));
    exitTimer.start();

  • Migrating existing portable homes to new server

    aside from moving the homedir data from the old server to the new, there seem to be at least a few issues with migrating existing portable home accounts to a new server:
    1. some of users' account details, like GeneratedUID, authentication authority, kerberos principals, OriginalNFSHomeDirectory, are different, while others (name, shortname, UID, GID, etc.) remain the same.
    2. home directory (OriginalNFSHomeDirectory, etc.) point to the old server.
    3. there's data on local machines that we don't sync back to the server, so we can't just blow away the existing local accounts and start fresh.
    the quickest way to migrate these users to the new server (with all the same shortnames and UIDs, etc.) seems to be to remove the local cached accounts (leaving the home folders) and have them recreate new PHDs on login, syncing things back down to the original home folder. i'm guess this won't involve much syncing, it's all the same data, essentially.
    the other way i can see resolving this is to replace the account attributes for each client to match what they should be when pointed to the new server. this would involve scripting the process for reliability and not moving any data or deleting accounts, but it will take more testing on my part.
    what do you think? can you think of better ways to accomplish this task?
    summary: what's the best way to move existing portable home accounts bound to "Server A" to "Server B," while maintaining data and portable homes pointed to the new server and storage?
    thanks.

    that createmobileaccount syntax was wrong. i guess you don't need the -t option and can instead specify the whole path to the user's home. it seems to work well enough, creating a portable home with no default sync settings -- basically manual. for my needs that's fine. the sync settings are managed via mcx anyway.
    here's an updated version of the standalone script. i realized just now the script assumes the diradmin usernames and passwords are the same between servers. if that's not the case, you can hard code it or add a couple of variables. since they're just taken in order on stdin, add them in order. i should also add a function to interactively ask for the passwords with stty -echo to avoid having the passes logged in command history or allowing the script to curl the pass from another file on a web server or something. for now, this seems to work for my purposes. edit as you see fit.
    #!/bin/bash
    # nate@tsp, 3/4/10: initial version
    # 3/5/10: added prettier heredoc usage statement, variables, further tested
    # todo: add function to add user to local admin group, as needed. this shouldn't be required in most environments.
    # todo: convert some of these one-liners to functions for better modular use; make it "smarter"
    # todo: convert the whole thing to ruby for practice
    # automates the process of unbinding from the old OD server, binding to the new, removing the existing local user, adding it back, and other bits
    # there are no "smarts" in this script, so use carefully
    # variables
    diradminpass=$1
    account=$2
    password=$3
    oldserver=$4
    newserver=$5
    mkdadmin=$6 # not used in this version
    # if no parameters are passed, display usage, exit
    if [ ! -n "$5" ] ; then
    cat<<endofnote
    usage: you must include at least 5 arguments (6th isn't used right now)
    run with `basename $0`
    1. [directory admin password]
    2. [shortname of account to change]
    3. [account password, which should be the default 'xxxxxxxx' on the new server]
    4. [name of old server]
    5. [name of new server]
    6. [yes or no to make this account a local admin - optional and not used now]
    ex: `basename $0` diradminpass jbrown password oldserver newserver yes
    endofnote
    exit 1
    fi
    # if you're running this as root or with sudo, proceed; otherwise, quit it!
    if [ $(whoami) = "root" ]; then
    echo "you're root. let's proceed..."
    # delete the user in question from the local directory store
    echo "deleting local account: $account"
    dscl . -delete /users/$account
    # remove the old od config
    echo "removing the old OD bind..."
    dsconfigldap -v -r $oldserver -c $HOSTNAME -u diradmin -p $diradminpass
    # remove the old server from the search and contacts paths
    echo "removing the old search paths..."
    dscl /Search -delete / CSPSearchPath /LDAPv3/$oldserver
    dscl /Search/Contacts -delete / CSPSearchPath /LDAPv3/$oldserver
    # add the new one
    echo "adding the new OD bind..."
    dsconfigldap -v -f -a $newserver -n $newserver -c $HOSTNAME -u diradmin -p $diradminpass
    # create and add the new ldap node to the search policy
    echo "adding the new search paths..."
    dscl -q localhost -create /Search SearchPolicy dsAttrTypeStandard:CSPSearchPath
    dscl -q localhost -merge /Search CSPSearchPath /LDAPv3/$newserver
    # create and add the new ldap node for contacts lookups
    dscl -q localhost -create /Contact SearchPolicy dsAttrTypeStandard:CSPSearchPath
    dscl -q localhost -merge /Contact CSPSearchPath /LDAPv3/$newserver
    # give directoryservice a kick to point it to the new server
    echo "killing directoryservice and waiting for 20 seconds..."
    killall DirectoryService
    # rest a bit to ensure everything settled down
    sleep 20
    # optional: lookup the $account you deleted as the first step to ensure it exists in the new directory
    echo "this id lookup should return details because it exists in the new OD:"
    id odtestor
    echo "this id lookup should fail because it doesn't exist in the old OD:"
    id odtestor
    # check the search path to ensure it looks like you need
    echo "verify the new OD server is in the search path:"
    dscl /Search -read / CSPSearchPath
    # optional: create a mobile account on the local machine with various options set.
    echo "creating a portable home for the user..."
    /System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -n $account -v -p $password -h /Users/$account -S -u afp://$newserver/homes/$account
    killall DirectoryService
    cat<<endofnote
    you should be ready to login with this account now.
    if you have trouble, revert the process by re-running with the old and new server names
    (and diradmin passwords, if they're different) reversed.
    endofnote
    else
    echo "you're not root or an admin. please re-run the script as an admin or via sudo."
    exit
    fi
    exit 0

  • Language experts: Port Java Code to AS3?

    Hello out there,
    I have been asked whether it would be feasable to translate Java code to AS3. This is a bit difficult since I am not really an expert in Java and only a beginner wrt AS3. Looking at some code samples it seems doable (at least in principle), but of course there might be hidden gotchas lurking. Hence:
    - Are there Java features which do not have an equivalent in AS3?
    - Does AS3 have prerequisites which do not exist in Java?
    - Other aspects to consider?
    Any comment or advice will be greatly appreciated.
    Best regards
    H.

    Thanks to you all.
    In the meantime I read "Actionscript for Java developers"
         http://www.javaworld.com/javaworld/jw-02-2009/jw-02-actionscript1.html
    and it seems like the two languages are not too far apart.
    Of course there are differences, but we only need to consider those features which Java has and AS has not (like method overloading) and modify our Java sources to not use these. Since the goal is not to have a universal tool which translates _any_ kind of Java source to AS but only our specific code base I think it will be worth a small effort to test how far we get with a machine translation.
    Yes, libraries may well be an issue - but again, I would have to see which (library) functions are actually used and how to replace them.
    Thanks again and best regards
    H.

  • Can AS1 code call AS3 code?

    I was wondering if there was any way for AS1 code to call AS3
    code.
    I need to write a server extension for SmartFox Pro. I just
    found out that the only version of action script that SmartFox
    sever extensions can be written in is AS1. However, I have a bunch
    of code already written in AS3 that I need to use. I have all of
    the source for the AS3 code.
    Is there a way for me to use my existing code, or am I out of
    luck?
    Thanks in advance
    John Lawrie

    you may be able to use swfbridge to do so, basically
    implementing the LocalConnection class
    http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html

  • How to add observable behaviour in existing code?

    Hi everyone, I'm new to design patterns. I have an existing numerical analysis package that I use to find roots using multiple strategy (bisection, secant, newton, etc). I want to show the process of root finding for every iterations taken by the algorithm (for example, iteration 0: left = 0, mid = 0.5, right = 1; iteration 2: left = 0, mid = 0.25, right = 0.5; ... etc. Its not exactly like that, I want to show it graphically, but you see what I mean). Looks like I need Observer to add event handling to notify the change of state in each initial guess as well as signaling the event when a root is/isn't found. But the solver classes doesn't seem to be implementing Observable, they just give out the answer, or not. How do I add Observer pattern without modifying the original code? I thought about using Decorator and having the real solver do the root finding but it just doesn't make sense to me. Thanx in advance.

    endasil wrote:
    georgemc wrote:
    endasil wrote:
    georgemc wrote:
    That won't get you intermediate results, though.If the method being observed needs to be firing multiple events per invocation, no, it won't.
    @OP, you were on the right track with the decorator pattern (indeed, that could be just as appropriate). What made you think it was wrong?I think that's the OP's tripping point:
    I want to show the process of root finding for every iterations taken by the algorithm
    ...But the solver classes doesn't seem to be implementing Observable, they just give out the answer, or not.
    Aha. Bytecode weaving (or plain old decompiling and nicking the source) then.Nope, I didn't. You're just too damned fast!For my own good! I hit "post" and immediately go "I forgot to say X" :-/
    @OP: if you want to see some examples of using bytecode weaving to introduce observableness to existing code, have a look at the sources for a test coverage tool like Cobertura. That's basically what they do. If you've never done it before, it'll take you a fair bit of head-scratching and sideways thinking to get your head round it all, but stick with it. Be prepared to learn a bit about opcodes as well. Or maybe just plundering the sources for this library is the way to go, not that I'm advocating that ;)

Maybe you are looking for