A Flash Developer Resource Site

Results 1 to 20 of 58

Thread: ARGH!...help on multiple arguments for asfunction...

Hybrid View

  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    94

    ARGH!...help on multiple arguments for asfunction...

    what I want to do is create an array that will allow me to call an SWF, give it x and y coordinates of a blank movie and load into a level...I understand that this will need four arguments...very unsure how to proceed...

    can someone give me a quick shot at how I can get started?

    Thanks!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You can have only one argument in an asfunction. Check asfunction in the flash help files. there is an example how to use it.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Jun 2004
    Posts
    94

    Ah...no

    Per Macromedia (whoops!...Adobe )...

    Passing multiple function parameters
    As mentioned above, the function called by asfunction is only passed a single string argument. One way to mimic passing multiple arguments is to separate the "arguments" using a predetermined string delimiter. Below, three comma-delimited arguments are passed to myFunction.

    asfunction:myFunction,argument_1,argument_2,argume nt_3


    In the new version of myFunction, the split method is used to break the comma-delimited string into an array of arguments, argumentArray.

    function myFunction(param){
    argumentArray = new Array;
    argumentArray = param.split(",");
    for (i=0; i< argumentArray.length; ++i){
    trace("Function argument " + i + " = " + argumentArray[i]);
    }
    }


    Testing the movie should result in the following being reported to the Output window:

    Function argument 0 = argument_1
    Function argument 1 = argument_2
    Function argument 2 = argument_3

    I'm just not sure how to set up the statement for the asfunction...

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Yeah you are right I did not think of that possibility. Here is the complete script, but I recommend you not to load into level. you will see why.

    PHP Code:
    import mx.utils.Delegate;
    var 
    myLoadvars:LoadVars = new LoadVars ();
    myLoadvars.onLoad = function ()
    {
        
    myText.htmlText this.test;
    };
    myLoadvars.load ("asfunction.txt");
    //
    function myTest (arg1:String)
    {
        var 
    argumentArray:Array = new Array ();
        
    argumentArray arg1.split (",");
        var 
    myLevel:String argumentArray[3];
        
    loadMovieNum (argumentArray[0], myLevel);
        
    //
        
    var myLoadedVar:Object argumentArray[0];
        var 
    myListener:Object = new Object ();
        
    myListener.traceVar setInterval (Delegate.create (thislistener), 1000);
        function 
    listener ()
        {
            if (
    myLoadedVar != undefined)
            {
                
    this["_level" myLevel]._x argumentArray[1];
                
    this["_level" myLevel]._y argumentArray[2];
                
    clearInterval (myListener.traceVar);
                
    this["_level" myLevel]._visible true;
            }
        }
        
    AsBroadcaster.initialize (myLoadedVar);
        
    myLoadedVar.addListener (myListener);
        
    myLoadedVar.broadcastMessage ("traceVar");

    And this is the text file.
    PHP Code:
    test=<a href="asfunction:myTest,testmovie.swf,100,200,1"><font size='24'>Test</font></a
    Here is the modified script for a movieclip loading.
    PHP Code:
    var myLoadvars:LoadVars = new LoadVars ();
    myLoadvars.onLoad = function ()
    {
        
    myText.htmlText this.test;
    };
    myLoadvars.load ("asfunction.txt");
    //
    function myTest (arg1:String)
    {
        var 
    argumentArray:Array = new Array ();
        
    argumentArray arg1.split (",");
        var 
    myLevel:Number argumentArray[3];
        
    _root.createEmptyMovieClip ("a"myLevel);
        
    a._lockroot true;
        
    a.loadMovie (argumentArray[0]);
        
    a._x argumentArray[1];
        
    a._y argumentArray[2];

    Last edited by cancerinform; 06-10-2006 at 12:44 PM.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Member
    Join Date
    Jun 2004
    Posts
    94

    Whow!

    It works! ..but I don't need the listener/broadcaster code, since it will be calling the SWF to the same main movie...and i wanted to point to an emptymovie, but this might work better...though I'm missing the point about loading into levels...?

    BTW, thanks!!!

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    what I want to do is create an array that will allow me to call an SWF, give it x and y coordinates of a blank movie and load into a level.
    level
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Member
    Join Date
    Jun 2004
    Posts
    94

    Oh my, it's him again...:D

    Is there a way, using the above code, to load a xxx.txt file, and have the asfunction load a graphic, without clicking on something?...barring this, can I call the asfunction from the frame and have it load the graphic?

    Thanks!

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Then you don't need the asfunction any more. just put the loadMovie function within the onLoad event function.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Member
    Join Date
    Jun 2004
    Posts
    94

    Well...

    Here's what I ended up doing...I couldn't get anything else to work...in the frame that I need the graphic to load, I place the code without the use of the array variables...


    _root.createEmptyMovieClip ("a", 1);
    a._x = 90;
    a._y = 187;
    var mc:MovieClip=_root.a.createEmptyMovieClip ("mc", 1);
    mc._lockroot = true;
    mc._alpha = 0;
    mc.loadMovie ("igaf.jpg");
    //
    _root.onEnterFrame = function ()
    {
    var speed:Number = 8;
    if (mc._alpha < 100)
    {
    mc._alpha += speed;
    }
    else
    {
    delete this.onEnterFrame;
    }
    };

    Anything more elegant would be appreciated...

  10. #10
    Member
    Join Date
    Jun 2004
    Posts
    94

    Another asfunction question...

    how would I go about placing a link on the text page that would use asfunction to point me to a page? as in gotoandplay?

  11. #11
    Member
    Join Date
    Jun 2004
    Posts
    94

    Gave up on dynamic text and moving to imported SWFs...

    Now, here's my question...using the asfunction code provided, how can I modify this for use in an SWF that replaces the dynamic text?...

    As always, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center