Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Not sure how to insert call to an external python page

Guest
Sep 16, 2014 Sep 16, 2014

Hi everybody,

I was just wondering if somebody could help me out(?)

I've got a flash powered card builder, basically an end user can upload an image of their choice, add some text (if they want), then have a custom card printed for them. Think of a customized Gift Card (i.e. McDonalds GC). The company I work for as decided they want to be able to externally control the file size of uploaded images. They want to be able to limit the minimum and maximum sizes of the uploaded image. This control is done externally, and the coding is already written (Python).

The Python developers have already supplied me with the location of the Python page, I just need to insert the call within the AS of the card builder. I have extremely limited experience with AS3, as a quick check of any of my posts will confirm. So I'm not at all sure how can I add this new call to the Python page. I say "new" because there is already a call to another Python page.

I'm hoping I explained myself correctly and you understand what I am looking for. If not please ask and I will be more then happy to elaborate further. I can also supply the pre-existing AS3 code if that helps. They are over 1000 lines of code, so I don't want to add them here and add to the length of this post, until it is absolutely necessary.

Any help is very greatly appreciated!!!

TOPICS
ActionScript
638
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 17, 2014 Sep 17, 2014

use the urlloader class to call server-side executables.

Translate
Community Expert ,
Sep 17, 2014 Sep 17, 2014

use the urlloader class to call server-side executables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 17, 2014 Sep 17, 2014

Hey kglad

I tried that and have sent the project off t the qa department for testing. Thanx for your advice

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2014 Sep 17, 2014

you're welcome.

(but it's going to be time-consuming if you have to send to someone else for testing..)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 23, 2014 Sep 23, 2014

As you can tell by the date of this reply, it is very time consuming!!! I'm still waiting to hear back.

But I've been fiddling around with it because I'm sure it will not work for them. I'm thinking I may have missed something. And have been looking into it. I'm thinking I may need to add in some "ldr.addVariable("XXX")" commands, but am not sure where to add them. I'm thinking I may need to create a function that handles these new files that are being introduced to the card builder swf. Am I on the right track?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

if you need to use data returned by the python code, you should use:

ldr.addEventListener(Event.COMPLETE,completeF);

function completeF(e:Event):void{

//do something with ldr.data

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 23, 2014 Sep 23, 2014

As always glad, thank you for your answer(s), they are always on point!!!

I'm not sure how I would add your solution to the code. I'm not going to include the whole AS3 (although that mite be the best solution) but I will include the sections I believe are where the new code/calls should be. Here we go ...

These are the Python “controlled” command calls …

'MIN_RESOLUTION_NOTE'

'MAX_SIZE_NOTE'

And this is where I believe the call comes from ...

<code>

// URL for uploaded image size control

var IMAGE_SIZE:String = "cws_gc_edit_custom_card.py";

function validateImage(w,h,fs):Boolean {

  var req:URLRequest = new URLRequest(IMAGE_SIZE);

  //Function to ensure the user uploaded image is within the dimension and file size specified below

  var wLimit:int = 2000;  //Width Limit

  var hLimit:int = 2000; //Height Limit

  var fsLimit:int = 8388608; //File Size Limit 8388608 = 8MB file

  var isValid:Boolean = new Boolean();

  if (fs<=fsLimit) { isValid = true; }

  else {

  isValid=false;

  setChildIndex(db,numChildren-1);

  db.visible = true;

  db.dialogBoxText.border = false;

  db.dialogBoxText.text = "ERROR\n\n"

  db.dialogBoxText.appendText("The file size of the image is " + w + "x" + h + "px at " + Math.round(fs/1024) + "KB. This exceeds the limit. \n\n");

  db.dialogBoxText.appendText("The maximum allowed file size is " + Math.round(fsLimit/1024/1024) + "MB and at most " + wLimit + "x" + hLimit + "px");

  db.x = 190;

  db.y = 250;

  }

  return isValid;

}

</code>

Basically the PYTHON call(s) above set the uploaded image size(s) ... Minimum allowed and Maximum allowed. My problem is I'm not sure how to insert those calls.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

that code is actionscript, not python code.

i'm not sure what the work-flow is supposed to be now.  i thought flash was calling the python code which would then handle the image file validation and, if validated, possibly the file upload.  the python script would then (typically) send back data to flash indicating what happened.  ie, the file was valid and uploaded successfully, or invalid and image file parameter was out of range.  typically, flash would then inform the user all's well and present them with the next step is the process or display an error message and give them another chance to correct the problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 23, 2014 Sep 23, 2014

The Python code is completely external from the AS. I have no access to that. I just need to be able to set up the AS so that it calls the Python code. The python code is what controls the min and max uploaded image size.

Sorry for the confusion. I am NOT working on the python code, it is already written.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

what's the code in message 6 supposed to be?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 23, 2014 Sep 23, 2014

That is a portion of the entire AS for that card builder file. It is the areas I believe need the calls to the python external files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2014 Sep 23, 2014

that code shouldn't even be in your app unless you're checking the file size in flash.

again, i'm not sure what the work-flow is supposed to be now.  i thought flash was calling the python code which would then handle the image file validation and, if validated, possibly the file upload.  the python script would then (typically) send back data to flash indicating what happened.  ie, the file was valid and uploaded successfully, or invalid and image file parameter was out of range.  typically, flash would then inform the user all's well and present them with the next step is the process or display an error message and give them another chance to correct the problem.

to call a python file you would use something like:

var urlloader:URLLoader=new URLLoader();

urlloader.addEventListener(Event.COMPLETE,completeF);

urlloader.load(new URLRequest("whatever.py"));

function completeF(e:Event):void{

//urlloader.data

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2014 Sep 24, 2014

Hmmm, sorry kglad I don't think I explained the process well enough. Let me try again.

So at this company we have several clients that use these Flash based custom card builders. Basically the client allows their clients to "build" their own loyalty/reward/cash cards. They can visit the portal site, upload their own image, add their own text, and then upon approval the card will be sent for printing. After which it is sent to the clients' client.

The card builders have a built in feature that is supposed to monitor the size of the uploaded cards. But the file sizes were hard coded into the ActionScript. So if the end user tries to upload a file that is too small, a small popup window tells them it's too small. The same for if the image is too large.

The UI people here have decided that a better way to set the file size limits would be for the Project Manager to be able to manually enter the low and high amounts. This is done externally in what we call an AIV file. The AIV files are powered by the back end Python code. So the Python code has already been written for the file size controls.

Unfortunately my ActionScript skills are from from intermediate, let alone advanced (I consider this modification advanced). I do not know how to insert the calls to the Python code, nor where those calls should be placed.

This is the Python code/page that needs to be called from the card builder ... "cws_gc_edit_custom_card.py" ... I do not know where to place this call, nor how to write the code to do the call. And these are the AIV controls that control the min and max file size ... 'MIN_RESOLUTION_NOTE' and 'MAX_SIZE_NOTE' ... I have no idea where these should be placed within the ActionScript, nor how to write that portion of code.

Your help is very much appreciated!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2014 Sep 24, 2014

i followed you right up to, '. So the Python code has already been written for the file size controls.'

you then skipped to discussing actionscript.  you're not ready to discuss/code any actionscript until you understand what the python code expects for parameters (if anything) and what it returns (which has to be something if you are supposed to take some action in your swf).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2014 Sep 24, 2014

Hmmm, okay sorry.

Thanks Kglad for all of your help. I'm pretty sure you've given me enough advice that I should be able to figure something out. Thanks!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2014 Sep 24, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines