The Codesee The Codesee - 13 days ago 7
ActionScript Question

How can I send the user to a different URL using navigateToURL depending on clicked target?

I have an SWF file of a "virtual map" with different locations. When each location is clicked, the user is redirected to a hyperlink.

How would I make each location redirect to a different hyperlink?



You can download the SWF from here or view it online: http://www.fastswf.com/NInMHKU

Here is ActionScript code which makes possible for the user to be redirected when clicking on a location:

package
{
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.events.MouseEvent;

public class Map
{
public function Map()
{
}

public function gotoLocation(param1:int) : void
{
if(param1 != 999)
{
navigateToURL(new URLRequest("http://www.baidu.com"),"_blank");
}
}

private function closeMap(param1:MouseEvent = null) : void
{

}
}
}





After decompiling the SWF file with a program called JPEXS Free Flash Decompiler, I discovered that there's two different AS files for each location on the map. As an example, below are the files for the fountain.

Source of: Flumsfountain_499.as

package SkylandersSuperchargersMap_26_10_15_fla
{
import flash.display.MovieClip;

public dynamic class Flumsfountain_499 extends MovieClip
{


public function Flumsfountain_499()
{
super();
addFrameScript(0,this.frame1,1,this.frame2);
}

function frame1() : *
{
stop();
}

function frame2() : *
{
stop();
}
}
}


Source of: flumsfountainlPU_520.as

package SkylandersSuperchargersMap_26_10_15_fla
{
import flash.display.MovieClip;

public dynamic class flumsfountainlPU_520 extends MovieClip
{


public function flumsfountainlPU_520()
{
super();
addFrameScript(18,this.frame19);
}

function frame19() : *
{
stop();
}
}
}





Previously I tried...

I was able to use RABCDAsm to decompile the SWF into many different files and here is the code (source file:
Map.class.asasm
) which is produced by the AS3 project at the top of this question:

trait method QName(PackageNamespace(""), "gotoLocation")
method
name "gotoLocation"
refid "TestGotoLocationFunction/instance/gotoLocation"
param QName(PackageNamespace(""), "int")
returns QName(PackageNamespace(""), "void")
flag HAS_PARAM_NAMES
paramname "param1"
body
maxstack 4
localcount 2
initscopedepth 0
maxscopedepth 1
code
getlocal0
pushscope

getlocal1
pushshort 999
ifeq L13

getlex QName(PackageNamespace("flash.net"), "navigateToURL")
getglobalscope
findpropstrict QName(PackageNamespace("flash.net"), "URLRequest")
pushstring "http://www.baidu.com"
constructprop QName(PackageNamespace("flash.net"), "URLRequest"), 1
pushstring "_blank"
call 2
pop
L13:
returnvoid
end ; code
end ; body
end ; method
end ; trait

Answer

Edit file com.binweevils.externalUIs.map.Map.as:

  public function gotoLocation(param1:int) : void
  {
     if(param1 == 190)
     {
        navigateToURL(new URLRequest("http://www.different.com"),"_blank");
     }
     else if(param1 == 113)
     {
        navigateToURL(new URLRequest("http://www.something.com"),"_blank");
     }
     else
     {
        navigateToURL(new URLRequest("http://www.baidu.com"),"_blank");
     }
  }

You can find values for param1 from:

     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.halloween_btn,818));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.sinksSub_btn,116));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.tinksTree_btn,191));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.doshPalace_btn,102));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.gongsPipenest_btn,103));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.shoppingMall_btn,104));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.castleGam_btn,113));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.flem_manor_btn,125));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.partyBox_btn,10013));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.rumsCove_btn,129));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.flumsFountain_btn,190));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.riggsPalladium_btn,111));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.post_btn,120));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.figgsCafe_btn,156));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.grottoClub_btn,109));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.labsLab_btn,172));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.nestStreet_btn,115));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.nest_btn,5));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.binPetsParadiseRight_btn,100));
     this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.binPetsParadiseLeft_btn,101));

Each line:

this.mapLocs.push(new com.binweevils.externalUIs.map.MapLocation(this,this.flumsFountain_btn,190));

Provides the buttonMC and roomID which further can be used as param1 for the gotoLocation() to conditionally navigate the browser.

You can download the swf from https://drive.google.com/open?id=0B_AKfmXEaZvQUldqNkU3ZW9ZMTg

NOTE: You shouldn't decompile and use others property without permission unless it is for educational purpose.

Comments