Skip to main content
arifniaz
Participant
May 31, 2017
Question

How to get the contentPath of Gallery Images

  • May 31, 2017
  • 4 replies
  • 478 views

hi

I am converting my project from adobe flash cs2.0 to cs3.0 and creating gallery that get images from my gallery images directory and its working fine , now I want to pass the image name to my external file which is a aspx file to store it in txt file to display the image in ecard later

In cs2.0 I was getting the path like this

ch1fn=this._parent.extimg.char1.contentPath;

ch1posx=this._parent.extimg.char1._x;

ch1posy=this._parent.extimg.char1._y;

please guide how to collect the contentPath in cs3.0

Thanks

This topic has been closed for replies.

4 replies

arifniaz
arifniazAuthor
Participant
June 2, 2017

Thanks for your reply


I tried to use the loaderinfo.url with my loaded bitmap image but here its giving the url of the script not the image url

in showChar() function I wrote

trace (theChar.loaderInfo.url); 

where as the theChar is loaded bitmap image

there it giving the url of the script like

file:///C|/Users/Desktop/eCards/cardnew.swf

Thanks

Colin Holgate
Inspiring
June 2, 2017

You're trying to get the path of the image to solve the problem of the images loading in the wrong order. Instead of doing that you could fix the problem of them loading in the wrong order, then you wouldn't need to worry about the path.

The way you have written the script you are telling all of the images to load at the same time, and as the next image loads you put it into the next empty button. But, images don't take the same amount of time to load, and it may even vary from session to session. If image 3 loads quicker than image 2, the buttons 2 and 3 will have their images switched.

The easiest solution is to load one at a time, and only load the next one when the current one finished loading. Here is some of your script changed to load one at a time:

var charCtr: int = 0;

loadCharacter();

function loadCharacter(): void {

  var charReq: URLRequest;

  var char_pic: Loader;

  chrequesturl[charCtr] = "charimages/char" + String(charCtr + 1) + ".png";

  // trace ("charimages/"+"char"+String(ct2+1)+".png");

  charReq = new URLRequest("charimages/" + "char" + String(charCtr + 1) + ".png");

  char_pic = new Loader();

  char_pic.load(charReq);

  char_pic.contentLoaderInfo.addEventListener(Event.COMPLETE, onCharLoaded);

}

var charBitmaps: Array = new Array();

var charimage: Bitmap;

var charimage2: Bitmap;

//var fpath:String="sdfsd sdf sdf";

function onCharLoaded(e: Event): void {

  charimage2 = new Bitmap(e.target.content.bitmapData);

  charBitmaps[charCtr] = charimage2;

  charimage = new Bitmap(e.target.content.bitmapData);

  charimage.width = 80;

  charimage.height = 64.5;

  //trace ("SOURCE......."+charimage.value);

  charButtons[charCtr].addChild(charimage);

  //trace ("button source"+charButtons[charCtr].value);

  charButtons[charCtr].alpha = 1;

  charCtr++;

  if (charCtr < charButtons.length) {

  loadCharacter();

  } else {

  //all characters are loaded;

  }

}

arifniaz
arifniazAuthor
Participant
June 5, 2017

Hi Colin

Thanks a lot it worked , infact I need to fix this issue and it worked

Thanks a lot

stay happy

arifniaz
arifniazAuthor
Participant
June 1, 2017

here is the code I am using

loading  of character in charButtion array is working fine but each time the charButtons loads different image at chaButtons array.

like on charButton[0] some time it laod char1.png and some time char2.png and so on.

for this reason I need to get the path of image loaded on charButton array. that I can use to pass and save it in txt file to generate the ecard again by the same images added by user.

so how can I get the imagepath of png file loaded in charButton array in showChar() function

//Charater buttons

var charButtons:Array = new Array();

charButtons[0] = icons.charico.contentMain1.char1;

charButtons[1] = icons.charico.contentMain1.char2;

