Select Page

FlashVars AS3 – getting values from the URL string

Getting values from the URL string in AS3 isn’t very complicated. First you need to set up your html to pass these into the SWF using a javascript function:


Place this inside your html.
Then if you are using the default HTML publishing you need to set up your SWF to take the variable. In this example I’m looking for a variable called ‘transition’



...




...

The important lines are:

‘FlashVars’, ‘transition=’+gup(“transition”),
and
param name=”FlashVars” value=”transition=”+gup(“transition”)

Here we are calling the javascript function to return the value that matches ‘transition’. Then this gets passed to the SWF.

Inside the flash this can be accessed with:

var sTrans:String = String(stage.loaderInfo.parameters.transition)

Then you can get variables from the URL string:

http://www.sitedaniel.com/index.html?transition=myvalue

Dragging in PaperVision 3D

There doesn’t seem to be much out there explaining how to drag something in 3d space. Recently I’ve had to create some planes that are draggable along one plane (i.e. the z depth doesn’t change but the x and y coordinates will). Doing this involves converting 2D coordinates into 3D coordinates. There is a built in function in Papervision that does this:

InteractiveUtils.getMapCoordAtPointDO3D(…)

So by passing the plane in to this, along with the mouseX and mouseY relative to the plane, we can get all the values needed for dragging.

Please note: I’m using pv3d\as3\tags\1_7\src as my base class, so this isn’t v2.0.

private function _startDrag(e:MouseEvent):void
{
    // get the plane from my dictionary where all my planes are
    // this is org.papervision3d.objects.Plane;
    _dragPlane = dict[e.target].pl;

    // start the enterframe function
    addEventListener(Event.ENTER_FRAME, _updateDrag);

    // get the intial mouseX and Y offset from
    // where the user has clicked on the plane
    var obj:Object =
            InteractiveUtils.getMapCoordAtPointDO3D(_thePlane,
            _thePlane.container.mouseX,
            _thePlane.container.mouseY);

        // save these coordinate offset values to use while dragging
        _drag_X_offset = obj.x;
        _drag_Y_offset = obj.y;
    }

private function _updateDrag(e:Event):void
{
    // get the updated position of the plane
    var obj:Object =
                InteractiveUtils.getMapCoordAtPointDO3D(_thePlane,
                _thePlane.container.mouseX,
                _thePlane.container.mouseY)

    // move the dragged plane to the new postion with the offset
    _thePlane.x = _thePlane.x + obj.x - _drag_X_offset;
    _thePlane.y = _thePlane.y - obj.y + _drag_Y_offset;
}