charButtons[2] = icons.charico.contentMain1.char3;

charButtons[3] = icons.charico.contentMain1.char4;

charButtons[4] = icons.charico.contentMain1.char5;

charButtons[5] = icons.charico.contentMain1.char6;

charButtons[6] = icons.charico.contentMain1.char7;

charButtons[7] = icons.charico.contentMain1.char8;

charButtons[8] = icons.charico.contentMain1.char9;

charButtons[9] = icons.charico.contentMain1.char10;

charButtons[10] = icons.charico.contentMain1.char11;

charButtons[11] = icons.charico.contentMain1.char12;

charButtons[12] = icons.charico.contentMain1.char13;

charButtons[13] = icons.charico.contentMain1.char14;

charButtons[14] = icons.charico.contentMain1.char15;

charButtons[15] = icons.charico.contentMain1.char16;

//Load Characters to the buttons
loadCharacters();


function loadCharacters():void
{
var charReq:URLRequest;
var char_pic:Loader;


for(var ct2=0; ct2<charButtons.length;ct2++)
{
  chrequesturl[ct2]="charimages/char"+String(ct2+1)+".png";
// trace ("charimages/"+"char"+String(ct2+1)+".png");
  charReq = new URLRequest("charimages/"+"char"+String(ct2+1)+".png");
  char_pic = new Loader();
  char_pic.load(charReq);
  char_pic.contentLoaderInfo.addEventListener(Event.COMPLETE, onCharLoaded);
 
}
}


var charCtr:int = 0;
var charBitmaps:Array = new Array();
var charimage:Bitmap;
var charimage2:Bitmap;
//var fpath:String="sdfsd sdf sdf";
function onCharLoaded(e:Event):void
{


charimage2 = new Bitmap(e.target.content.bitmapData);
charBitmaps[charCtr] = charimage2;
    charimage = new Bitmap(e.target.content.bitmapData);

charimage.width = 80;
charimage.height = 64.5;


//trace ("SOURCE......."+charimage.value);
charButtons[charCtr].addChild(charimage);

//trace ("button source"+charButtons[charCtr].value);

charButtons[charCtr].alpha = 1;
charCtr++;

}

for(var t=0; t<=15;t++)

{

charButtons.addEventListener(MouseEvent.CLICK, showChar);

}


var charhold1:Boolean = false;
var charhold2:Boolean = false;
var charhold3:Boolean = false;
var theChar:Bitmap;

function showChar(e:MouseEvent):void
{
var theBtnName = e.currentTarget.name;

 
  trace ("here is PNG  name ::"+theBtnName);

//var rect:Rectangle = extimg.char_holder1.getBounds(stage);



theBtnName = theBtnName.substr(4,2);

var theId:int = int(theBtnName)-1;

 
if(charhold1 && icons.charico.radio1.selected)
{
  removeKids(extimg.char_holder1);
 
}

if(charhold2 && icons.charico.radio2.selected)
{
 
  removeKids(extimg.char_holder2);
 
}

if(charhold3 && icons.charico.radio3.selected)
{
 
  removeKids(extimg.char_holder3);
 
}

theChar = charBitmaps[theId];

 
if(icons.charico.radio1.selected)
{
  //trace("inside 1 radio");
  //trace ("the chacter is :::"+theChar);
  extimg.char_holder1.addChild(theChar);
  charhold1 = true;
  currentImage = extimg.char_holder1;
 
 
 
}


}

kglad
Community Expert
Community Expert
June 1, 2017

your loaded bitmaps have a loaderInfo.url property that contains the path/name of the loaded image.

arifniaz
arifniazAuthor
Participant
June 1, 2017

thanks for your reply , I am working in as3 reference code was in as2

kglad
Community Expert
Community Expert
May 31, 2017

contentpath was a property of some as2 components.  in as3, this is usually source, but that's probably not going to help you because you don't appear to understand you were/are even using a component.